Skip to content

Instantly share code, notes, and snippets.

@MattDiesel
Created June 26, 2013 09:44
Show Gist options
  • Save MattDiesel/5866187 to your computer and use it in GitHub Desktop.
Save MattDiesel/5866187 to your computer and use it in GitHub Desktop.
Global $packetID = "UCAS"
Local $inbuff = "", $n
While 1
;ManageTray()
;Sleep(50) ; (to allow script to make way for other software. Not sure if it does though?)
$inbuff = $inbuff & _Commgetstring()
If @error <> 0 Then
loggit("Error returned by _Commgetstring()")
ExitLoop
EndIf
loggit("$inbuff & _Commgetstring() is: '" & $inbuff & "'")
;loggit("@error is: " & @error)
$n = StringInStr($inbuff, @CR)
loggit("$n is: " & $n)
If $n > 0 Then ; found CR
;loggit("$n is: " & $n)
;$inbuff - The string to evaluate.
;@LF - The substring to search for or the character position to start the replacement.
;"" - The replacement string.
$inbuff = StringReplace($inbuff, @LF, "")
loggit("$inbuff using StringReplace is: " & $inbuff)
loggit("Received i.e. StringLeft($inbuff, $n-1) " & StringLeft($inbuff, $n - 1))
loggit("$packetID is: " & $packetID)
;If StringInStr($inbuff, $packetID) And StringInStr($inbuff, $remoteID) Then
If StringInStr($inbuff, $packetID) Then
loggit("$inbuff in StringInStr($inbuff, $packetID) " & $inbuff)
loggit("StringMid($inbuff, $n-1, 1) in StringInStr($inbuff, $packetID) is: " & StringMid($inbuff, $n - 1, 1))
keysend(StringMid($inbuff, $n - 1, 1)); process the char before the CR
EndIf
$inbuff = StringTrimLeft($inbuff, $n) ; inbuff holds everything after the CR
loggit("$inbuff after StringTrimLeft($inbuff, $n) is: " & StringTrimLeft($inbuff, $n))
;Else
;loggit( "$n is not greater than i.e. $n is: " & $n )
EndIf
WEnd
Func loggit($s)
ConsoleWrite($s & @LF)
EndFunc ;==>loggit
Func _Commgetstring()
Local Static $i = 0
Local Static $aReturns[5] = ["", "", @CRLF & "UCAST:000D6F0001B557E3,07=RFC-951" & @CRLF, "", ""]
If $i >= UBound($aReturns) Then Return SetError(1, 0, "")
$i += 1
Return $aReturns[$i - 1]
EndFunc ;==>_Commgetstring
Func keysend($ch) ; translate the character into a keystroke and send it out
MsgBox(0, "$ch is: ", "$ch is: " & $ch)
EndFunc ;==>keysend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment