#include #include #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 Global Const $iPort = 3 Global Const $iBaud = 9600 Global Const $iParity = 0 Global Const $iByteSize = 8 Global Const $iStopBits = 0 Global Const $sCommand = "Command" & @CRLF Main() Func Main() Local $iErrorLine = COMHandling() If @extended Then MsgBox(32, "Error", _WinAPI_GetLastErrorMessage()) ElseIf @error Then MsgBox(32, "Error", "Error in line " & $iErrorLine) EndIf EndFunc Func COMHandling() Local $hFile = 0 Local $sResult = "" ToolTip(_CommAPI_GetCOMPorts(), Default, Default, "COM Ports", 1) $hFile = _CommAPI_OpenCOMPort($iPort, $iBaud, $iParity, $iByteSize, $iStopBits) If @error Then Return SetError(@error, @extended, @ScriptLineNumber) _CommAPI_ClearCommError($hFile) If @error Then Return SetError(@error, @extended, @ScriptLineNumber) For $i = 1 To 10 _CommAPI_TransmitData($hFile, $sCommand) If @error Then Return SetError(@error, @extended, @ScriptLineNumber) Sleep(5000) $sResult = _CommAPI_ReceiveData($hFile) If @error Then Return SetError(@error, @extended, @ScriptLineNumber) If $sResult Then ToolTip($sResult, Default, Default, "Received data", 1) Else ToolTip("Loop " & $i, Default, Default, "No received data", 3) EndIf Next _CommAPI_CLosePort($hFile) If @error Then Return SetError(@error, @extended, @ScriptLineNumber) Sleep(5000) EndFunc