silogarrett Posted April 27, 2011 Share Posted April 27, 2011 Hi Guru! I send commands to my frequency inverter and I get a response as shown: Tx (16:07:22.725): \x02\x0C\x00\x00\x00\x00\x00\x00\x00\x04\x7E\x00\x00\x74 Rx (16:07:22.734): \x02\x0C\x00\x00\x00\x00\x00\x00\x00\x0F\x31\x00\x00\x30 Tx (16:07:22.826): \x02\x0C\x00\x00\x00\x00\x00\x00\x00\x14\x7E\x00\x00\x64 Rx (16:07:22.836): \x02\x0C\x00\x00\x00\x00\x00\x00\x00\x0F\x31\x00\x00\x30 Question is, how do I READ the Rx response? I mean, I can translate it once I get it, but I just don't know how to get in into a channel. The Rx does not repeat, it's a one-time response. I've tried the following to no avail: private string datain // get us lined up: //device.DIVERTER.purge() datain = device.DIVERTER.readuntil(56) while(1) try datain = device.DIVERTER.readuntil(56) FI_OUTPUT.addvalue(tranpose(asca(left(datain,56)),1)) catch() ? strLastError delay(0.5) // realign: device.DIVERTER.purge() datain = device.DIVERTER.readuntil(10) endcatch delay(1) endwhile I get a "C1136 Timeout: READ_STUFF Line 24 - Uncaught error in sequence READ_STUFF" Can you guide me? Mike Link to comment Share on other sites More sharing options...
AzeoTech Posted April 28, 2011 Share Posted April 28, 2011 Your probably getting timeout because you are doing readuntil() without actually sending the query to the device. So you are basically waiting for an answer without asking a question! You probably want something that looks like this: purge() while(1) try write(...) readuntil(56) ... catch() ? strLastError purge() endcatch delay(1) endwhile The above is, of course, pseudocode, but you get the idea. Link to comment Share on other sites More sharing options...
silogarrett Posted May 2, 2011 Author Share Posted May 2, 2011 Hi Guru! Here's my attempt using your guidance: device.SORTER.Purge() while(1) try device.SORTER.Write(chra({0x02,0x0C,0x00,0x12,0xCF,0x00,0x01,0x00,0x00,0x04, 0x7F,0x35,0xB8,0x24})) // poll param 719 delay(0.1) datain = device.SORTER.readuntil(56) device.SORTER.readuntil(56) FI_OUTPUT.addvalue(tranpose(asca(left(datain,56)),1)) catch() ? strLastError //device.SORTER.Purge() endcatch delay(1) endwhile But I'm still getting C1136 Timeout errors on line 10. Am I counting enough spaces - is 56 correct? I wanted to simply specify the last hex value received, but then I realized the last character received is a hex block checksum - and it's not always the same value. Can you explain what I'm doing wrong? Mike Link to comment Share on other sites More sharing options...
AzeoTech Posted May 4, 2011 Share Posted May 4, 2011 I think you misunderstand the readuntil() function. It doesn't read 56 characters, but rather reads the input buffer until it finds the ASCII code 56 (or binary 56 depending on your point of view), or times out. You are getting a timeout because you do readuntil() twice, but only do a single write. You probably can eliminate the second readuntil() and things will work a little better. Link to comment Share on other sites More sharing options...
silogarrett Posted July 2, 2012 Author Share Posted July 2, 2012 Hi Guru, A year later, I'm back to this topic. I'm still having trouble with reading from my frequency inverter. Here's my latest sequence: // VARIABLES: PRIVATE private string datain private data // SEQUENCE: try device.DIVERTER.Purge() device.DIVERTER.Write(chra({0x02,0x0E,0x00,0x12,0xD2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xCC})) // chk status datain = device.DIVERTER.readuntil(242) // read until 0xF2 data = asca(datain) RELAY_STAT.addvalue(data) catch() endcatch // END SCRIPT After execution of the sequence, the screengrab of the Comm monitor looks like this: Tx (14:44:00.691): \x02\x0E\x00\x12\xD2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xCC Rx (14:44:00.701): \x02\x0E\x00\x12\xD2\x00\x00\x00\x00\x00\x00\x0F\x31\x00\x00\xF2 Exactly what I expect, but for the life of me, no matter what I try, I cannot accomplish the READ. The channel did get an entry, but it is NaN. The DATAIN and the DATA always come up NaN. I've tried ?Datain and I get NaN - which doesn't make sense if its a string - at least to me. I've tried AscA, Asc, Chra, Chr, GetLength, parsing, everything I can think of to see what Datain looks like. No success. I am assuming that \xF2 in the Rx equals the ASCII 242, and thus my ReadUntil(242). I've also tried Read(0) and Read(1) to no avail. Please SHOW me what to do to accomplish this simple task? PLEASE HELP! Link to comment Share on other sites More sharing options...
AzeoTech Posted July 9, 2012 Share Posted July 9, 2012 The script looks ok, but something else might be wrong. First, always put: ? strLastError inside catch() blocks, at least until you finish debugging, otherwise, any errors are just ignored and thus probably just throwing away the answer to your problem. Second, try changing "datain" to something else, like "strDataIn", just in case there is a name conflict with dataIn, not that I see one. Finally, you realize that you are adding the entire array of bytes to Relay_stat? You probably just want data[11] or [12] or something, though you aren't this far yet. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.