parsing strings of varying length
Rich Abel
Junior Member
Looking for suggestions on parsing return strings from a device. The strings are variable length. There is no distinct end character.
One thought I had was to use get_buffer_string to break the string up into specific blocks by their meaning. I can do this by looking at the leading character of each block.
Does anyone know what get_buffer_string returns if the Array is empty or shorter than the specified length? If the behavior is consistent, I can use this to indicate that I'm done parsing.
Thanks,
Rich
One thought I had was to use get_buffer_string to break the string up into specific blocks by their meaning. I can do this by looking at the leading character of each block.
Does anyone know what get_buffer_string returns if the Array is empty or shorter than the specified length? If the behavior is consistent, I can use this to indicate that I'm done parsing.
Thanks,
Rich
Comments
-
Rich, if there is no distinct end character, how would YOU tell when you had a complete message - if YOU were looking at characters coming in from the device? I'm guessing there are one or two bytes at the head of each message that indicate the length of the total message? Is there a unique header to the device's messages?
Break it down to eensy steps. If YOU can figure out what the messages look like if they were coming back from the device, then you can figure out how to tell the control system to do the same...
- Chip -
parsing strings of varying length
The return string can have 4 possible lengths and I can identify the length based upon the response. That's how I've implemented the code.
I was thinking that if there was a reliable response to a get_buffer_string when the string was empty, then I could use this as an indicator that I'd parsed the entire string, and make for a simpler approach.
Thanks. -
Could you do something like this?
// RUN ONLY WHEN THERE'S SOMETHING IN THE BUFFER WHILE(LENGTH_STRING(cBUFFER)) { cRESULT = GET_BUFFER_STRING(cBUFFER,LENGTH_STRING(cBUFFER)) IF(!LENGTH_STRING(cBUFFER)) PARSING_FINISHED = 1 } -
Rich Abel wrote:I was thinking that if there was a reliable response to a get_buffer_string when the string was empty, then I could use this as an indicator that I'd parsed the entire string, and make for a simpler approach.
If you're just testing for an empty string, I'd skip G_B_S and just use LENGTH_STRING...
- Chip
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums