{"id":5125,"date":"2025-05-26T10:21:44","date_gmt":"2025-05-26T09:21:44","guid":{"rendered":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/?page_id=5125"},"modified":"2025-05-26T10:23:09","modified_gmt":"2025-05-26T09:23:09","slug":"modbus-device-monitoring","status":"publish","type":"page","link":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/?page_id=5125","title":{"rendered":"Modbus Device Monitoring"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>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&#8217;t something I&#8217;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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Interface Hardware<\/h2>\n\n\n\n<p>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&#8217;s Linux OS) and to attempt to source a unit with a genuine FTDI chip. I chose to use a supplier I&#8217;d had good service from before and elected to buy this unit from <a rel=\"noreferrer noopener\" href=\"https:\/\/www.ebay.co.uk\/str\/technofixuk\" target=\"_blank\">TechnoFix UK<\/a>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/wp-content\/uploads\/2022\/10\/s-l1600.jpg\" alt=\"\" class=\"wp-image-5126\" width=\"442\" height=\"395\" srcset=\"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/wp-content\/uploads\/2022\/10\/s-l1600.jpg 968w, https:\/\/www.marshflattsfarm.org.uk\/wordpress\/wp-content\/uploads\/2022\/10\/s-l1600-300x269.jpg 300w, https:\/\/www.marshflattsfarm.org.uk\/wordpress\/wp-content\/uploads\/2022\/10\/s-l1600-335x300.jpg 335w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><figcaption>USB to RS-485 Adaptor from TechnoFix UK<\/figcaption><\/figure>\n<\/div>\n\n\n<p>When connecting this device to a Raspberry pi, <code>\/var\/log\/syslog<\/code> reports:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kernel: &#91; ] usb 1-1.4: new full-speed USB device number 4 using dwc_otg\nkernel: &#91; ] usb 1-1.4: New USB device found, idVendor=0403, idProduct=6001, bcdDevice= 6.00\nkernel: &#91; ] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3\nkernel: &#91; ] usb 1-1.4: Product: FT232R USB UART\nkernel: &#91; ] usb 1-1.4: Manufacturer: FTDI\nkernel: &#91; ] usb 1-1.4: SerialNumber: &lt;SECRET>\nkernel: &#91; ] usbcore: registered new interface driver usbserial_generic\nkernel: &#91; ] usbserial: USB Serial support registered for generic\nkernel: &#91; ] usbcore: registered new interface driver ftdi_sio\nkernel: &#91; ] usbserial: USB Serial support registered for FTDI USB Serial Device\nkernel: &#91; ] ftdi_sio 1-1.4:1.0: FTDI USB Serial Device converter detected\nkernel: &#91; ] usb 1-1.4: Detected FT232RL\nkernel: &#91; ] usb 1-1.4: FTDI USB Serial Device converter now attached to ttyUSB0<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Interface Software<\/h2>\n\n\n\n<p>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 <a href=\"https:\/\/github.com\/gavinying\/modpoll\" target=\"_blank\" rel=\"noreferrer noopener\">modpoll<\/a> looking the most promising for my purposes:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Open source and written in Python, which I have recently become familiar with<\/li><li>Built-in functionality for interacting with MQTT as well as Modbus-RTU, which was already my preference for sharing the readings<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">CIRCUTOR CVM-1D<\/h2>\n\n\n\n<p>The first device I attempted to monitor was an electricity meter (or &#8220;power analyzer&#8221; as the manufacturer likes to call it &#8211; 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.<\/p>\n\n\n\n<p>The manufacturer&#8217;s information page is <a rel=\"noreferrer noopener\" href=\"https:\/\/circutor.com\/en\/products\/fixed-power-analyzers\/fixed-power-analyzer\/power-analyzer-single-phase-din-rail\/product\/M55511.\/\" target=\"_blank\">here<\/a> and the user manual (PDF format) is <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.circutor.com\/docs\/M98236001-03.pdf\" target=\"_blank\">here<\/a>. The user manual confirms the (default) settings for the Modbus-RTU parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>A Baud Rate of 19,200<\/li><li>A Device ID of 1<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t something I&#8217;d had any previous experience of though &hellip; <a href=\"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/?page_id=5125\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":5856,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-5125","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/5125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5125"}],"version-history":[{"count":2,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/5125\/revisions"}],"predecessor-version":[{"id":5128,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/5125\/revisions\/5128"}],"up":[{"embeddable":true,"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=\/wp\/v2\/pages\/5856"}],"wp:attachment":[{"href":"https:\/\/www.marshflattsfarm.org.uk\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}