Home AMX User Forum NetLinx Studio
Options

parsing strings of varying length

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

Comments

  • Options
    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
  • Options
    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.
  • Options
    jjamesjjames Posts: 2,908
    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
    }
    
  • Options
    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
Sign In or Register to comment.