Modbus Device Monitoring

Introduction

While re-engineering a failed electric vehicle charging unit it proved necessary to re-integrate a couple of Modbus-based devices in order to read their registers and (potentially) control their behaviour. This isn’t something I’d had any previous experience of though I had done some research previously, with a view to controlling some other systems I suspected might be using Modbus internally.

Interface Hardware

The first challenge is electrically connecting the RS-485 bus to a Raspberry Pi or similar and the obvious solution is one of the dedicated USB to RS-485 adaptors, of which there is a large choice on eBay. Based on previous bad experiences with poor quality USB to RS-232 adaptors I wanted a unit based on the FTDI FT232RL chip (which is well supported under the Raspberry Pi’s Linux OS) and to attempt to source a unit with a genuine FTDI chip. I chose to use a supplier I’d had good service from before and elected to buy this unit from TechnoFix UK.

USB to RS-485 Adaptor from TechnoFix UK

When connecting this device to a Raspberry pi, /var/log/syslog reports:

kernel: [ ] usb 1-1.4: new full-speed USB device number 4 using dwc_otg
kernel: [ ] usb 1-1.4: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00
kernel: [ ] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
kernel: [ ] usb 1-1.4: Product: FT232R USB UART
kernel: [ ] usb 1-1.4: Manufacturer: FTDI
kernel: [ ] usb 1-1.4: SerialNumber: <SECRET>
kernel: [ ] usbcore: registered new interface driver usbserial_generic
kernel: [ ] usbserial: USB Serial support registered for generic
kernel: [ ] usbcore: registered new interface driver ftdi_sio
kernel: [ ] usbserial: USB Serial support registered for FTDI USB Serial Device
kernel: [ ] ftdi_sio 1-1.4:1.0: FTDI USB Serial Device converter detected
kernel: [ ] usb 1-1.4: Detected FT232RL
kernel: [ ] usb 1-1.4: FTDI USB Serial Device converter now attached to ttyUSB0

Interface Software

The second challenge is handling the Modbus-RTU protocol. Lots of other people have solved this problem in various different ways and from a quick review of options I settled on a Python-based utility called modpoll looking the most promising for my purposes:

  • Open source and written in Python, which I have recently become familiar with
  • Built-in functionality for interacting with MQTT as well as Modbus-RTU, which was already my preference for sharing the readings

CIRCUTOR CVM-1D

The first device I attempted to monitor was an electricity meter (or “power analyzer” as the manufacturer likes to call it – to be fair it does a lot more than just record kWh usage) made by Circutor. I was confident this had been communicating successfully using Modbus-RTU with the previous, proprietary control board.

The manufacturer’s information page is here and the user manual (PDF format) is here. The user manual confirms the (default) settings for the Modbus-RTU parameters:

  • A Baud Rate of 19,200
  • A Device ID of 1

CC BY-SA 4.0 Modbus Device Monitoring by Marsh Flatts Farm Self Build Diary is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.