TCP Socket Hex Data

mjp123gp

Member
Join Date
Mar 2012
Location
Savannah, GA
Posts
94
Hello,

I'm trying to setup a TCP connection from a Compactlogix 5069-L306ER to a TDI checkweigher to receive real-time weight data of the filled jugs. The Compactlogix controller would be the TCP server. I used the sample code from Rockwell's website and I've been able get the connection setup and receive data from the checkweigher.

The issue I'm having is the data I get in the PLC is in ASCII format. I need this data to be in HEX so I can use the OEM's hex map to extract only the weight variable I need.

The attached picture shows the data being received in the Net Assistant software that I used for testing this connection before the PLC was setup. In the receive options of Net Assistant, it has a check box where I can select ASCII or HEX to receive.

Does anyone know how I can get the Compactlogix controller to receive this data in HEX format?

Thanks in advance!

TDI Data Received.jpg
 
I don't know what is meant by HEX data here, because HEX is a form of display for binary data (e.g. 8 bits per byte); technically HEX characters ('0' '1' '2' ... 'E' 'F') are ASCII characters, each representing one nibble (4 bits, or half) of an 8-bit byte.

If the data received by the CompactLogix using the ReadSocket Service (cf. here), then the data of interest are in the .Buf[] array element, with data type SINT (8-bit signed integer), of the Destination Element passed to the ReadSocket Service.

The values of SINT data run from 0 to 127 decimal (0x00 to 0x7F hexadecimal) and -128 to -1 (0x80 to 0xFF).

If you want to compare data in that .Buf[] array against hexadecimal values, you can do it like this: EQU RCVD.Buf[108] 47H, where 47H is a literal for the hexadecimal value 0x47.
 
In a TCP connection you receive exactly what the other side sends, it is not possible to do a conversion on the fly, if you receive ASCII then your PLC program should convert it to what you need.

There are several ways to receive data, it all depends on who designed the protocol, sometimes the pure hexadecimal value is received as Modbus does, other times the representation in ASCII characters of the decimal value is received or also the representation in ASCII characters of the hexadecimal value, and more ways that surely exist
 
Hello,

I'm trying to setup a TCP connection from a Compactlogix 5069-L306ER to a TDI checkweigher to receive real-time weight data of the filled jugs. The Compactlogix controller would be the TCP server. I used the sample code from Rockwell's website and I've been able get the connection setup and receive data from the checkweigher.

The issue I'm having is the data I get in the PLC is in ASCII format. I need this data to be in HEX so I can use the OEM's hex map to extract only the weight variable I need.

The attached picture shows the data being received in the Net Assistant software that I used for testing this connection before the PLC was setup. In the receive options of Net Assistant, it has a check box where I can select ASCII or HEX to receive.

Does anyone know how I can get the Compactlogix controller to receive this data in HEX format?

Thanks in advance!
If you know the precise byte order of the weigher equipment, you would find the first byte position of the weight in the payload returned and just COP it into a REAL.
 
It is essential to have the exact specification of the protocol and know what each of the received bytes is.

There is usually a header that must be read first and may indicate whether there has been an error or the number of bytes in the transmission.

After reading the header, if there is no error, the data can be read.

You must keep an exact count of how many bytes are read and how many bytes remain to be read, since in a TCP connection the data can arrive grouped in different blocks as they were sent.
 

Similar Topics

Hi Everybody, newbie here with PLCs, using a B&R plc. I'm playing with a printer and its tcp socket communication. Connection works fine if...
Replies
3
Views
156
Hi all, I have two questions I am hoping someone might have some information on. 1. I remembered reading somewhere on this forum that you could...
Replies
5
Views
194
I would like to communication with application installation in my printer server via TCP port 5450. i.e ., 71.16.40.200:5450 . How can i write...
Replies
1
Views
417
I'm trying to set up a TCP Socket connection between a CompactLogix 1769-L16 and a printer that can receive external data through a TCP socket. I...
Replies
7
Views
3,372
I am at a plant right now that is installing a domino ax350i inkjet printer and it is using tcp socket ascii communication to talk to a compact...
Replies
0
Views
1,499
Back
Top Bottom