UE9 Modbus Support
From LabJack Wiki
UE9 Modbus User’s Guide
December 26, 2006
1.0 Introduction
Modbus is an industry standard command-response protocol for data acquisition and control equipment. This document assumes that the user is either familiar with the Modbus protocol or a software package which handles most of the Modbus details is being used. For detailed information about Modbus visit the website at "http://www.modbus.org/".
Beta Modbus support was first added to the UE9 with comm. firmware 1.41 and control firmware 1.70. Both the control and comm. firmware are required for Modbus functions.
2.0 Modbus Support History
Firmware Comm/Control
1.41/1.70 Added beta Modbus support. Functions 1, 2,3,4,5,6,15, and 16 implemented. 3 and 4 mostly tested.
1.42/1.71 Improved Modbus packet generation. Functions 1, 2,3,4,5, and 6 should be fully working.
3.0 Communicating to the UE9 via Modbus
Modbus commands must be sent to port 502 and must be formatted as a Modbus TCP over Ethernet packet. Any commands received over ports other than 502 will be interpreted as a LabJack proprietary command.
Future Comm firmware versions will make it possible to change port that the UE9 receives Modbus commands on.
4.0 Supported Modbus Functions
The UE9 supports 8 Modbus functions. Sections 4.1 through 4.8 describe the supported functions.
4.1 Read Discrete Inputs (Modbus Function #2)
The Read Discrete Inputs function was intended by the Modbus protocol to read the state(s) of digital inputs. The UE9 does not distinguish between inputs and outputs. So, the UE9 will return the state of any requested digital IO regardless of their direction setting.
Valid Discrete Addresses:
FIO[0:7]
EIO[0:7]
CIO[0:3]
20-22 MIO[0:2]
4.2 Read Coils (Modbus Function #1)
Reference the Read Discrete Inputs Function
The Read Coils function is intended by the Modbus protocol to read the state(s) of digital output. However, when reading the state(s) of digital IO the UE9 does not distinguish between inputs and outputs, so this function is exactly the same as the Read Discrete Inputs Function.
4.3 Read Input Register (Modbus Function #4)
This function will retrieve the data contained in the UE9’s internal registers. Modbus defines a register as 16-bits.
| Address | Data Type | Permissions | Function(s) |
|---|---|---|---|
| 0-511 | AIN (32-bit float) | R | 3,4 |
| 1000-1511 | Ain (16-bit raw) | R | 3,4 |
| 2000-2511 | AIN Resolution index | R/W | 3,4,16 |
| 3000-3511 | AIN BP/Gain index | R/W | 3,4,16 |
| 4000-4511 | AIN Settling index | R/W | 3,4,16 |
| 5000-5099 | DAC Values (32-bit float) | W | 16 |
| 5100-5199 | DAC Values (16-bit RAW) | R/W | 3,4,16 |
| 6000 | Read FIO states | R | 3,4 |
| 6001 | Read EIO states | R | 3,4 |
| 6002 | Read CIO states | R | 3,4 |
| 6003 | Read MIO states | R | 3,4 |
| 6100 | Write FIO states | W | 6,16 |
| 6101 | Write EIO states | W | 6,16 |
| 6102 | Write CIO states | W | 6,16 |
| 6103 | Write MIO states | W | 6,16 |
| 6200 | FIO Directions | R/W | 3,4,6,16 |
| 6201 | EIO Directions | R/W | 3,4,6,16 |
| 6202 | CIO Directions | R/W | 3,4,6,16 |
| 6203 | MIO Directions | R/W | 3,4,6,16 |
| 7000-8999 | Reserved (Timers etc.) | ||
| 9000-9099 | Unipolar CAL | R | 3,4 |
| 9200-9299 | AIN Bipolar CAL | R | 3,4 |
| 9400-9499 | CAL Other (DAC, Temp etc.) | R | 3,4 |
All of the analog data is considered 32-bits. To work with the 16-bit address map the 32-bits needs to be read or written by accessing two 16-bit registers. This means that in order to read an analog input, input parameter, or analog output two registers need to be read. The first address for any channel is two times that channel number. As this implies, a read of an analog parameter must always start on an even channel.
For example, to read the AIN Resolution index of AIN1 two registers must be read starting at 2002. The data returned as a big-endian unsigned long.
MikeF: I think it would be a good idea to move related registers together. IE. FIO State and Direction together.
Upon powering up all analog input resolutions will be set to maximum (17-bit or 18-bit for UE9-Pro). The BP/Gain idex will be set to 8, which corresponds to bipolar with a gain of 1 (range of +-5V). For more information about the BP/Gain idexes reference the BipGain descriptin in the Feedback section (5.3.3) of the user's guide.
4.4 Read Holding Registers (Modbus Function #3)
The UE9 does not distinguish between input and holding registers. Any readable register in the address table shown above can be read by this function or the Read Input Register function. So, to the UE9 this function is identical to the Read Input Register function. A holding register is considered by the Modbus protocol to be an analog output.
4.5 Write Single Coil (Modbus Function #5)
This function will write the state of a digital output. If a write is made to a line that is set to input an invalid address error will be returned.
Valid Discrete Addresses:
FIO[0:7]
EIO[0:7]
CIO[0:3]
20-22 MIO[0:2]
4.6 Write Single Register (Modbus Function #6)
This function allows a single register to be written. At this time only the writing of digital states can be accessed with this function.
All analog registers must be written as 32-bits, so this function is incapable of writing the analog parameters or analog outputs.
4.7 Write Multiple Coils (Modbus Function #15)
This function will operate the same as the Write Single Coil function with the exveption that multiple coils can be written with a single function call.
4.8 Write Multiple Registers (Modbus Function #16)
This function is the same as the Write Single Register function with the exception that several registers can be written with a single function call.
5.0 What can and can't be done through ModBus
Some of the UE9's features are not available through ModBus. The following sections list the features that may be included in the future, and UE9 features that there are no plans to make available through ModBus.
5.1 Features that may be added
5.2 Features that currently have no plans to be added
6.0 Difference in UE9 behavior when using ModBus
When using ModBus serveral behavioral differences should be kept in mind.
7.0 QuickMod example
This example uses AzeoTech's QuickMod tool to communicate with a UE9 via ModBus. QuickMod is a simple utility that should be able to communicate to any ModBus compliant device. QuickMod is included with all non express versions of DaqFactory and is available as a stand alone download from the AzeoTech website at www.azeotech.com/downloadqm.php.
Before attempting to run this example, ensure that the UE9 can communicate to the computer via Ethernet. You can use LJControlPanel to verify the Ethernet connection. If you have trouble communicating, reference the Ethernet troubleshooting section of the UE9 Quickstart Guide.
Before attempting to communicate to the UE9 via Modbus, be sure you have Comm firmware 1.42 and Control 1.71 or later.
Once you have the proper firmware, verified the Ethernet connection, and installed the QuickMod utility, follow the steps below.
- Launch QuickMod from the DAQFactory directory of the programs menu.
- An introduction screen, describing QuickMod and available DAQFactory licenses will show up. Select "Start" to continue to the QuickMod Utility.
- We now need to configure QuickMod to talk to the UE9. In the top left corner, select TCP over Ethernet.
- Click "Configure". The "Ethernet Configuration" window will open. Enter the IP address of the UE9 you wish to talk to, then click "Save."
- Under Type select float from the drop down menu.
QuickMod will now be reading the UE9's first four analog inputs. Note that AIN0 corresponds to address 0, and AIN1 corresponds to address 2. This is because Modbus specifies that all registers be 16-bits wide, and the analog data is 32-bits wide.
There are four parameters that control the data being retrieved from the UE9. The first is "Function," this parameter determines what type of register is being read. ModBus specifies several different register types, but for simplicity all readings are available through the holding registers. The second is "Type," this parameter specifies how to interpret the data read from the UE9, as well as how many registers need to be read per data point. The third is "Tag #," this is the first address that will be read. The default is zero which is half of an analog measurement. With float selected for the type QuickMod will read two consecutive addresses and interpret them as a float. The fourth parameter is "# pts," this parameter tells QuickMod how many data points you want to read.
To select other data to read consult the address map in section 4.3 of the UE9 Modbus user's guide page: http://www.labjack.com/wiki/UE9_Modbus_Support. To read the states of the digital IO lines set the first address to read, which is referred to as Tag# on Modbus, to 6000. Also, set the data Type to "Unsigned Integer (16)." Now the states of FIO, EIO, CIO and MIO should be displayed as 255, 255, 15 and 7 (assuming that the UE9 is set to factory defaults and the terminals are open). Notice that QuickMod automatically changes the number of addresses that it reads data from based on the data type selected.
Appendix A – Glossary
Coil – The term coil refers to the coil of a relay. Within the context of Modbus functions a coil can be can be considered a digital output..
