Variable Length Serial Commands
Claude
Posts: 3
Greetings-
I’m attempting to use SERIN to process a variable length commands originating at a PLC. The commands deal with relay control. For example:
RLYA – Prints the status of all relays
RLY1OFF – Turns off relay 1
RLY1ON – Turns on relay 1
XXX – Other commands I’m not interested in processing (note these are three bytes long)
I would like nothing more than to say SERIN RX, Baud, 1000, Do_Task_1, [noparse][[/noparse]STR serStr\7] and read as few as 3 or as many as 7 bytes. I’m seeing that you can only specify only the number of byte you can safety anticipate. That is, I start with SERIN \3 and either determine I have a valid command (“RLY”[noparse];)[/noparse] or not. If the string equals “RLY”, I do a SERIN \1 and determine if the string equals “A” or “1 thru 9”. If “1 thru 9”, then I do a SERIN \2 to get an indication of an ON (“ON”[noparse];)[/noparse] or OFF “OF”[noparse];)[/noparse].
I must be missing something, because this shouldn’t be this hard. Can the group suggest an alternative? --Thanks
Best Regards,
Claude
I’m attempting to use SERIN to process a variable length commands originating at a PLC. The commands deal with relay control. For example:
RLYA – Prints the status of all relays
RLY1OFF – Turns off relay 1
RLY1ON – Turns on relay 1
XXX – Other commands I’m not interested in processing (note these are three bytes long)
I would like nothing more than to say SERIN RX, Baud, 1000, Do_Task_1, [noparse][[/noparse]STR serStr\7] and read as few as 3 or as many as 7 bytes. I’m seeing that you can only specify only the number of byte you can safety anticipate. That is, I start with SERIN \3 and either determine I have a valid command (“RLY”[noparse];)[/noparse] or not. If the string equals “RLY”, I do a SERIN \1 and determine if the string equals “A” or “1 thru 9”. If “1 thru 9”, then I do a SERIN \2 to get an indication of an ON (“ON”[noparse];)[/noparse] or OFF “OF”[noparse];)[/noparse].
I must be missing something, because this shouldn’t be this hard. Can the group suggest an alternative? --Thanks
Best Regards,
Claude
Comments
I used this approach in a recent project (albeit with a BS1), SERIN waits for a header "59/GDL" instead of "CO"· --
Post Edited (PJ Allen) : 1/5/2006 2:41:03 AM GMT
The serin command has a couple of special switches when reading in STR variables. You can specify that it read in a certain number of characters OR, until it sees a certain character, like a carriage return or line feed.
See the Stamp help file for SERIN.
Cheers
These things are really outside of the SERIN command, but greatly support it.
You might find a way to have the PLC issue a header that will tell the receiver how many bytes to expect.
You can set up a receiver to recieve a maximum size or less, then pare down what it has recieved by dumping the empty portion of the buffer. No changes to the PLC
Or back to modifying the PLCC, you might re-think your code and find a way to stadardize it to one particularlly useful packet size. Each nibble gives you 16 possilbe codes in one context and each byte can be 256 codes in one context. If you need to transmit ASCII, you can use 7bit ASCII and have an extra bit to indicate something else.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Best reagards,
Claude