Jump to content

Serial Port /COM Port UDF


martin
 Share

Recommended Posts

Hi Martin,

Its XP Pro 32 bit

I can also get commmg working if i press the reset button on the arduino, guess this resets the serial port to a default?

After i do this commMG works again?

Another clue if i go into CommgExample.au3 and set it to Xon Xoff and send the text using CommgExample.au3 in works

Then commMG works again as it should. Now I don't need to use Xon Xoff normally.

Hope that helps

Regards

Gary

Link to comment
Share on other sites

Hi Martin

I have done more investigation using SerialMon v1.4.0 to monitor events.

I used Hyperterminal (works) and Realterm (works) and commmg (not working)

From the results below it seems as though DTR is not being turned on by commMG ?

Please find below my autoit code that I believe I am turning it on ?

Hope this helps

Regards

Gary

;Include the Serial UDF
#include 'CommMG.au3'
;Internal for the Serial UDF
Global $sportSetError = ''
;COM Vars
Global $CMPort = 6   ; Port
Global $CmBoBaud = 9600   ; Baud
Global $CmboDataBits =  8  ; Data Bits
Global $CmBoParity = "none"  ; Parity
Global $CmBoStop = 1   ; Stop
Global $setflow = 2 ; Flow
Global $RTSMode = 0
Global $DTRMode = 1

;Start up communication with the Arduino
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow, $RTSMode, $DTRMode)
_CommSendstring("<lamp on>" )
If @error = -1 Then ConsoleWrite("!Error: " &  @error & @CRLF)

# SerialMon v1.4.0 - www.serialmon.com

2011-12-01 19:15:16.109 # Device opened by: USB Serial Port (COM6) (1972)

2011-12-01 19:15:16.125 # Get baudrate: 9600

2011-12-01 19:15:16.125 # Get bits: 8N1

2011-12-01 19:15:16.125 # Get baudrate: 9600

2011-12-01 19:15:16.125 # Get bits: 8N1

2011-12-01 19:15:16.125 # Set baudrate: 9600

2011-12-01 19:15:16.125 # DTR: Off

2011-12-01 19:15:16.125 # DTR: Off

2011-12-01 19:15:16.125 # Set bits: 8N1

2011-12-01 19:15:16.125 T "<lamp on>"

2011-12-01 19:16:23.516 # Device opened by: hypertrm.exe (2812)

2011-12-01 19:16:23.531 # Get baudrate: 9600

2011-12-01 19:16:23.531 # Get bits: 8N1

2011-12-01 19:16:23.531 # Get baudrate: 9600

2011-12-01 19:16:23.531 # Get bits: 8N1

2011-12-01 19:16:23.531 # Set baudrate: 9600

2011-12-01 19:16:23.531 # DTR: On

2011-12-01 19:16:23.531 # DTR: On

2011-12-01 19:16:23.531 # Set bits: 8N1

2011-12-01 19:16:26.422 T "<"

2011-12-01 19:16:26.953 T "l"

2011-12-01 19:16:27.297 T "a"

2011-12-01 19:16:28.078 T "m"

2011-12-01 19:16:28.406 T "p"

2011-12-01 19:16:28.625 T " "

2011-12-01 19:16:28.781 T "o"

2011-12-01 19:16:29.188 T "n"

2011-12-01 19:16:29.781 R "Data received is ... lamp on" 0A

2011-12-01 19:16:30.141 R "and the socket is ON" 0D 0A

2011-12-01 19:16:29.719 T ">"

2011-12-01 19:17:25.891 # Device opened by: realterm.exe (1012)

2011-12-01 19:17:34.891 # Device opened by: realterm.exe (1012)

2011-12-01 19:17:34.891 # Get baudrate: 9600

2011-12-01 19:17:34.891 # Get bits: 8N1

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # Get baudrate: 9600

2011-12-01 19:17:34.891 # Get bits: 8N1

2011-12-01 19:17:34.891 # Get baudrate: 9600

2011-12-01 19:17:34.891 # Get bits: 8N1

2011-12-01 19:17:34.891 # Get baudrate: 9600

2011-12-01 19:17:34.891 # Get bits: 8N1

2011-12-01 19:17:34.891 # Set baudrate: 9600

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # Set bits: 8N1

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # Get baudrate: 9600

2011-12-01 19:17:34.891 # Get bits: 8N1

2011-12-01 19:17:34.891 # Get baudrate: 9600

