Friday, March 22, 2013

Modbus RTU

Artisan v0.6 adds a new device call MODBUS. Selecting that one allows you to have Artisan talk to your Modbus RTU device. Modbus is a de facto standard serial communication protocol connecting industrial electronic devices. Artisan supports the RTU (Remote Terminal Unit) variant and plays the role of the supervisory computer, while the connected devices have to be the slaves. Interesting devices for us are variable-frequency drive controllers that allow to control the speed of your drum and fans as well as PID controllers. But there are also temperature meters that provide a Modbus link.

Reading Registers

Let's take one of those later devices to explain the general setup. David found the 2 channel myPCLab device with a rather small price tag. It comes with the required USB connector as well as some software. Of course David preferred to use Artisan for logging, because of its specific features targeting the coffee roasting process. He had first to select MODBUS in Artisan's device dialog (Config/Device menu). Next he specified the device registers that hold the temperature values in the Modbus tab of the Serial Ports Configuration dialog. According to the manual, that device reports the value of probe one in register 4 and that of probe two in register 5. David specified those registers numbers as Artisan's Modbus Input 1 and Input 2, selected as slave id 1 (Artisan deactivates channels with slave id 0 and this specific device ignores the slave id), and finally he inserted the serial communication parameters, like port and speed. 

He encountered one complication. The temperature 152.8C is reported by that meter as 1528. No problem, he just add the formula x/10.0 for both, ET and BT in the tab Symb ET/BT of the Device Assignment dialog to fix this. Done.

The myPCLab also reports the ambient temperature from an internal probe in register 6. So David pointed Artisans Modbus Input 3 to that register. To have this 3rd curve being logged he had also to add an extra device of type +MODBUS_34 to enable addressing the Modbus channels 3 and 4. As for ET and BT he adds x/10.0 as formula.

Writing to Registers

The communication with Modbus devices is not limited to read access only. The event button and slider actions also allow to write values into registers of Modbus devices. For example, my variable-frequency drive controller (a VersiDrive from Peter electronic) accepts set points for the drive speed in register 1, so I have a slider Drum defined with the Command write([1,1,{}]) following the general syntax of the write command. It takes a list of triples specifying the slave id, the register number as well as the value. Here I filled the value with the placeholder {} that gets substituted by the slider value.


Thanks David for your support in developing the Modbus support for Artisan!

Follow-up post: More Modbus