Modbus over RS-485 and RS-232
The Modbus protocol can be implemented over RS-485 and RS-232 physical layers. The Waspmote platform provides the necessary hardware and software for working with both protocols. The name and use of the functions are the same for RS-232 and RS-485, and the only changes are the library to include and the instantiation of the object. The differences between the two standards are explained in the corresponding communication guides.
Both RS-232 module and RS-485 module can implement Modbus since, it is simply a software layer built on top the physical layer. That is why we suggest to start developing in RS-232 or RS-485, and after this, continue with Modbus.
The Modbus library has been tested with various devices and is compatible with the majority of commercial modules, but this does not ensure the working with all of them. Be sure that the Modbus module fits your technical requirements. The final user is the responsible to perform the task of communicating the Modbus module with other commercial devices.
Modbus over RS-232
The first step to use Modbus over RS-232 is to include the corresponding libraries and instantiate the necessary objects. Below you can see how to include this library.
After including libraries, you have to instantiate a ModbusMaster
object. Below you can see that an object called slave
has been created in the address "1" (in the assumption that an actual Modbus slave is connected in that address), and the corresponding communication protocol is configured, in this case RS232_COM. When the master needs to communicate with the address "1", it must use this object.
Example of code to run in slaves nodes:
After including the libraries, you have to instantiate a ModbusSlave
object.
Modbus over RS-485
The first step to use Modbus over RS-485 is to include the corresponding libraries and instantiate the necessary objects. Below you can see the complete process.
Example of use in master mode:
After including libraries, you have to instantiate a ModbusMaster
object. Below you can see that an object called slave has been created in the address "1" (in the assumption that an actual Modbus slave is connected in that address), and the corresponding communication protocol is configured, in this case RS485_COM. When the master needs to communicate with the address "1", it must use this object.
Example of use in slave mode:
After including the libraries, you have to instantiate a ModbusSlave
object.
Last updated