2011-12-01 19:17:34.891 # Get bits: 8N1

2011-12-01 19:17:34.891 # Set baudrate: 9600

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # Set bits: 8N1

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # Get baudrate: 9600

2011-12-01 19:17:34.891 # Get bits: 8N1

2011-12-01 19:17:34.891 # Get baudrate: 9600

2011-12-01 19:17:34.891 # Get bits: 8N1

2011-12-01 19:17:34.891 # Set baudrate: 9600

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # Set bits: 8N1

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # Get baudrate: 9600

2011-12-01 19:17:34.891 # Get bits: 8N1

2011-12-01 19:17:34.891 # Get baudrate: 9600

2011-12-01 19:17:34.891 # Get bits: 8N1

2011-12-01 19:17:34.891 # Set baudrate: 9600

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # Set bits: 8N1

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:34.891 # DTR: On

2011-12-01 19:17:44.391 T "<lamp on>"

2011-12-01 19:17:44.406 R "Data "

2011-12-01 19:17:44.422 R "received is ... "

2011-12-01 19:17:44.437 R "lamp on" 0A

2011-12-01 19:17:44.766 R "and the soc"

2011-12-01 19:17:44.781 R "ket is ON" 0D 0A

Link to comment
Share on other sites

if you want hardware flow control then you need to have $flow = 0.

Then you can use the DTR according to the value you have used in the DTR parameter

;$DTRMode 0 = turns on the DTR line when the port is opened and leaves it on

; 1 = enables DTR handshaking

; 2 = disables the DTR line when the device is opened and leaves it disabled.

It's unfortunate that $flow = 0 probably reads wrong. I might add some enums so that I can make it something like

Global enum $fmHARDWARE = 0, $fmXONXOFF, $fmNONE

and then you can have

$flow = $fmHARDWARE

etc

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

Have been working on this for another 6 hours and twice thought it was working OK ( but then switch PC off and come back to it later and its stopped working)

As I am new to commMG I am not fully sure of what I am exactly doing, as I cannot find any instructions on all the functions of commMG ?

Anyway I think we are close to getting it working as whenever I use CommgExample.au3 and I select my com port THEN Xon/Xoff and then type "lamp on" it ALWAYS works?

I have looked at the script of CommgExample but find it hard to know exactly how its setup, can you modify my code below so that it sends the correct setup as CommgExample?

Thank you your help

Regards

Gary

; NOTES
; -----
; If you want hardware flow control then you need to have $setflow = 0.
; Then you can use the DTR according to the value you have used in the DTR parameter
; $DTRMode Enables
; 0 = turns on the DTR line when the port is opened and leaves it on
; 1 = enables DTR handshaking
; 2 = disables the DTR line when the device is opened and leaves it disabled.

;Include the Serial UDF
#include 'CommMG.au3'
;Internal for the Serial UDF
Global $sportSetError = ''
;COM Vars
Global $CMPort = 6  ; Port
Global $CmBoBaud = 9600   ; Baud
Global $CmboDataBits =  8  ; Data Bits
Global $CmBoParity = "none"  ; Parity
Global $CmBoStop = 1   ; Stop
Global $setflow = 1 ; Flow ..... IS THIS CORRECT?
Global $RTSMode = 0 ; RTS parameters ...... IS THIS CORRECT?
Global $DTRMode = 0 ; DTR parameters ....IS THIS CORRECT?
Global $XonChar
Global $XoffChar
Global $XonStart
Global $XoffStop
;====================== SetXonXoffProperties =======================================================================
; Description: Set the values used for the XON and XOFF characters, and when these charactyers are to be transmitted
; Parameters - $XonChar - the ASCII code for the character to be sent to indicate the port is ready to receive
;           - $XoffChar - the ASCII code fo rthe character to be sent to stop receiving
;           - $XonStart - when the number of characters in the input buffer falls below this value the XonChar will be sent
;           - $XoffStop - when the number of bytes free in the input buffer falls below this value the XoffChar will be sent
;When a port is opened the values are as the defaults for the function.
;Return - on success 1
;      - on error   0 if error making dllcall and @error set to 1
;                  -1  illegal XonChar value
;                  -2  illegal XoffChar value
;
_CommSetXonXoffProperties($XonChar = 0x11, $XoffChar = 0x13, $XonStart = 100, $XoffStop = 100) ; .. IS THIS CORRECT?

