|
$MsComm = ObjCreate("MSCOMMLib.MsComm.1")
$MsComm.CommPort = 1
$MsComm.Settings = "9600,N,8,1"
$MsComm.Handshaking = 0
$MsComm.InBufferSize = 1024
$MsComm.InputLen = 1
$MsComm.PortOpen = 1
While 1
_MsgOut("RT" & @CR)
MsgBox(0,"Testing",_MsgIn())
Sleep(2000)
WEnd
Func _MsgOut($str)
$MsComm.OutBufferCount = 0
$MsComm.InBufferCount = 0
If $MsComm.PortOpen = True Then
$MsComm.Output = $str
EndIf
$MsComm.InputLen = 0
EndFunc
Func _MsgIn()
$TIMEOUT = 1000
$nTimeCtr = 0
$sBuffer = ""
Do
$nTimeCtr += 1
If $MsComm.InBufferCount > 0 Then
$sBuffer = $sBuffer & $MsComm.Input
EndIf
Sleep(500)
Until StringInStr($sBuffer,@CR) OR $nTimeCtr > $TIMEOUT
If $nTimeCtr < $TIMEOUT Then
$nI = StringInStr($sBuffer,@CR)
Return StringLeft($sBuffer,$nI)
Else
Return "Error"
EndIf
EndFunc |
|