Create a string from a group input (48 bytes)

How to create a string from a group input?

The string represents the content of 2D barcode glued on a container. The 2D barcode contains 48 bytes of information. The barcode value is transmitted to a IRB140 robot using an Allen-Bradley PLC.

48 bytes can be handled by 12 UDINT in RAPID. Should 12 group inputs be created and merged using PackRawBytes, then interpreted as a string using UnpackRawBytes? It works in theory, but I'd like to know if there is a better way to do this.

I do not have access to a robot at the moment. Thanks!

Best Answer

  • Bulli
    Bulli Germany RLP
    Accepted Answer
    Hi fross,

    i´m using this Function for reading a Barcode out of the PLC. I didnt know any other way to convert a groupinput to string. But the string is limited to 80 signs, so maybe you have to split it.

    Maybe this is helpfully for you

    FUNC string fReadString()
            VAR string Out;
            VAR rawbytes raw_data_IO;
            ClearRawBytes raw_data_IO;
            PackRawBytes GInputDnum(giGlasID1),raw_data_IO ,1\IntX:=UDINT;
            PackRawBytes GInputDnum(giGlasID2),raw_data_IO ,5\IntX:=UDINT;
            PackRawBytes GInputDnum(giGlasID3),raw_data_IO ,9\IntX:=UDINT;
            PackRawBytes GInputDnum(giGlasID4),raw_data_IO ,13\IntX:=UDINT;
            PackRawBytes GInputDnum(giGlasID5),raw_data_IO ,17\IntX:=UDINT;
            PackRawBytes GInputDnum(giGlasID6),raw_data_IO ,21\IntX:=UDINT;
            PackRawBytes GInputDnum(giGlasID7),raw_data_IO ,25\IntX:=UDINT;
            UnpackRawBytes raw_data_IO,1,Out\ASCII:=25;
            RETURN Out;


  • lemster68
    lemster68 United States ✭✭✭
    I just had an idea, why not send over the ascii code numbers and then convert those codes to string?  Bulli is right about string size is limited.  Maybe you might write the data into an array.
    Lee Justice
  • fross
    fross Canada
    edited March 29
    I ended up using PackRawBytes and UnpackRawBytes as Bulli pointed out.

    Note that RawBytesLen can be used for the parameter StartIndex of PackRawBytes in order to remove some hardcoded values.

    PackRawBytes GInputDnum(giGlasID1), raw_data_IO, (RawBytesLen(raw_bytes) + 1)\IntX:=UDINT;
Sign In or Register to comment.