;Start up communication with the Arduino
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow, $RTSMode, $DTRMode )
_CommSendstring("<lamp on>" )
If @error = -1 Then ConsoleWrite("!Error: " &  @error & @CRLF)
Link to comment
Share on other sites

There are a few things to sort out.

The first is that there is an error in my example script which I think must have been there for years and I'm surprised no-one has compalained about it. Maybe they did and I ignored them. I expect that a lot of your grief has been because of this and this is where I think the internet comes into its own; punching me on the nose is a lot more dfficult. I had the settings for hardware handshaking and XON/XOFF reversed, so when you selected XON/XOFF using my example you were actually settingf hardware handshaking and it worked.

In the example the optional parameters for RTS,DTR weren't used so they would have defaulted to 0 as you deduced.

Next, I think you have misunderstood the use of default parameter values in a function. This function in th eUDF

Func _CommSetXonXoffProperties($XonChar = 0x11, $XoffChar = 0x13, $Xonstart = 0, $XoffStop = 0)

has parameters which will default to the values shown if they are not given. If one is omitted then the following parameters must also be omitted. If you do this

_CommSetXonXoffProperties(0x11)

you are telling the function to use 0x11 for XON, 0x13 for XOFF, 0 for $Xonstart and 0 for $XOFFSTOP)

If you do this

_CommSetXonXoffProperties($XonChar = 0x11)

you are telling the function to set $XON to ($XonChar = 0x11) which is true or false depnding on what $XonChar was and that will be converted to 1 or 0. So that is wrong.

You don't actually need to call that function at all because the defaults are standard for XON/XOFF and it is only people who use XON/XOFF and who also have none standard control codes that need that function. But in any case, you don't want XON/XOFF it appears.

You need to remember that _CommSendString only sends exacly the string you pass to it. If you want a Carriage Return added then you must add it. I don't know if it is needed for your Arduino but I have added it in the code below because my guess it that it should be added.

Fianlly, the documantation in the UDF for each function is all there is.

This is what I think will make your Arduino work

;Include the Serial UDF
#include 'CommMG.au3'
;Internal for the Serial UDF
Global $sportSetError = ''
;COM Vars
Global $CMPort = 6 ; Port
Global $CmBoBaud = 9600 ; Baud
Global $CmboDataBits = 8 ; Data Bits
Global $CmBoParity = "none" ; Parity
Global $CmBoStop = 1 ; Stop
Global $setflow = 0 ; Flow ..... IS THIS CORRECT? Due to error in my example selecting XON/XOFF actually set harware handshaking


;Start up communication with the Arduino
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)
if $sportSetError &lt;&gt; '' Then
    MsgBox(262144,"Error opening Port", $sportSetError)
    Exit
EndIf


Global $toSend[2] = ["<lamp on=>", "<lamp off=>"] ;;guessed lamp off

For $n = 0 To 9
    _CommSendstring($toSend[Mod($n, 2)] & @CR);  CR  ??
  ConsoleWrite("Sent -->; " & $toSend[Mod($n, 2)] ; @CRLF)
    If @error &lt;&gt; 0 Then
        ConsoleWrite("!Error: Send String returned with @error = " & @error & @CRLF)
        ExitLoop
    EndIf

    Sleep(2000)
Next


;all done so close current channel

_CommClosePort()

I see that the parameters for RTS and DTR are not actually used in the dll and I have no idea when they ever were used. So I have corrected the example and the dll and I will update the zip for downloading fairly soon.

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

New version of the dll and example in the download. (see first post in this thread.)

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 that . don't worry about the pop on the nose :-) only to happy to help and when i get my code working i will be :D

Have downloaded your new ddl and tried to use the new code you sent in previous posting, but it seems to have typos? a lot is showing up in green and I get an error message.

I think there may be 3 lines with errors?

Also i don't need CR can you please take them out?

The exact code my arduino is looking for is <lamp on> or <lamp off>

< is used as the start character and the > is used as the end character of a packet

So in my code these are stripped and i will actually look for the strings lamp on or lamp off

By the way, using your CommgExample.au3

I select my com port AND now its RTS/CTS, this works when I type "lamp on" etc.

Regards

Gary

Link to comment
Share on other sites

When I edited my post it got messed up by the forum utility and translated things like ">" to "&gt;". I have truied to correct a few more in that post.

By the way, using your CommgExample.au3

I select my com port AND now its RTS/CTS, this works when I type "lamp on" etc.

