Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Endianess for ModbusTcpServer

See original GitHub issue

I have seen that the ModbusTcpServer checks if we have Little or Big-Endian. My system (Linux ARM32) is Little-Endian. When I check the data (with ModbusPoll) - it is not reversed.

For example:

Span<short> inputreg = server.GetInputRegisterBuffer<short>();
inputreg[0] = 1;

In ModbusPoll I got “256” (0x0100), I expected “1” (0x0001). It was possible that I manually reverse my data before with ModbusUtils.SwitchEndianness(), but I was wondering if there is a cleaner solution for it.

With the client I was able to receive the data in the correct endianess:

client.Connect(IPAddress.Parse(""), ModbusEndianness.BigEndian);

It would be great if someone could help me, or tell me if it makes sense to reverse every single value before.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

Apollo3zehncommented, Aug 28, 2020

Yes the content is returned without changes. The check in the extension method will be lightweight, so you should not notice any performance impact.

Start offset: If you set the 8 byte double value to buffer[1], it would be located at byte positions 8-15 which is equal to Modbus registers 4-7 (with 2 bytes per Modbus register). But if you want to have it located at Modbus registers 1-5, you need a way to specify a start offset (in bytes).

Since everything is clear for me now, I will prepare a draft and hopefully finish it on Monday.

mkroesencommented, Aug 29, 2020

Sounds good, I think this is a good solution. Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Modbus TCP Little Endian Byte Swop
Modbus commonly uses 'big/little endian' to refer to the order in which it transmits 16-bit chucks of a larger 32-bit ( or in...
Read more >
Common Modbus Protocol Misconceptions
Overview. This article should be useful if you are writing your own Modbus communication software. These issues generally don't cause problems if you...
Read more >
Modbus Endianness : r/PLC
Modbus protocol is big-endian in that the most significant byte of a 16-bit word is transmitted first. Micro800 is also big-endian, ...
Read more >
Modbus Poll display formats
Modbus Poll display formats: ; Signed; Unsigned; Hex ; 32 Bit signed Big-endian; 32 Bit signed Little-endian; 32 Bit signed Big-endian byte swap...
Read more >
How Real (Floating Point) and 32-bit Data is Encoded in ...
Given that the Modbus RTU message protocol is big-Endian, in order to successfully exchange a 32-bit datatype via a Modbus RTU message, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found