Scanner Bytes to Text
medium
Turns the bytes a barcode scanner sends into a STRING without its carriage return.
What it teaches
Serial and network devices often deliver text as an array of SINTs, one character each, plus a count. A STRING tag starts with its LEN, so copying the bytes into the tag itself turns the first four characters into the length. The bytes belong in DATA, the characters after LEN from Display New Text, and writing DATA never changes LEN, so the length is yours to set: a count of 2 makes 'HI', whatever bytes follow. Then drop the final $r as the reply's was dropped in Strip the Terminator; a code without one, such as 'XYZ', is kept whole.
Parameters
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| In_Count | Input | DINT | 4 | How many bytes arrived, 0 to 40 |
| Ref_Buffer | InOut | SINT[40] | — | The bytes as the scanner sent them, one character each |
| Ref_Code | InOut | STRING | — | The code as text |
Required behavior
- A barcode scanner's bytes arrive in Ref_Buffer, one character per SINT, and In_Count says how many there are. The scanner ends each code with a carriage return, byte 13 ($r).
- Every scan, Ref_Code holds the first In_Count bytes of Ref_Buffer as text, without a final $r: bytes 65, 66, 67, 13 are 'ABC'.
- Writing bytes into Ref_Code.DATA does not change Ref_Code.LEN, so set LEN to the number of characters. Bytes after In_Count are left over from earlier codes and are not part of this one.
- Copying Ref_Buffer into the STRING tag itself fills LEN first: the first four bytes become the length.
- In_Count is always 0 to 40. Never change Ref_Buffer.
- With the default In_Count of 4, Ref_Code is 'ABC'.