Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 16 Serial and Ethernet Communications > 16.9 Predefined Protocols

16.9.6 ModbusTCP/RTU/ASCII Slave protocol

Scroll Prev Top Next More

The ModbusTCP, ModbusRTU and ModbusASCII Slave protocols allows you to set DAQFactory up as a Modbus slave.  A modbus slave receives commands from a master and performs those commands.  Typically, PLC's and other devices are the slave and SCADA applications such as DAQFactory are the master.  DAQFactory can act as the Modbus master but it can also act as a slave.  This is useful if you want to integrate DAQFactory into a larger SCADA system that acts as a Modbus master, or you wish to network DAQFactory using Modbus instead of the built in networking.

Setting up the slave protocol is similar to other protocols.  Please review the section on Creating a Comm Device for more information about working with protocols.  Once you have created a device with the ModbusTCP, ModbusRTU or ModbusASCII Slave protocol, you can assign Modbus register addresses to any channels you wish to have accessible through the slave.  This is done right in the channel configuration, either in the channel table or the channel view in the Mod Slave # or Mod Slave Tag area, NOT the Channel #.  The numbers you assign are rather arbitrary, but should be unique in your system.  Register addresses under 10,000 (but greater than 0) will result in a signed 16 bit word, the default Modbus type, to be returned.  Registry values 10,000 and over are treated as 32 bit floating point values.  Since this takes 2 Modbus words, the register address should increment by 2 (i.e. 10000, 10002, 10004, etc).  The duplicate button in the channel table will do this for you automatically.  

Once the register addresses are assigned, a Modbus master can connect in and retrieve and set values.  The Modbus Slave protocols supports Modbus function codes 3 and 4 for reading values and treats these codes the same way.  It also supports function code 16 to set values.  All other codes are ignored.  The default slave address of DAQFactory is 1.  This is a variable of the protocol, so you can change it using the simple script: Device.mydevice.ModbusAddress = newvalue where mydevice is the name you gave the slave device, and newvalue is the new address.

There are also two system events you can use in addition to, or as a replacement for Modbus Slave identification in channels:

OnMBSlaveGetValue: if a sequence with this name exists, the sequence will be called passing in a variable called tag whenever the slave driver receives a request for a value (Modbus commands 3 or 4).  You can either return the value you want associated with that tag, or nothing if you want to let the channel handle it.  

OnMBSlaveUpdate: if a sequence with this name exists, the sequence will be called whenever the slave driver receives a command to set a value (Modbus commands 6 or 16).  A variable called tag along with a variable called val will be passed in. Tag is the modbus tag to adjust, while val holds the new value.  If you process the request, you should return something, though it doesn't matter what.  If you return nothing the slave will continue to attempt to process the request through channels.

Note: if tag < 10000, your value will be adjusted to fit into a signed 16 bit integer.  If is is >= 10000 it will be adjusted to fit into a 32 bit floating value.  This is based on the first tag of the request, so if your Master requests 6 registers starting at 9998, DAQFactory will convert all of them to signed 16 bit even though some of the registers in the block are >= 10000.

Note: With ModbusTCP slave you will typically use the Ethernet Server and not the Ethernet Client you would use for ModbusTCP master.  You certainly can apply any of these protocol to any of the port types, however, this arrangement is the most common.

Note: The Modbus Slave protocols requires DAQFactory Standard or higher.