2

I have a barcode scanner that communicates with a 1756-L75 ControlLogix PLC over RS232.

The data from the scanner is read in byte by byte and stored in a SINT array as characters. It includes a header and the barcode data. The barcode data is variable in length.

I need to convert this array of characters into a proper STRING datatype.

I know that I can copy the array into the data portion of the string, but I'm looking for the best way to fill in the length.

Is there a built-in instruction that will automatically do that or will I need calculate it?

lcecl
  • 326
  • 2
  • 11

1 Answers1

1

My current (untested) solution is as follows.

I'm assuming that the character array and the string are cleared before data is read.

  1. Execute an FSC (File Search and Compare).
    • Here I've populated the .LEN with the size of the character array. This ensures that the instruction will search to the end of the array.
    • Search for the first element that is still null
    • The FSC will report the index of the element it finds. This equals the length of the actual data.
 char  -> 'd' 'a' 't' 'a' $00 $00
 index ->  0   1   2   3   4   5
                           ^
.POS = 4
  1. Move the FSC result (.POS) into the string's .LEN
  2. Copy the characters to the string data
  3. Do what you need with the data, then clear the character array, clear the string, and reset the FSC to get ready for the next barcode.

screenshot of ladder logic

Note that logic preceding these instructions has been stripped in an effort to reduce clutter so assume that this only executes for one scan after a barcode is read. You may also need additional logic if it's possible for the barcode data to completely fill the character array.

chris neilsen
  • 52,446
  • 10
  • 84
  • 123
lcecl
  • 326
  • 2
  • 11