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 _______________________________________________ lwip-users mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/lwip-users
