lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] ModbusTCP


From: Sergio R. Caprile
Subject: Re: [lwip-users] ModbusTCP
Date: Fri, 22 Jun 2018 09:49:04 -0300
User-agent: Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

Modbus/TCP is Modbus over TCP port 502, with a simple header (MBAP).
A Modbus master is quite simple, and unless you have to support all
intricacies of different brand proprietary stuff, it ends up being just
a couple of functions.
The only tricky part is the word alignment, since registers are
big-endian 16-bit entities and depending on the function they are
aligned to a 16-bit address or not, inside the message.
Then you have to collect the message from TCP, and that is what the
header is for.
A slave is a bit more involved, particularly over serial lines, and
specially when an OS controls the serial port, and that is why you can
find some libraries around. There are a number of free implementations
and examples anyway, including the master, that will help you build your
code.
All you need is at modbus.org.

Summing up:
A Modbus/TCP master is a TCP client that connects to a TCP server and
sends an ADU: a simple 7-byte header (MBAP) followed by a simple Modbus
query (PDU). That query depends on what you need from the slave,
typicals are input and holding register reads, and if you need to
actually change something, then holding register writes. That means you
have 4 elementary functions building a simple ~5-byte query if we
include the slaveid, to know the slave. Then you send that to TCP and
you start a timer and sit waiting for the response or a timeout.
The response echoes your function call (or indicates an error),
indicates the number of elements included, and carries what you asked for.
As simple as that, no states, no handshakes, just a plain old stateless
client-server interaction



reply via email to

[Prev in Thread] Current Thread [Next in Thread]