Convert String to PackBit in Redlion G3

As my Dad use to say, "There is only one operation: counting."

Nice, you should get there.

Displaying the 16-bit word values in hexadecimal* will make it easier, because there will always be two hex digits per character, and there are simple mnemonics to convert between most characters and their hex representation:

  • Numbers
    • the character '0' is ASCII code 48 decimal 0 + 3 * 16dec = 0 + 0x30hex = 0x30hex
    • digits '1' through '9' are in sequence after '0'
      • '1' is ASCII code 49dec** =1+48dec = 1 + 3*16dec = 9 + 0x31hex = 0x31hex
      • '2' is ASCII code 50dec = 2+48dec = 2 + 3*16dec = 2 + 0x30hex = 0x32hex
      • ...
      • '9' is ASCII code 57dec = 9+48dec == 9 + 3*16dec = 9 + 0x30hex = 0x39hex
  • Alpha
    • The character '@' is ASCII code 64dec = 4*16dec = 0x40hex, and "root" of the uppercase alphabet
      • 'A' is ASCII code 65dec = 1 + 64dec = 1 + 4*16dec = 0x41hex
      • 'B' is ASCII code 66dec = 2 + 64dec = 2 + 4*16dec = 0x41hex
      • ...
      • 'J' the 10th (dec) uppercase letter is ASCII code 74dec = 10dec + 64dec = 10dec + 4*16dec = 0xAhex + 0x40hex= 0x4Ahex
        • Ahex is 10dec
        • Bhex is 11dec
        • Chex is 12dec
        • Dhex is 13dec
        • Ehex is 14dec
        • Fhex is 15dec, the last single hex digit, so
          • 1+Fhex = 0x10hex,
          • i.e. carrying the 1 the same way that
          • 1+9dec = 10dec does, because 9 is the last single dec digit
      • 'Z' is the 26th (dec) uppercase letter is ASCII code 90dec = 26dec + 64dec = 26dec + 4*16dec = 0x1Ahex + 0x40hex = 0x5Ahex
    • The character '`' (backtick) is ASCII code 96dec = 6*16dec = 0x60hex, and root of the lowercase alphabe
      • 'a' is ASCII code 97dec = 1 + 96dec = 0x61hex = 1 + 6*16dec
      • ...
      • 'z' is ASCII code 122dec = 26dec + 96dec = 0x7Ahex = 26dec + 6*16dec = 0x1Ahex + 0x60hex
  • Other - no mnemonic or sequence, but here are some examples
    • ' ' (space) is ASCII code 32dec = 0 + 2*16dec = 0 + 0x20hex = 0x20hex
    • '!' (bang; exclamation) is ASCII code 33dec = 1 + 2*16dec = 0 + 0x20hex = 0x21hex
    • ...
    • '~' (tilde) is ASCII code 127dec = 15dec + 7*16dec = 0xFhex + 0x70hex = 0x7Fhex
    • ASCII 0 to 31dec = 0 to 0x2Fhex represent unprintable (control) characters that are typically not present in a string, although sometimes a null (ASCII code 0) is a terminator for a string of otherwise non-null characters.
      • Exceptions are
        • <CR> carriage return is ASCII code 13dec = 13dec + 0*16dec = 0xDhex + 0x00hex = 0x0Dhex
        • <LF> linefeed a.k.a. newline is ASCII code 10dec = 10dec + 0*16dec = 0xAhex + 0x00hex = 0x0Ahex
        • N.B. Control-M on most ASCII keyboards send <CR> i.e. ASCII code 13dec = 0x0Dhex, and M is the 13th (dec) letter of the alphabet
          • Same for Control-J and <LF> ASCII code 10dec = 0x0Ahex
* sometimes referred to as BCD, though they are not strictly the same

** "dec" means decimal i.e. base 10
 
making some progress.

The packed bit shows up as expected. But, Kep only wants to read the first bit of the array. Not sure why that is the case.

Just curious: do you have it configured the way B. Gallimore did in that video you linked?

  • Kepware OPC [Tag Properties] dialog window just after 2m11s in the video
  • Red Lion [Navigation Pane] ane [Resource Pane] just after 3m2s in the video?
    • I.e. with every member of the array having a sequential Modbus address assigned to it?
It looks like you did in one of the images in the previous posts, so I wonder why it did not work.
 
Last edited:
String data to int array.
Code:
int x;
int i;
int hByte,lByte;
x := Len(string);

for(i=0;i<x;i++)
{
	hByte := string[i*2] <<8;
	lByte := string[i*2+1];
	int_array[i] := hByte+lByte;
}
xyz.png
 

Similar Topics

Hi I need to convert a DINT with HEX value e.g A0F15663 to a string with the same value 'A0F15663'. Any tips of good instructions to use ...
Replies
11
Views
3,317
hi, i try to capture barcode data using UDT with SINT ascii array. i have all the data i need but it in array format, how can i convert to 1...
Replies
5
Views
3,016
Found an awesome point of sale for $500. It sends an ascii string when a product is sold. Need to convert this into a number between 0 and 255 or...
Replies
1
Views
2,256
I'm trying to display a Allen Bradley Controller Serial Number that's in HEX to String for my SCADA to display. Any ideas?
Replies
3
Views
2,781
Firs of all I'm working with Structured Text on B&R Automation Studio 4.0: I have a binary message on a string (collected from serial port). The...
Replies
4
Views
8,085
Back
Top Bottom