To Byte swap or not to Byte swap, that is the question

Ozpeter

Member
Join Date
Aug 2014
Location
Virginia
Posts
124
I am writing software for a system(*) that has the following data flow

4-20mA Sensor => Siemens AI 8xU/I/RTD/TC ST card
Siemens AI 8xU/I/RTD/TC ST card => Simatic ET 200MP Profinet remote I/O scanner
Simatic ET 200Mp => Emerson/GE PLC

What I am having a hard time figuring out is do I need to byte swap the word data in the PLC or not?

I've looked in the manual for the AI card and I cant see anything that defines it as being big endian or little endian data. I also have no experience with Siemens systems, so I don't know what I should expect.

Does anyone have any experience in exchanging data between Siemens and Emerson PLCs?

----

(*) If I actually had some hardware in front of me I would test this out.
 
In my experience siemens usually requires byte swaps, hope for the best but prepair for the worst.
Byte swapping itself is not very hard to accomplish with the built in inscructions.
 
In these situations I find it much quicker to initially code it naively i.e. assume no byte swap, and then look at the bits inside the destination device and compare them to what would be expected from a known value sent by the source device (e.g. apply a calibrated 4/8/12/16/20mA signal, or measure what is there).


If you are not bit-savvy, post your test data here e.g. table of (mA, Emerson integer value) pairs, plus the expected range and format (16-bit INT; 32-bit REAL; etc.).



Maybe the protocol takes care of it.
 
What systems are you exchanging data with that require byte swapping?

I know I can achieve by swapping via a single instruction, but I don't want to have people in the field (who will do the commissioning) having to modify my code because I guessed wrong.
 
In these situations I find it much quicker to initially code it naively i.e. assume no byte swap, and then look at the bits inside the destination device and compare them to what would be expected from a known value sent by the source device (e.g. apply a calibrated 4/8/12/16/20mA signal, or measure what is there).

While I would do that if I had my choice:

1. The hardware is being specified in Finland
2. The PLCs are incorporated in machinery being built in China
3. The company contracted to do the programming is based on the East Coast of the US
4. I am writing the code in my home office in the SW of the US
5. The machinery will be delivered to a totally different part of the USA.

Welcome to global projects!

So actually testing the hardware is kind of impossible
 
1) If there are only two choices, make an in-place byte-swap conditional on a spare discrete input, and deciding whether to put a jumper on that input is the first step of the I/O checkout during commissioning.

2) If the DN range is small e.g. 0-4095 then the code could figure it out on the fly pretty fast.

3) Either of those choices is probably comparable to the cost of buying/borrowing the individual hardware pieces (eBay?) and doing it on a test bench.
 
Answering my own question. I just discovered the Siemens manual A5E03461439-AC which is:

"S7-1500, ET 200MP,ET 200SP, ET 200AL, ET 200pro, ET 200eco PN Analog value processing"

Which has a wonderful chapter called "Representation of analog values" which goes down to the bit level.

EG the decimal value of 27648 is represented as 0110110000000000 from MSB to LSB. Which matches the Emerson PLC format for the same value.

So technically no byte swap is needed between Siemens and Emerson.
 
I don't think you are out of the woods yet, how does the emerson plc store the value 0001 in a word consisting of two bytes?


Here's how it is stored in a siemens plc. The least significant bits are stored in the most significant byte.

bits.jpg
 
I am with @L D on this: that document describes MSBit and LSBit i.e. bits in the entire 16-bit INT, but does not answer the question of byte order in a multi-byte value, i.e. whether bits [7-0] are first or last.

I found the information below at this link; the screenshot and other links referred to are not much help.

That said, I would be amazed if Profi-whatever does not define byte order in its specification, (it's not a fly by night protocol like Modbus, after all ;)), but who knows? I found a claim by one person that they never had to do a byte-swap of Profi-obtained data for many different devices, and another who had to byte-swap in an Omron PLC.


[Update: is Profinet/Profibus even a protocol, or is it a different layer?]


yyy.png
 
Last edited:
1) If there are only two choices, make an in-place byte-swap conditional on a spare discrete input, and deciding whether to put a jumper on that input is the first step of the I/O checkout during commissioning.

2) If the DN range is small e.g. 0-4095 then the code could figure it out on the fly pretty fast.

I like this concept from drbitboy

I would build the function with byte swap capability as a built in option like this, only I would prefer an internal bit that could be accessed by an HMI. You could always map that bit to a discrete input if necessary to completely avoid any need to edit the function in the field.
 
If there are multiple analog channels with one spare, the spare could be supplied with a known signal (e.g. 8mA, 25% of scale) and have the GE/Emerson figure out the byte order from that channel.
 
.. or use a constant value.


I thought of that first, but this ET 200MP scanner is transmitting digitized data from analog input devices. Does it even have its own internal values it could send?


Also, the analog signal chosen to decode byte order needs to be done with care. E.g. I mistakenly suggested 25% of scale e.g. 8mA in a 4-20mA channel. If the analog card is 12 bit, the signal would be near 1024, which breaks down to 4 in the high-order byte and 0 in the low-order byte; half a percent of noise or error and that could read as 1028, which puts 4s in both high- and low-order bytes. There is also the issue that all ranges are left-aligned, i.e. bit-padded on the right, to push them out to 16 bits if bi-polar or to 15 bits if unipolar, so a 12-bit uni-polar channel (0-4k) sends values from 0 to +32k nominally, as does a 14-bit channel (0-16k).
 

Similar Topics

I have a C-More HMI that changes my PLC String from "Machine Status" to "aMhcni etStasu" . There is an option with other objects that have string...
Replies
15
Views
3,413
Good Morning, I'm using RS Logix 5000 to program an Allen-Bradley 1769-QBFC1B Version 20.12 and want to use the Byte Swap Instruction (SWPB)...
Replies
7
Views
4,798
I ran into a situation where some devices I use display String bytes in a swapped order as they are stored in my PLC (CompactLogix). I thought it...
Replies
3
Views
3,809
Hi guys I'm having some weird data conversion issue over modbus happening. And I found a post here before that is similar to what I'm seeing but...
Replies
6
Views
7,072
Hello everybody, I have a communication to a Linux-PC via sockets. So I created a quite large UDT with all the content. Unfortunately we have to...
Replies
1
Views
2,140
Back
Top Bottom