Jump to content

Serial Port /COM Port UDF


martin
 Share

Recommended Posts

Thanks for telling me what you are using the udf for; it's great to know what people are doing with it. I will defintely look at the link.

The example script must have got mixed up with some experiments. That while loop would be better as

While 1
    $instr =  _commGetLine(@CR); now that it works :), or just _CommGetString()
  
    If $instr <> '' Then;  if we got something
        If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then $instr = StringReplace($instr,@CR,@CRLF)
        GUICtrlSetData($edit1,$instr,1); ,1 to append instead of replacing
    EndIf

WEnd

The link you gave gives a white sheet. Presumably what the balloon looks like close up :D. I'll try again tomorrow.

Link works.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Glad you like it xapu.

Have you got a video of your car moving?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hello martin. If I have a timeout with _CommReadByte() I get a MsgBox telling this and the function is returning 'Timeout'. Can you disable this MsgBox please.

TIA

Edit: Is it possible to change the wait mask with your library or the special chars for handshaking?

(IOCTL_SERIAL_SET_CHARS, IOCTL_SERIAL_SET_WAIT_MASK, IOCTL_SERIAL_WAIT_ON_MASK)

Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Hello martin. If I have a timeout with _CommReadByte() I get a MsgBox telling this and the function is returning 'Timeout'. Can you disable this MsgBox please.

TIA

Edit: Is it possible to change the wait mask with your library or the special chars for handshaking?

(IOCTL_SERIAL_SET_CHARS, IOCTL_SERIAL_SET_WAIT_MASK, IOCTL_SERIAL_WAIT_ON_MASK)

Hi funkey,

OK, I've removed the message from the GetByte function in the dll. It shouldn't have been left there. New version uploaded.

You can change (should be able to change) the characters used for XON/XOFF handshaking with the function _CommSetXonXoffProperties.

What do you want to change for the wait parameters? (i assume you mean the settings in the function _CommSetTimeouts).

@xapu : Wonderful :)

Have you taught it to play the drums yet?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hi funkey,

OK, I've removed the message from the GetByte function in the dll. It shouldn't have been left there. New version uploaded.

You can change (should be able to change) the characters used for XON/XOFF handshaking with the function _CommSetXonXoffProperties.

What do you want to change for the wait parameters? (i assume you mean the settings in the function _CommSetTimeouts).

Thx for removing the MsgBox.

_CommSetXonXoffProperties and _CommSetTimeouts does a bit of what I want, but not absolut right. I would also need something to adjust the 'WAIT_MASK'.

Here are screenshots of what I mean: http://www.abload.de/gallery.php?key=kjzj7WKk

Thanks for beeing that patient.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Thx for removing the MsgBox.

_CommSetXonXoffProperties and _CommSetTimeouts does a bit of what I want, but not absolut right. I would also need something to adjust the 'WAIT_MASK'.

Here are screenshots of what I mean: http://www.abload.de/gallery.php?key=kjzj7WKk

Thanks for beeing that patient.

I could provide a function in the UDF which is called with 2 parameters. One parameter would be a user function, the other parameter would specify which combination of the following events should call the user function -

Break, RxChar, TxChar,CTS, DSR, Ring, RLSD, Rx80PercFull, TxEmpty

The user function could have a parameter to indicate what the event was.

Is that the sort of thing you mean or have I not understood?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 3 weeks later...

I hesitate to ask this because it seems so basic and I feel sure that someone else must have come across the issue if it is real.

I am using this UDF to receive data from a PICAXE microcontroller (2400,8,N,1). Everything works swimmingly except all lowercase characters are lost. If I send the string ABCdef123, for example, I receive ABC123. I have checked comms parameters until I am blue in the face. There is little to check at the PICAXE end because it is fixed at 8 bits, no parity, 1 stop bit. The only thing you can change is the speed.

At the PC end, the parameters I am using are:

_CommSetPort(3,$sportSetError,2400,8,0,1,0)

and I am receiving the data with a simple:

$indata = _CommGetLine()

Has anyone else come across this? Has anyone any ideas?

Does anyone know of good (free if possible) software I can run on the PC to intercept the incoming serial data transparently.

Thanks,

Adrian

Link to comment
Share on other sites

... a little more detail and investigation

I have sent, a byte at a time, all printable chars from 32 to 126 and after "c" (decimal 99, hex 63) no more are received.

very strange.

I am not aware of any problems with the UDF or DLL which would account for that. You need to try using some terminal emulator such as Hyperterminal or similar. If you get the same problem then the cause is in the picaxe.

You could try setting the flow control to none and linking pins 2 and 3 on the serial port connector. That will tell you if the udf sends and receives the missing characters, in which case you can say the problem is not with the PC but outside of it.

What is the program in the pcaxe and how do you know that the reason isn't there?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hi Martin, thanks for the reply.

I tried hyperterminal and it shows that the data is being sent fine. When received by the udf chars greater than decimal 99 are ignored. The program in the PICAXE is a simple command to send the string " !"£$%^&*()_+-=~#ABCDEFGHIJ...XYZabcdefij" etc. Anything greater than "c" is ignored.

Link to comment
Share on other sites

Then I had better have a look at my program. Back in 5 minutes.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

In the UDF look for the function _CommReadByte, then look fo rthe line something like

if... $DllANs[0] > 2 ....

change that to > 3

Apologies for this, it's too late for me here to do any more including thinking about why it was like that.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

No need to apologise!!

That has worked perfectly! Thank you! And thank you for this great UDF.

I am using it to send data to a tiny transmitter that in turn sends it to a bedside "clock". The data consists of timestamps to set the time together with information from my weather station and BBC newsflashes grabbed with autoit from their website.

I was hoping this UDF would do the job as I couldn't find other serial UDF for Autoit and I didn't want to have to learn some other language. My proposed workaround was to send each alpha byte along with an upper or lower case indicator but this has saved me that hassle so thank you again.

Adrian

p.s. if I was just to ask for one thing it would be to reduce the CPU load while the program is waiting for serial data to arrive.

Edited by adrianhudson
Link to comment
Share on other sites

....

p.s. if I was just to ask for one thing it would be to reduce the CPU load while the program is waiting for serial data to arrive.

Can you show, or pm me, a short example code that you think uses too much cpu and I will see what I think causes the problem.

EDIT:

I have made some tests and I think this is what you need.

In the UDF look for the function _CommGetLine. There is a While/wend section. Before the 'Wend' line add

sleep(20)

I will change the downloads this evening to include these changes. (This one and as post #475)

EDIT 2:

Now done.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hi Martin,

Sorry, I was not ignoring you. Have been away a couple of nights.

Thanks for the update. The code is real simple:

_CommSetPort(3, $sportSetError, 2400, 8, 0, 1, 0) to set things up

and

$instr = _CommGetLine()

to read data. The data comes along in brief pulses once a minute and while it is waiting for the next pulse CPU is high. It looks like you have made changes (thank you) to fix this so this may all be irrelevent now.

I will test this evening and let you know.

Regards

Link to comment
Share on other sites

..

I will test this evening and let you know.

Regards

I think it will work but I also think I didn't do it correctly. I added a sleep, (which I see was also done in a previous version so I don't know how it got lost) but I didn't make the sleep conditional. This means that if data is coming in fast the sleep will slow everything down. So instead of

sleep(20)

I should have written

if $nextchar = '' then sleep(20)

in the _CommGetLine function.

So perhaps you could test that for me. If it works ok for you I'll make another update.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...