Do you mean with the latest version I posted this afternoon?

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,

I have written to the Arduino forum to find out the flow control it uses, see below for answer:

The arduino hardware and serial software uses no serial data flow control at all. You could using external hardware and or software in your sketch to implement some forms of flow control.

So it looks as though I was over complicating things.

But what seems strange is that when I use RTS/CTS, using your latest dll and CommgExample.au3, that is the only way I can get the arduino to work correctly?

Also when i chose "APPLY", I always see the arduino lights an led on pin13, so it must be sending something ?

With My code I have never got it working correctly, at times I've had it working and think I have solved it, then when try it next day it doesn't work?

But when i do get it working as long as I don't switch of the PC it works perfectly?

Any ideas

Also how do I send the text out with no flowcontol as I've tried so many variations I am a bit lost as to what is correct?

Tried the following but this doesn't work:

;Include the Serial UDF
#include 'CommMG.au3'
;Internal for the Serial UDF
Global $sportSetError = ''
;COM Vars
Global $CMPort = 6  ; Port
Global $CmBoBaud = 9600   ; Baud
Global $CmboDataBits =  8  ; Data Bits
Global $CmBoParity = "none"  ; Parity
Global $CmBoStop = 1   ; Stop
Global $setflow = 2 ; Flow ..... IS THIS CORRECT?

_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)
_CommSendstring("<lamp on>" )
_CommClosePort()
If @error = -1 Then ConsoleWrite("!Error: " &  @error & @CRLF)

One final thing I sometimes use a program called RealTerm and this always works and the settings are all as you would expect? see attached image:

Thanks for all your help!

Regards

Gary

post-2897-0-79079100-1323036866_thumb.jp

Edited by quest
Link to comment
Share on other sites

If there is no flow control then flow should be set to 2 when you open the port and leave out the settings for DTR and RTS.

How do you send the instructions with the terminal emulators which work? Don't you have to press ENTER to get the instruction to work? If not how do you avoid having one continuous line full of instructions across the screen? And if you do press ENTER then why do you think that you don't need CR added to the commands?

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,

Its now late in the evening 11.30 pm, but have still been researching whats going on and at last its all becoming clearer, most of it is to do with the Arduino.

Remeber I mentioned that I see a LED light up when either your CommgExample.au3 OR RealTerm is used, its because they reset the Arduino and my code isn't doing that?

I have attached the relevant parts of an article i found and when read you can see whats happening :D

Soft reset on arduino through starting serial comm

10.02.2009 at 17:41:54

Hi everyone,

Question:

I have made my first serial comm program on arduino last weekend. I realized that each time I establish link on the USB serial port by opening serial port file and activating the transmission lines, the arduino resets itself. I know this because each time I open that comm port I receive the string that arduino is supposed to send when it starts up. Is what's happening really what I think? Undecided Does establishing serial comm reset the arduino?

Answer 1:

The board resets the controller chip when there is a wiggle on the DTR line of the serial connection. This lets the bootloader run again, which gives the Arduino IDE a chance to upload a new sketch that replaces the old sketch. If no such upload happens, the old sketch is started again from the beginning.

In most applications, this is welcome behavior. When you connect with a terminal application or the Arduino monitor, you probably want setup() to run again so the Serial.begin(9600) takes effect, and you can see the first message your sketch prints out.

Answer 2

Yes, It's actually two signal lines on the RS-232 that are activated when a port is opened, DTR and RTS. The process of opening a comm port (at least on windows) cause DTR/RTS to be turned on.

So its to do with the DTR Line after all. I will work on it tomorrow.

Thank you very much and i think we are nearlly there

Your help is very much appreciated !

Regards

Gary

Edited by quest
Link to comment
Share on other sites

Hi Martin,

Just to refresh:

Arduino does not use any flow control .

On using new DLL and CommgExample.au3 I select my com port AND now its Hardware (RTS/CTS), that only works, when I type "lamp on" etc.

This seems strange as I would have thought I would select "None" ?

If I do select "none" this will ALWAYS lock up my port and no data will get through, the only way to clear it is to go back and select Hardware (RTS/CTS) which causes the arduino to reset itself and restart its code from the beginning.

I just can't find the combination to get it to work, but the Arduino has been designed that any term program will work correctly, and so far the others i have tried do work and require no setting up, other than making sure there is no flow control and thats it, other than the baud etc. I do notice that all these programs when selecting options etc and then only when I enable that port by clicking on a buitton, this causes the Arduino to reset.

