Jump to content
Sign in to follow this  

Serial communication difficulties

Recommended Posts


Hello all,

I am embarking on a project which requires serial communication. One would logically think that serial communication would be a little easier to deal with then IP. It seems that I am running into the exact antithesis of my hypothesis when attempting to communicate serially. I have been playing around with Martin's comm udf and am having no luck at all. In this phase of the project, I am merely attempting to send one serial command via exe and after much reading around have found someone elses post that seemed to be along the lines of what I am looking for but is not working for me.

;Include the Serial UDF
#include 'CommMG.au3'

;Internal for the Serial UDF
Global $sportSetError = ''

;COM Vars
;_CommSetPort($iPort, ByRef $sErr, $iBaud = 9600, $iBits = 8, $iPar = 0, $iStop = 1, $iFlow = 0, $RTSMode = 0, $DTRMode = 0)
Global $CMPort = 2              ; Port
Global $CmBoBaud = 19200        ; Baud
Global $CmboDataBits =  8       ; Data Bits
Global $CmBoParity = "none"     ; Parity
Global $CmBoStop = 1            ; Stop
Global $setflow = 0            ; Flow
Global $RTSMode = 0
Global $DTRMode = 0
Global $iWait = 0

;Start up communication
Opt("GUIOnEventMode", 1)
While 1
_CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow, $RTSMode, $DTRMode)
sleep (2000)

$bBinData = Binary("0xF10801F0010102EE")
$iNumbytes = BinaryLen($bBinData)
$tBinData = DllStructCreate("byte["&$iNumbytes&"]")
DllStructSetData($tBinData, 1, $bBinData)
$iRet = _CommSendByteArray(DllStructGetPtr($tBinData),$iNumbytes,1)
If @error Or $iRet = -1 Then ConsoleWrite("!Error: " &  @error & @CRLF)


; Function Name:   _CommSendByteArray($pAddr,$iNum,$iWait)

; Description:    Sends the bytes from address $pAddress
; Parameters:     $iNum the number of bytes to send.
;                 $iWaitComplete - integer: if 0 then functions returns without
;                                  waiting for bytes to be sent
;                                 if <> 0 then waits until all bytes are sent.
; Returns:  on success returns 1
;           on failure returns -1 and sets @error to 1
;;NB could hang if byte cannot be sent and $iWaitComplete <> 0
;    could lose data if you send more bytes than the size of the outbuffer.
;    the output buffer size is 2048

By the appearance of this code, I should be able to execute this exe and a command should be sent from the appropriate port.

I am really confused by this and could deffinetely use a little help.

Thank you!

Share this post

Link to post
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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.