Announcement

Collapse
No announcement yet.

Help parsing a variable length string that is stored with byte swap

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help parsing a variable length string that is stored with byte swap

    I am reading a string into a DL260 with a F2-CP128 coprocessor that is stored with byte swap. I am sending this string with PRINT to a Datamax printer out Port 2.
    Everything prints correctly.
    The string is always an exact length with an even number of characters for each field.

    My new challenge is to be able to parse the string when the fields can be any length with a space character in between fields. The space character is not unique. The fields use spaces, too.
    I can set up a screen to enter the lengths of fields, but since the data is byte swapped and can be an even or odd amount of characters into the string, I have not been able to figure out how to get the correct starting character for the field.

    For example, the first three fields can be 1 to 24 of characters long. Each field has a space after the data.

  • #2
    So....... SPACE is the delimeter and also is valid string content -- and the field/string are variable lengths?


    1. Who is generating the strings? Can you have formatting info embedded into the string (like a header)
    -if your plc sees a header then it knows to perform special parsing. If no header use existing parsing.

    2. Are you required to maintain backwards compatibility of the messages?
    -if not - always embed header info in the info that your plc receives

    3. Do other devices use/see these strings (input to your plc and output to the printer)
    -if other devices use/see the strings that your plc RECEIVES, you may not be able to use anything mentioned above.
    -if other devices use/see the strings that your plc SENDS, you could have the input strings modified to supply formatting info

    Comment


    • #3
      Thanks Kewaki,
      The string comes from a custom PC database program. It is sent to an existing machine and cannot be edited. Our new owner wants our machine to be able to accept the same string. No header. The string is sent to a printer to create a label and back to the PC database program to update calculated packages to actual packages.

      What I have so far and is working for the first 2 fields (that is as far as I have gotten so far) is to check the count of characters and spaces and if it is even add one to get the first character and if odd subtract one to get the first character. Also, if an odd number, add one to the total number of characters for that field, because of the byte swap.

      FYI,
      Checking the last digit of the counter in binary. 0=even 1=odd

      Comment

      Working...
      X