In my AutoIt code I have tried various combinations to get this to work.

I even tried $DTRMode 0 = turns on the DTR line when the port is opened and leaves it on and had $setflow = 0 as this is the only way I beleive you mentioned that this will work?

Does $setflow = 0 do handshaking? if so thats why it will not work.

Hopefully all this makes sense and you can let me know how i get the combination i need?

Once again thanks for taking the time to help me Martin

Regards

Gary

Edited by quest
Link to comment
Share on other sites

Hi Martin

Finally worked out what was wrong! :D

Brief explanation

---------------------

The Arduino originally required the user to press a reset button and release it at just the right time to load "code" into it (In Arduino terms the code is called a "sketch")

If the button was not released at the correct time, the new sketch would not load !

Later they came up with a "fix" that automatically did all the above without the user doing anything and when the sketch was fully loaded

An automatic RESET was performed on the chip using DTR, to run the program of code.

This is what causes problems!

More explanation

----------------------

The Arduino RESETS its self when DTR is pulsed from HIGH to a LOW (for a minimum of 22ms) and the Arduino pulses pin13 briefly to show that it has reset.

BUT it then waits a further 1 second to see if there is a new sketch to be uploaded.

You MUST NOT send any data for at least 1.4 seconds (Seems to be the minimum using FTDI USB to Serial convertor)

Then data can be sent!

It is advisable not to change DTR again as this would course another Reset.

Data can then be sent without a Reset occuring on every transmission of Data.

When I was trying to send data on all other Term programs I would select Com port etc then press enable, and because it took me longer than 1.4 seconds to type in <lamp on> thats why they all worked!

Thank you for your help Martin !

Here is my working code for anyone that reads this in the future

; NOTES
; -----------
; If you want hardware flow control then you need to have $setflow = 0
; Then you can use the DTR according to the value you have used in the DTR parameter
; $DTRMode
; 0 = turns on the DTR line when the port is opened and leaves it on
; 1 = enables DTR handshaking
; 2 = disables the DTR line when the device is opened and leaves it disabled.
;Include the Serial UDF
#include 'CommMG.au3'
;Internal for the Serial UDF
Global $sportSetError = ''
;COM Vars
Global $CMPort = 6     ;  Port
Global $CmBoBaud = 9600 ;  Baud
Global $CmboDataBits =  8   ;  Data Bits
Global $CmBoParity = "none"   ;  Parity
Global $CmBoStop = 1     ;  Stop
Global $setflow = 0    ;  $setflow

_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow)
sleep (1500)   ;  Wait for arduino to settle after DTR has reset it
       ; 1450 is the lowest I can go or it will stop responding
_CommSendstring("<lamp on>")

Regards

Gary

Link to comment
Share on other sites

I'm glad you found out what the problem was, and relieved that it wasn't a problem with my software. I couldn't have found that by staring at my code.

I case anyone else has a problem which might be to do with DTR you could add a button or two to the AutoIt gui to toggle the DTR line by calling _CommgSetDTR(0) or (1).

Also, you can read the states of DTR and some other lines with _CommgGetLineStates and if you used a timer of AdlibRegister you could update little LED icons.

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

Thanks for telling me Gary. The version date was corrected but not the version number.

Error now corrected.

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

Hey Martin,

First let me say Excellent UDF. This has made the particular project I'm working on 1000x easier. However... (you knew the "however" was coming), I am having some trouble with the _CommGetLine() function. During the debugging i decided to use your example script to see if it was just an error in my code. Here's the issue. I am trying to read the serial data coming in line by line and perform various actions based on the strings received. The _CommGetString causes alot of problems due to the way it splits lines every now and then. So I saw that the _CommGetLine would actually read a complete line where a "line" is defined as all text inbetween a @CR or some other predefined $EndChar. Sounded Perfect... But I have yet been able to get the _CommGetLine to perform at all. When using the getline func no data is ever received. I verified the data being sent does contain @cr and tried @crlf and also set the $EndChar to various other values like comma's, numbers, and even " ". But never received any data in the variable or on the $Edit window.

