What is a Slave?
In terms of the Client-Server network computing paradigm, the Slave application is a Server. It has a Listener for receiving an incoming Request from the Master application (which indeed is a Client) and sends a corresponding Response.
I need to write Modbus RTU master app in Java that support 03 - Read Holding Registers and 16 - Write Multiple Registers. I found three java libraries: jamod, j2mod, modbus4j.I try all of these libraries (I spend about 4 hours) and it still doesn't work. Modbus is a serial communication protocol. Originally developed by Modicon in 1979. Use with Modicon PLC. Modbus is a very simple protocol. Modbus protocol also defined as a master-slave protocol. Means device operating as master will poll one or more device operating as slave.master user read data from slave device register. Master user Write data from slave device register.
As described in Understanding the Protocol, each cycle of Request and Response is called a Transaction.
Figure 1 shows a simple graphical representation of such a cycle:
In case of the serial implementation, the communication can be point-to-point (RS232, EIA422) or on a shared signal cable (EIA485). In both cases there should be only one master, that acquires data from a source (data acquisition), or writes data to a sink (device control).
A possible simple network setup for this tutorial is composed of two nodes, as depicted in Figure 2.
The implementation from the jamod library will automagically construct the actual responses for requests related to the standard Modbus data model, according to the contents of the actually set Process Image. The reference to the actual Process Image is stored in the Modbus Coupler a singleton instance accessible throughout the VM.
This is a fork of Java Modbus Library (jamod) - http://jamod.sourceforge.net/. Original SVN revision at the time of fork was 26 according to https://svn.code.sf.net/p/jamod/svn/trunk/.
Commits from openhab1-addons (modbus binding) and openhab2-addons (modbus transport) bundle have been rebased on top of clean jamod SVN checkout. Further details are documented in openHAB2 Modbus binding PR.
About
This project represents a Modbus implementation in 100% Java. It can be used to implement Modbus masters and slaves in various flavors:
- Serial: ASCII, RTU (Master only), BIN
- IP: TCP, UDP
The design of this library is fully object oriented, based on abstractions which should support easy understanding, reusability and extensibility.
One important goal of this project is a codebase that is easily usable on a variety of Java Platforms (and devices). Many limited resource devices do not provide Java 5 and Java 6 environments, and there are only limited possibilities for logging.