Modbus DIA Server
From Digi Developer
Enabling the DIA Modbus Server
The DIA Modbus server allows remote Modbus masters/clients to query your DIA devices as if they were Modbus devices. However, the data has been cached by the Digi gateway, so if the DIA device is sleeping and wakes only once per hour, then the Modbus data returned will be repeated (stale) for the entire hour.
Each device appears as a distinct Modbus destination with the I/O such as:
- 4 analog inputs (field to system)
- 4 analog outputs (system to field)
- 16 digital inputs (field to system)
- 16 digital outputs (system to field)
More information is on this Wiki page: Modbus_Dia_Block_Register_Map
How the Modbus Unit Id (or Slave Address) is mapped to DIA device is covered on this Wiki page: Enable_Modbus_Query_of_Dia_Devices
(Future work) You build custom Modbus maps on a channel-by-channel basis.
Robust Block Server
This version runs only on Digi gateways with the Modbus/IA Engine. DIA uses Modbus/UDP on localhost to the IA Engine, which provides a mature and robust multi-master solution.
It allows up to 32 incoming Modbus masters via:
- Modbus/TCP in TCP/IP or UDP/IP
- Modbus/RTU on gateway serial ports, or encapsulated in TCP/IP or UDP/IP
- Modbus/ASCII on gateway serial ports, or encapsulated in TCP/IP or UDP/IP
- Digi Realport on Windows set up for UDP mode, which enters the Modbus/IA Engine as a Modbus/RTU or Modbus/ASCII master encapsulated in UDP/IP
By Web UI
To enable correct bridging of Modbus into the DIA, create a simple Industrial Automation configuration summarized by these steps:
- Click the Applications | Industrial Automation link on the left side of the display
- Confirm a Modbus Protocol table exists, or add one if required. The table name can be anything
- Click the Table Name to see the Table Settings page
- Add at least one message source (an incoming Master/Client). This could be Modbus/TCP on Ethernet or any other selection. More than one can be created.
- Add a message destination to a Modbus/TCP in UDP/IP on IP 127.0.0.1, UDP port 8502. To start with, route all messages to this and place it in the first row (index #1).
- reboot the gateway
By CLI over Telnet or SSH
set ia table=1 state=on name=DigiDia family=modbus accessmode=multi set ia table=1 ownerperiod=15000 set ia table=1 addroute=1 set ia table=1 route=1 active=on type=ip protaddr=0-255 protocol=modbustcp set ia table=1 route=1 transport=udp connect=passive address=127.0.0.1 set ia table=1 route=1 ipport=8502 replaceip=off slavetimeout=1000 set ia table=1 route=1 chartimeout=50 idletimeout=0 lineturnmode=off set ia table=1 route=1 fixedaddress=0 rbx=off set ia master=1 active=on type=tcp ipport=502 protocol=modbustcp table=1 set ia master=1 priority=medium messagetimeout=2500 chartimeout=50 set ia master=1 idletimeout=0 lineturnmode=off errorresponse=on set ia master=1 broadcast=replace
The Final Result
Your final IA Engine Configuration should look something like this (web colors may vary - this is a NDS web customization):
DIA YML Changes
Below is an example YML showing use of DIA 1.3 with auto-enumeration of XBee AIO and LTH sensors. Any device discovered will be automatically added to the Modbus server/slave list.
- You MUST use the special Modbus 'sub-class' for the DIA drivers - such devices.modbus.mbdia_xbee_aio:MBusXBeeAIO. These behave like the normal DIA drivers, but have the added Modbus calls to create the Modbus register maps
- You must include the Modbus server presentation: presentations.modbus.mbdia_pres:MbDiaPresentation
- name: xbee_device_manager driver: devices.xbee.xbee_device_manager.xbee_device_manager:XBeeDeviceManager - name: xbee_autoenum driver: devices.xbee.xbee_devices.xbee_autoenum:XBeeAutoEnum settings: xbee_device_manager: xbee_device_manager short_names: True devices: - name: ain driver: devices.modbus.mbdia_xbee_aio:MBusXBeeAIO settings: sample_rate_ms: 60000 power: "On" sleep: False channel1_mode: "CurrentLoop" channel2_mode: "CurrentLoop" channel3_mode: "CurrentLoop" channel4_mode: "CurrentLoop" - name: lth driver: devices.modbus.mbdia_xbee_sensor:MBusXBeeSensor settings: sleep: True sample_rate_ms: 15000 awake_time_ms: 5000 presentations: - name: mbus_srv driver: presentations.modbus.mbdia_pres:MbDiaPresentation settings: mapping: "('auto', 1, 20)" auto_enum_name: xbee_autoenum
Seeing the Modbus 'Unit Id/Slave Address' assignment
The Modbus DIA server maintains a text file in the gateway's Python file systems named 'mbus_map.txt'. Every time it boots, it starts by reading this file (if it exists). Any new nodes seen are appended. You can edit this file at any time, reordering the lines.
This is a static example of mbus_map.txt, where the devices were manually entered by name in the YML as mapping: "( (1,'solar'), (2,'outdoor'), (3,'indoor') )"
# DIA Modbus Server unit_id mapping as of 2010-03-24 15:01:56 1,'solar','XBeeAIO','00:13:a2:00:40:4b:90:24!' 2,'outdoor','XBeeSensor','00:13:a2:00:40:4a:6e:83!' 3,'indoor','XBeeSensor','00:13:a2:00:40:32:14:FA!'
This is a dynamic/autoenum example of mbus_map.txt
# DIA Modbus Server unit_id mapping as of 2010-03-26 21:46:48 1,'lth_14_c6','XBeeSensor_LT','[00:13:a2:00:40:32:14:c6]!' 2,'lth_15_1a','XBeeSensor_LT','[00:13:a2:00:40:32:15:1a]!'