KF5WGB Posted August 17, 2019 Share Posted August 17, 2019 (edited) Hi, I am trying to receive data send from a radio. Sending commands work just fine and the radio does what it is supposed to do. When I request the Frequency readout from the radio, for example it reads 52.370.000 MHz, all the 00 are dropped. A portmonitor shows me all the 00 coming across but commMG drops them. Here is the program: expandcollapse popup#include <CommMG.au3> #include <MsgBoxConstants.au3> Global $CMPort = 8 Global $CmBoBaud = 19200 Global $sportSetError = '' Global $CmboDataBits = 8 Global $CmBoParity = "none" Global $CmBoStop = 2 Global $setflow = 2 Global $freq Global $complete, $alltogether, $iRet _CommSetPort($CMPort, $sportSetError, $CmBoBaud, $CmboDataBits, $CmBoParity, $CmBoStop, $setflow) _CommSetRTS(1) _CommSetDTR(1) If @error Then MsgBox(16,"Error!","Can't connect to IC-7300 on port : "&$CMPort) Exit EndIf $bBinData = "" $bBinData = $bBinData & "0xFEFE94E003FD" ;command to request Frequency readout _SendToRadio($bBinData) $fromradio = _CommGetLine("",32,500) ;reads buffer up to 50 char's but does not read 00's ?? ; input spaces for easier reading not really needed for $i = 1 to StringLen($fromradio) $ascStr = Asc(StringMid($fromradio, $i)) $hexStr = Hex($ascStr,2) $complete &= $hexstr $alltogether = $alltogether & " " & $hexStr Next MsgBox(0,"IC-7300", "Conv with spaces: " & $alltogether & @CRLF & "Binary from radio: " & Binary($fromradio) & @CRLF & "Radio ACK: " & $iRet & @crlf) $filehandle = FileOpen("ic7300.txt",1) FileWrite ($filehandle,"in Buffer: " & $fromradio & @crlf) FileWrite ($filehandle,"Converted to HEX: " & $alltogether & @CRLF) FileWrite ($filehandle,"Expected: FE FE E0 94 03 00 00 37 52 00 FD"& @CRLF) FileWrite ($filehandle,"DllStructGetData returns: " & $iRet & @CRLF) FileClose($filehandle) _CommClearOutputBuffer() _CommClearInputBuffer() _CommCloseport() Exit Func _SendToRadio($bBinData) _CommClearOutputBuffer() _CommClearInputBuffer() $bBinData = Binary($bBinData) $iNumbytes = BinaryLen($bBinData) $tBinData = DllStructCreate("byte["&$iNumbytes&"]") $struct = DllStructSetData($tBinData, 1, $bBinData) $iRet = _CommSendByteArray(DllStructGetPtr($tBinData),$iNumbytes,1) If @error Or $iRet = -1 Then ConsoleWrite("!Error: " & @error & @CRLF) $iRet = _CommReadByteArray(DllStructGetPtr($tBinData), $iNumbytes, 1) $iRet = DllStructGetData($tBinData, 1) sleep(1000) Return $iRet EndFunc Here is the txt file output in Buffer: þþà”7Rý Converted to HEX: FE FE E0 94 03 37 52 FD DllStructGetData returns: 0xFEFE94E003FD Expected: FE FE E0 94 03 00 00 37 52 00 FD Let me explain the HEX stuff radio language - FE FE E0 94 03 00 00 37 52 00 FD: FE (OK) FE (OK) this is radio with ID (E0) answering to PC with ID (94) to the request Send FREQ readout (03) and the readout is 00 00 37 52 End of report (00) Ready (FD) 00 00 37 52 needs to be converted to 52.370.000 (got that function done already) The radio send data 'backwards", starting with tens, hundreds and so on. Also notice that the DllStructGetData does not have any returned data, it still has the data to request the frequency readout. How can I get those double 00's in the returned data from the device (Radio)? Thanks for your help KF5WGB Edited August 17, 2019 by KF5WGB Link to comment Share on other sites More sharing options...
Gianni Posted August 17, 2019 Share Posted August 17, 2019 (edited) Hi @KF5WGB have you tried the _Commgetstring() function instead of _CommGetLine() to see if something changes? (former IK1VQE) Edited August 17, 2019 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
jchd Posted August 17, 2019 Share Posted August 17, 2019 (edited) You send binary data to the receiver, but read string data. In many string functions (not only here), a binary 0x00 in the string means "end of string", like in C. Here, is seems the 0x00s are simply ignored by the Comm DLL. You should use _CommReadByteArray() to read binary data from the device. Edited August 17, 2019 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
KF5WGB Posted August 17, 2019 Author Share Posted August 17, 2019 (edited) 9 hours ago, jchd said: You send binary data to the receiver, but read string data. In many string functions (not only here), a binary 0x00 in the string means "end of string", like in C. Here, is seems the 0x00s are simply ignored by the Comm DLL. You should use _CommReadByteArray() to read binary data from the device. Hi jchd, I did. Check towards the end of the _SendToRadio function. That's where FileWrite ($filehandle,"DllStructGetData returns: " & $iRet & @CRLF) gets it's data from. Guess I miss something. Edited August 17, 2019 by KF5WGB Typo Link to comment Share on other sites More sharing options...
KF5WGB Posted August 17, 2019 Author Share Posted August 17, 2019 9 hours ago, Chimp said: Hi @KF5WGB have you tried the _Commgetstring() function instead of _CommGetLine() to see if something changes? (former IK1VQE) Hi Chimp, Yes i did try that. Like jchd said, 0x00 means end of string and _CommGetString() cuts it even shorter. The dll just ignores them. Anyway, I found another UDF called CommInterface.au3. That one 'gets' all of the returned data BUT has hickups. The Purge command to clear the buffer does not work right. Sometimes the returned string is only a part of the complete data and sometimes it is longer than expected, meaning data from the "pull" before is still in the buffer. I have to send the request multiple times before the "right and complete" data returns. For now I run a for-next loop to check for stringlength. Not very elegant but gets the job done...kinda. Link to comment Share on other sites More sharing options...
jchd Posted August 17, 2019 Share Posted August 17, 2019 2 hours ago, KF5WGB said: I did. Check towards the end of the _SendToRadio function. That's where FileWrite ($filehandle,"DllStructGetData returns: " & $iRet & @CRLF) gets it's data from. Guess I miss something. Yes, but you don't do anything with the value returned from _SendToRadio($bBinData) Then you issue: $fromradio = _CommGetLine("",32,500) Which I suppose is there where 0x00s are ignored (or maybe binary zeroes are not written to the file in text mode). This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
KF5WGB Posted August 18, 2019 Author Share Posted August 18, 2019 3 hours ago, jchd said: Yes, but you don't do anything with the value returned from _SendToRadio($bBinData) Then you issue: $fromradio = _CommGetLine("",32,500) Which I suppose is there where 0x00s are ignored (or maybe binary zeroes are not written to the file in text mode). OMG, You are right. I forgot all about it. Thanks for pointing this out. I stared at this for 2 days and did not see it. I changed _SendToRadio($bBinData) to $fromradio = _SendToRadio($bBinData) and removed CommGetLine. Then I found that the received data string is longer than the struct created with just the request of $bBinData & "0xFEFE94E004FD". All that was left to do was to increase the size a few bytes. It helps to read the programmers part of the radios amnual 🙂 $bBinData = $bBinData & "0xFEFE94E003FD0000000000000000000000" ;command to request Frequency readout PLUS receive bytes Once that was done I got the complete data back from the Radio: 0xFEFE94E003FDFEFEE094030000375200FD - structs....gotta love 'em A little String magic and the readout looks like this: 52.370.000 MHz Thanks jchd Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now