I then added a bunch of ConsoleWrite funcs to the CommMG.au3 file to help me debug the problem. So far I'm able to tell that the $nextchar variable always equals " ". I assume this has something do with the issue, but I'm not sure where to start looking to continue debugging my issue. Any guidance or assistance would be GREAT. I haven't included any scripts or examples since I am literally using your exact example and regular serial data that works fine with CommGetString but not CommGetLine. If you do need me to include some script or examples of the serial data being transmitted just let me know. THANKS!!!

Link to comment
Share on other sites

I am investigating....

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

I am investigating....

The function _CommReadByte is broken and may have been for years. Please change it to be like this as a temporary fix. I will think about a better correction and then update the download.

Thanks for pointing out that this was a problem jdc928.

Func _CommReadByte($wait = 0)
    Local $iCount, $vDllAns
    If Not $fPortOpen Then
        SetError(1)
        Return 0
    EndIf


    If Not $wait Then
        $iCount = _CommGetInputCount()
        If $iCount = 0 Then
            SetError(1)
            Return ''
        EndIf
    EndIf

    $vDllAns = DllCall($hDll, 'str', 'GetByte');GetByte returns the ascii code in string format for the next char

    If @error <> 0 Then
        mgdebugCW("readbyte error = " & @error & @CRLF)
        SetError(2)
        Return ''
    EndIf

    If Execute($vDllAns[0]) > 999 Then;<------------ line changed
        mgdebugCW("getbyte call returned >" & $vDllAns[0] & @CRLF)
        Return SetError(3, 0, $vDllAns[0])
    EndIf

    Return $vDllAns[0]

EndFunc   ;==>_CommReadByte
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

WOW, I deal with programmers on a daily basis, and I have to say it is RARE to get a response of any kind in that short of a time period, much less a response with a solution! Great Work!

As far as the function change... I do have the _CommGetLine working now! But I did notice some very odd issues with my code I was using yesterday that I can only explain by the possibility that at some point I downloaded a previous version of the UDF and didn't notice I was using it, as opposed to the current one. (Although I have NO recollection of downloading this UDF in the past.)

But when your new _CommReadByte function didn't work I decided to unpackage the original again just to be safe. As soon as i opened the code i noticed some major differences. At first I thought I had just accidentally deleted some code the first time I opened it, but while inspecting the code I realized that couldn't have been the case. Luckily the "first" version of the code I opened clued me in to why the _CommReadLine func was still not working and the resolution. Here's what I ran into with the freshly unzipped code:

The _CommGetLine func started to work but each line sent was being placed over top of the previous line. Checking the box in the top right made no change. When I compared the new code to the one I was using yesterday I saw major differences in this area:

(This is the "fresh" code I un-zipped today which worked with new ReadByte modification but didn't display correctly)

If $instr &lt;&gt; '' Then;if we got something
  GUICtrlSetData($edit1,$instr)
  ;If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then $instr = StringReplace($instr,@CR,@CRLF)
  ;$lines = GUICtrlRead($edit1)
  ;$charcount = StringLen($lines)
  ;_GUICtrlEditSetSel($edit1, $charcount, $charcount)
  ;If $charcount &gt; 10000 Then GUICtrlSetData($edit1,StringRight($lines &amp; $Instr,8000))
  ; _GUICtrlEditReplaceSel($edit1, False, $instr)
  ; _GUICtrlEditScroll($edit1,$SB_SCROLLCARET)
  ;;;If $scroll Then _GUICtrlEditLineScroll($edit1,0,_GUICtrlEditGetLineCount($edit1) - 14)
EndIf

In my first example code I had almost none of this commented code. I did however have the SetData and "If Checkbox then..." lines but they were not commented out. Also the SetData had an extra parameter of "1" (which upon adding caused the data to start being displayed correctly. Also the "If Checkbox then...." line was before the SetData line, which would make sense.

I only include this information in case the code that I opened today is somehow a newer or different version then the one I opened yesterday and to hopefully give you a heads up if this is potentially a snippet of problematic code.

Again, thanks for your time in creating this UDF.

(Just to let you know, you'r UDF is being used EXTENSIVELY to create a "Ground Control" application that will be performing final testing and setting final values on an "Autonomous Un-manned Balloon that will be setting a world record for un-manned flight in the next couple of months! 3 days flying across the Atlantic Ocean and landing in Europe. Your UDF is communicating with 9 arduinos up until the moment it's launched from our launch site. You can take a look at the project website if your interested. I'll post our Ground Control app with a mention of the UDF and this blog post when it's finished. http://www.whitestarballoon.com )

Edited by jdc928
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...