parsing strings of varying length
Rich Abel
Posts: 104
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
0
Comments
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
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.
If you're just testing for an empty string, I'd skip G_B_S and just use LENGTH_STRING...
- Chip