Jump to content

Marcsf73

Members
  • Posts

    4
  • Joined

  • Last visited

Recent Profile Visitors

123 profile views

Marcsf73's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. The line numbers in my post are relative. I abitrarly chose the start line at 100 in "Code add box" so we can reference statements in both routines in our discussions. Yes, My addon script is valid. AutoIit references a function by name it doesn't care what line it starts on. The idea behind my _CommGetLine()? I needed a drop in replacement for CommMG's function. I just added more error reporting. If I used _CommAPI_ReceiveData() I would have to implement the checking functions in my main program. 6 of one 1/2 dozen of the other..
  2. Answers to ADOM's questions Got 2 questions: 1. I parsed orig func Local $hFile = _WinAPI_CreateFile($sFileName, 2, $GENERIC_ALL) I didn't find the $GENERIC_ALL Var . I used the current code at: http://www.autoitscript.com/wiki/CommInterface.au3 See line 116 below ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CommAPI_OpenPort ; Description ...: Opens a specified communications device. ; Syntax ........: _CommAPI_OpenPort(Const $sMode) ; Parameters ....: $sMode - [in] A device-definition string. ; Return values .: Success - The open handle to a specified communications device. ; Failure - 0 ; Author ........: ; Modified ......: ; Remarks .......: ; Related .......: _CommAPI_OpenCOMPort, _CommAPI_ClosePort, _CommAPI_SetCommState ; Link ..........: http://msdn.microsoft.com/en-us/library/aa363214(v=vs.85).aspx ; Example .......: No ; =============================================================================================================================== Func _CommAPI_OpenPort(Const $sMode) Local $sFileName = "\\.\" & StringLeft($sMode, StringInStr($sMode, ":") - 1) Local $hFile = _WinAPI_CreateFile($sFileName, 2, $GENERIC_ALL) If @error Then Return SetError(@error, @ScriptLineNumber, 0) If $hFile <= 0 Then Return SetError(-1, @ScriptLineNumber, 0) Local $tDCB = DllStructCreate($tagDCB) Local $tCommTimeouts = DllStructCreate($tagCOMMTIMEOUTS) _CommAPI_BuildCommDCB($sMode, $tDCB) If @error Then Return SetError(@error, @extended, 0) _CommAPI_SetCommTimeoutsElement($tCommTimeouts, "ReadTotalTimeoutMultiplier", 1) If @error Then Return SetError(@error, @extended, 0) _CommAPI_SetCommTimeoutsElement($tCommTimeouts, "WriteTotalTimeoutMultiplier", 1) If @error Then Return SetError(@error, @extended, 0) If Not _CommAPI_SetCommState($hFile, $tDCB) Then Return SetError(@error, @extended, 0) If Not _CommAPI_SetCommTimeouts($hFile, $tCommTimeouts) Then Return SetError(@error, @extended, 0) Return $hFile EndFunc ;==>_CommAPI_OpenPort I found: Local $hFile = _WinAPI_CreateFile($sFileName, 2, 6) Is this correct? Refer to parameters listed: http://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_CreateFile.htm Local $hFile = _WinAPI_CreateFile($sFileName, 2, 6) $iCreation=2; 2 - Opens a file. The function fails if the file does not exist This is one of the parameters I changed to make it work on my system $iAccess=6; 6=2+4 this is correct: Bit setting 2-Read (010) + 4-Write(100) = 6 decimal (110) I always write multiple bit settings a sum decimal weighted sum. It is easier to figure out what is specified. 2. In my tests I got no problems with acces of $sFileName. Could it be it is different from system to system? Looks like the access bits are correctly set. 3. Pls share your func: "I had to write a function to replace _CommGetLine($sEndChar = @CR, $maxlen = 0, $maxtime = 0) found in CommMG.au3. I'll post it if requested." Below is promised code. Append this function to CommInterface.au3: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _CommAPI_GetLine ; Description ...: Receives data string (RxD/RX/RD) from a specified communications device ending in $EndChar. ; Syntax ........: _CommAPI_GetLine(Const $hFile[, $EndChar = @CR[, $MaxLen = 0[, $iTimeout = 0]]]) ; Parameters ....: $hFile - [in] A handle to the communications device. ; $EndChar - [in] terminating character in a string ; $MaxLen - [in] Maximum string length ; $iTimeout - [in] An integer value for total read timeout in milliseconds. ; Return values .: Success - Received string including $EndChar ; @error=0 ; ; Failure - Empty string ; @error=1: Timeout ($iTimeout) ; @error=2: String exceeded maximum length ($MaxLen) ; @error=3: String Terminator ($EndChar) not in valid sized String ; ; Author ........: Marcsf73 ; Modified ......: March 26, 2014 ; Remarks .......: If the result contains Chr(0), you should convert the result with function Binary(). ; Related .......: _CommAPI_TransmitData ; Link ..........: ; Example .......: _CommAPI_GetLine($hFile,";",20,5000) ;get line terminated in ";" 20 characters max, timeout 5 seconds ; =============================================================================================================================== Func _CommAPI_GetLine(Const $hFile,Const $EndChar = @CR, Const $MaxLen = 0, Const $iTimeout = 0) Local $tBuffer = DllStructCreate("char") Local $hTimer = TimerInit() Local $iWritten = 0 Local $sLine = "" Local $cChar="" Local $flgDone=False Local $error=0 While $flgDone=False _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), 1, $iWritten) $cChar=DllStructGetData($tBuffer, 1) Select Case TimerDiff($hTimer) >= $iTimeout ;Timeout error condition $flgDone=True $sLine="" ;Return string for Timeout Error $error=1 Case StringLen($sLine) >= $MaxLen ;String too long error $flgDone=True $sLine="" ;Return string for String too long Error $error=2 Case $cChar=$EndChar ;$EndChar Detected Finished! $sLine &= $cChar ;append $EndChar to string (Delete line if $EndChar unwanted in return string) $flgDone=True Case $iWritten ;Charater in buffer, Continue building line $sLine &= $cChar Case Not $iWritten ;No more characters in buffer, $EndChar not found in string $flgDone=True $error=3 $sLine="" ;Return String for String without $EndChar EndSelect WEnd SetError($error) Return $sLine EndFunc ;==>_CommAPI_GetLine
  3. Andrew, Thanks for the response. Unfortunately turning off handshaking did not work. Problem solved! To fix the problem, I had to delve into the CommInterface.au3 script and modify the function _CommAPI_OpenPort(Const $sMode). It appeared that, on my system, the file with handle $hFile could not be accessed. To allow file access, I had to modify the following statement in the function _CommAPI_OpenPort(Const $sMode) From: Local $hFile = _WinAPI_CreateFile($sFileName, 2, $GENERIC_ALL) Where: $iCreation set to 2 - Opens a file. The function fails if the file does not exist To: Local $hFile = _WinAPI_CreateFile($sFileName, 3, 2+4,2+4) Where: _WinAPI_CreateFile($sFileName, $iCreation [, $iAccess = 4 [, $iShare = 0 [, $iAttributes = 0 [, $pSecurity = 0]]]]) $iCreation set to 3 - Opens a file. If the file does not exist, the function creates the file $iAccess and $iShare set to 2+4; Both 2 - Read and 4 - Write ---------------------------------------------------------------------------------------------------------------------------------------- Hardware handshaking also works. I had to write a function to replace _CommGetLine($sEndChar = @CR, $maxlen = 0, $maxtime = 0) found in CommMG.au3. I'll post it if requested. Does anyone know if the CommAPI works running Windows 7 and 8? Marc
  4. Hello, I'm a first time poster and a long time AutoIt user. I'm having trouble sending and receiving data via a configured serial port. Software Editor: SciTE 2.2.8 AutoIt 3.3.8.1 Computer running Windows XP SP3 A USB to Serial port converter is fitted with a loop back plug (RD --> TD, CTS --> RTS) When the Port was configured with Hyperterminal , it worked with both "no handshaking" and "hardware flow control" modes. Successful operation was confirmed by the echoed typed Characters. Free Serial Port Monitor V3.31 also confirms port was opened and shows the transmission and reception of typed characters via the loopback connector when using Hyperterminal When the same port is configured with commands CommAPI, the Serial Port Monitor V3.31 confirms the port opens. With the open port, the Below commands successfully toggle the RTS and DTR lines from the CommAPI configured port using a script containing the following commands: _CommAPI_SetOnRTS($hFile, True) _CommAPI_SetOnRTS($hFile, False) _CommAPI_SetOnDTR($hFile, True) _CommAPI_SetOnDTR($hFile, False) The problem is when I run the First Example Scrip from http://www.autoitscript.com/wiki/CommAPI_Examples The command _CommAPI_TransmitData($hFile, $sCommand) is not sending the string assigned to $sCommand and _CommAPI_ReceiveData($hFile, 5000) is not receiving the string. Serial Port Monitor V3.31 confirms the serial port was opened by the program but no characters were transmitted after the execution of _CommAPI_TransmitData($hFile, $sCommand). The command _CommAPI_ClosePort($hFile) successfully closes the port as reported by the serial port monitor. Any Ideas why the data is not being sent? Thanks, Marc
×
×
  • Create New...