Opt("MustDeclareVars", 1) #AutoIt3Wrapper_Au3Check_Parameters= -w 4 Jos #include ; ;Test for ComUDF.au3 ; ;Expected environment: ; The COM port with the highest number on the system will be used ; The TX and RX are expected to be connected to each other ; There are no tests for CTS-RTX-Xon-Xoff implemented Local $ports = _ComListPorts() ;an array with com ports Local $sComPort ;a com port, e.g. COM1 Local $sDef=' baud=9600 data=8' ;speed settings (for default values see _ComOpenPort) Local $hComPort ;serial port handle Local $char = 'x' ;test char Local $string = 'nm-1' ;test string, limit to 4 characters Local $byref = '' ;response Local $binary = Binary(0x3132330034) ;test binary Local $byrefBinary = 0 ;response $string = StringMid($string, 1, 4) ;limit to 4 characters ;info ConsoleWrite(':INFO:' & @CRLF) ConsoleWrite('The COM port with the highest number on the system will be used.' & @CRLF) ConsoleWrite('The TX and RX are expected to be connected to each other' & @CRLF) ConsoleWrite('There are no tests for CTS-RTX-Xon-Xoff implemented' & @CRLF) ConsoleWrite('Manually check the results' & @CRLF) ConsoleWrite(@CRLF) ;tests ConsoleWrite(':Running tests:' & @CRLF) If UBound($ports)=0 Then ConsoleWrite('No serial ports found'); For $i=0 to UBound($ports)-1 $sComPort = $ports[$i] ConsoleWrite('Serial Port ' & $i+1 & ' of ' & UBound($ports) & ': ' & $sComPort & @CRLF) Next ConsoleWrite('Running tests with the last serial port listed above (' & $sComPort & '):' & @CRLF) ConsoleWrite(@CRLF & 'Test starts: _ComOpenPort,_ComClosePort,_ComOpenPort' & @CRLF) ConsoleWrite('Expected response: (a positive number),1,(a positive number)' & @CRLF) $hComPort = _ComOpenPort($sComPort & $sDef) ConsoleWrite('_ComOpenPort ='& $hComPort & '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComClosePort='&_ComClosePort($hComPort)& '#@error='&@error&'#' & @CRLF) $hComPort = _ComOpenPort($sComPort & $sDef) ConsoleWrite('_ComOpenPort ='& $hComPort & '#@error='&@error&'#' & @CRLF) ConsoleWrite(@CRLF & 'Test 1 of 8: _ComSendByte and _ComReadByte' & @CRLF) ConsoleWrite('Sending 0x00, 0x09, 0xff, reading four bytes' & @CRLF) ConsoleWrite('Expected response: 1,1,1,3,0,9,255,-1' & @CRLF) ConsoleWrite('_ComSendByte ='&_ComSendByte($hComPort,0x00)&'#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComSendByte ='&_ComSendByte($hComPort,0x09)&'#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComSendByte ='&_ComSendByte($hComPort,0xff)&'#@error='&@error&'#' & @CRLF) Sleep(500) ;wait 500ms to allow the receive buffer to fill up ConsoleWrite('_ComGetInputcount='&_ComGetInputcount($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadByte ='&_ComReadByte($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadByte ='&_ComReadByte($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadByte ='&_ComReadByte($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadByte ='&_ComReadByte($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite(@CRLF & 'Test 2 of 8: _ComSendBinary and _ComReadBinary' & @CRLF) ConsoleWrite('Sending "'&$binary&'", read back 10 byte, 8 bytes' & @CRLF) ConsoleWrite('Expected response: 8,0,1,"'&$binary&'","'&$binary&'"' & @CRLF) ConsoleWrite('_ComSendBinary ='&_ComSendBinary($hComPort, $binary)&'#@error='&@error&'#' & @CRLF) Sleep(500) ;wait 500ms to allow the receive buffer to fill up ConsoleWrite('_ComReadBinary ='&_ComReadBinary($hComPort, $byrefBinary, 10)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadBinary ='&_ComReadBinary($hComPort, $byrefBinary, 8)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('Sent data =' & $binary & @CRLF) ConsoleWrite('Read data =' & $byrefBinary & @CRLF) ConsoleWrite(@CRLF & 'Test 3 of 8: _ComSendChar and _ComReadChar' & @CRLF) ConsoleWrite('Sending two "' &$char& '" chars, reading three chars' & @CRLF) ConsoleWrite('Expected response: 1,1,2,' & $char & ',' & $char & ',-1' & @CRLF) ConsoleWrite('_ComSendChar ='&_ComSendChar($hComPort,$char)&'#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComSendChar ='&_ComSendChar($hComPort,$char)&'#@error='&@error&'#' & @CRLF) Sleep(500) ;wait 500ms to allow the receive buffer to fill up ConsoleWrite('_ComGetInputcount='&_ComGetInputcount($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadChar ='&_ComReadChar($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadChar ='&_ComReadChar($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadChar ='&_ComReadChar($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite(@CRLF & 'Test 4 of 8: _ComSendString and _ComReadChar with string = "'&$string&'"' & @CRLF) ConsoleWrite('Sending "'&$string&'", reading five chars' & @CRLF) ConsoleWrite('Expected response: 4,4,'&StringMid($string, 1, 1)&','&StringMid($string, 2, 1)&',' & _ StringMid($string, 3, 1)&','&StringMid($string, 4, 1)&',-1' & @CRLF) ConsoleWrite('_ComSendString ='&_ComSendString($hComPort, $string)& '#@error='&@error&'#' & @CRLF) Sleep(500) ConsoleWrite('_ComGetInputcount='&_ComGetInputcount($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadChar ='&_ComReadChar($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadChar ='&_ComReadChar($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadChar ='&_ComReadChar($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadChar ='&_ComReadChar($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadChar ='&_ComReadChar($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite(@CRLF & 'Test 5 of 8: _ComSendString and _ComReadString with string = "'&$string&'"' & @CRLF) ConsoleWrite('Sending "'&$string&'", read 5 chars, read 4 chars, timeout 1s' & @CRLF) ConsoleWrite('Expected response: 4,4,0,"'&$string &'"' & @CRLF) ConsoleWrite('_ComSendString ='&_ComSendString($hComPort, $string)& '#@error='&@error&'#' & @CRLF) Sleep(500) ;wait 500ms to allow the receive buffer to fill up ConsoleWrite('_ComGetInputcount='&_ComGetInputcount($hComPort)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadString 5 ='&_ComReadString($hComPort, 10)& '#@error='&@error&'#' & @CRLF) ConsoleWrite('_ComReadString 4 ='&_ComReadString($hComPort, 4)& '#@error='&@error&'#' & @CRLF) ConsoleWrite(@CRLF & "Test 6 of 8: To be defined" & @CRLF) ConsoleWrite(@CRLF & "Test 7 of 8: To be defined" & @CRLF) ConsoleWrite(@CRLF & "Test 8 of 8: To be defined" & @CRLF) ConsoleWrite(@CRLF & "Test finished: _ComClosePort" & @CRLF) ConsoleWrite('#_ComClosePort='&_ComClosePort($hComPort)& '#@error='&@error&'#' & @CRLF)