FLProg - New implementation of Modbus RTU exchange
Earlier, at Habré, I talked about the implementation of the support for the Modbus protocol in the FLProg program. Unfortunately, as the practice of its use has shown, the implementation was not very successful. If Slave worked even more or less confidently, then the master was very unstable. In addition, the assignment of register addresses was possible only as a continuous array, and there was no division into memory areas. The master in that implementation could only apply to Holding Registers of slaves, which greatly limited the possibilities of its use. For a long time, I was looking for a normally implemented Modbus RTU library for Arduino, but searches did not lead to success. Therefore, it was decided to write the implementation of the exchange on Modbus RTU independently. And in the recently released version of the FLProg program with the number 1.12, this is done. What changed:
The implementation of Modbus RTU is fully compatible with industry standard.
Implemented four variable tables - Coils, Discrete Inputs, Input Registers, Holding Registers. For each variable, you can set any address (not necessarily sequentially).
Implemented the ability to set the slave address, port speed and disable / enable polling of a particular slave by the master programmatically with storing this data in the EEProm.
The possibility of simultaneous work of the master and the slave on one controller (on different ports) is implemented.
Implemented the ability to use SoftwareSerial as a port
Thanks to the dynamically generated code, simultaneous operation of the master and the slave is possible even on the Pro-Mini board.
Implemented direct compatibility with older versions - previously created projects will work on the new version without rework.
In this lesson I decided to do what may be really useful. Having run through the online stores, I found the victim - we will duplicate the sensors and actuators on the RS-485 bus sold in the Wiren Board store . Why they? Yes, I just killed their prices. Especially outraged by the price of sensors DS18B20 . On the site, they honestly talk about their Chinese origin, and at the same time they request 400 rubles. Although in China, even at retail, their price is 102 rubles . And when wholesale is certainly much cheaper. Interesting - the margin of more than 300% - this is a trip to the mail?
Total - 307 rubles. As it is cheaper than two thousand rubles. I think out of distribution at wholesale prices on their board, the cost will be even less. Schematic diagram:
Well, now, finally, we will assemble a device that will collect data and manage these blocks. To display information and control, we will use a smartphone on Android. The connection will be made via Bluetooth, and the software will be the HMI-KaScada software . On the Arduino board, Modbus Master (for collecting information from the blocks) and Modbus Slave (for working with the HMI-KaScada program) will be organized simultaneously.