Skip to content

OB-216 Modbus Interface Reference

Table – OB-216 Settings

Setting operating modes (Address 100)

ParameterValue rangeFactory valueTypeW/RAddress (DEC)
Operating mode0…6, 8, 11–121UINTW/R100

Operating mode values:

  • Measurement of discrete signals:
    • 0 – impulse counter (discrete signal)
    • 1 – logical input
  • Measurement of analog signals:
    • 2 – voltage measurement
    • 3 – current measurement
  • Temperature measurement:
    • 4 – NTC sensor (10KB)
    • 5 – PTC 1000 sensor
    • 6 – PT 1000 sensor
  • Additional:
    • 8 – digital sensor (1-Wire)*
    • 11 – pulse counter (voltage)
    • 12 – pulse counter (current)

Connected digital sensor (Address 101)

ParameterValue rangeFactory valueTypeW/RAddress (DEC)
Connectable digital sensor0…30UINTW/R101

Connectable digital sensor values:

  • 0 – DS18B20 (1-Wire)
  • 1 – DHT11 (1-Wire)
  • 2 – DHT21/AM2301 (1-Wire)
  • 3 – DHT22 (1-Wire)

Temperature and threshold settings (Addresses 102–105)

ParameterValue rangeFactory valueTypeW/RAddress (DEC)
Temperature correction–99…990INTW/R102
Working parameter*0…10UINTW/R103
Upper threshold-32767…32767250INTW/R104
Lower threshold–32767…327670INTW/R105

Working parameter values:

  • 0 – temperature
  • 1 – humidity

Settings for the pulse counter (Addresses 106–108)

ParameterValue rangeFactory valueTypeW/RAddress (DEC)
Pulse counter mode0…20UINTW/R106
Contact debouncing delay**1…25010UINTW/R107
Number of pulses per counting device***1…655348000UINTW/R108

Pulse counter mode values:

  • 0 – counter on the rising edge of the pulse
  • 1 – counter on the falling edge of the pulse
  • 2 – counter on both pulse edges

Data transfer settings (Addresses 109–116)

ParameterValue rangeFactory valueTypeW/RAddress (DEC)
RS-485 protocol0…10UINTW/R109
MODBUS UID1…24728UINTW/R110
Exchange rate0…83UINTW/R111
Parity and stop bits control0…20UINTW/R112
Interface selection0…20UINTW/R113
Password protection Modbus****0…10UINTW/R116
Modbus password valueA–Z, a–z, 0–9adminSTRINGW/R117–124

RS-485 protocol values:

  • 0 – MODBUS RTU
  • 1 – MODBUS ASCII

Exchange rate values:

  • 0 – 1200
  • 1 – 2400
  • 2 – 4800
  • 3 – 9600
  • 4 – 14400
  • 5 – 19200
  • 6 – 38400
  • 7 – 57600
  • 8 – 115200

Parity and stop bits control values:

  • 0 – no, 2 stop bits
  • 1 – even, 1 stop bit
  • 2 – odd, 1 stop bit

Interface selection values:

  • 0 – automatically
  • 1 – RS-485
  • 2 – USB

Measured value conversion settings (Addresses 130–134)

ParameterValue rangeFactory valueTypeW/RAddress (DEC)
Measured value conversion0…10UINTW/R130
Minimum input value0…20000UINTW/R131
Maximum input value0…20001000UINTW/R132
Minimum converted value–32767…327670INTW/R133
Maximum converted value–32767…327671000INTW/R134

Measured value conversion values:

  • 0 – conversion is disabled
  • 1 – conversion is enabled

Settings for analog output (Addresses 150–156)

ParameterValue rangeFactory valueTypeW/RAddress (DEC)
Analog output control0…40UINTW/R150
Register for writing value in manual mode0…20000UINTW/R151
Converting the manual control value to analog signal0…10UINTW/R152
Minimum input value–500…25000INTW/R153
Maximum input value–500…25001000INTW/R154
Minimum converted analog value0…20000UINTW/R155
Maximum converted analog value0…20001000UINTW/R156

Analog output control values:

  • 0 – control is disabled
  • 1 – automatic control of voltage output
  • 2 – automatic control of current output
  • 3 – manual control of voltage output
  • 4 – manual control of current output

Converting the manual control value to analog signal values:

  • 0 – conversion is disabled
  • 1 – conversion is enabled

Notes:

  • * Used parameter of the selected digital sensor (address 101).
  • ** Delay in milliseconds used to suppress contact bounce in the «Pulse counter» and «Logic input/pulse relay» modes.
  • *** Used only if pulse counter is enabled. The «Value» column indicates the number of pulses at the input, after the registration of which the counter is increased by one. Writing to memory is performed at intervals of 1 minute.
  • **** If «Modbus password protection» is enabled (address 116 value «1»), then the correct password value must be written to addresses 51-58 in order to access the writing functions to the other addresses.
NameDescriptionW/RAddress (DEC)
Command registersee Command codes belowW/R50
Entering Modbus password (8 ASCII characters)Set the correct password to access the recording functions (default value is “admin”). To disable recording functions, set any value other than a password. Allowed characters: A-Z; a-z; 0-9W/R51 – 58

Notes:

  • W/R – type of access to the register write/read;
  • an address like “50” means a 16-bit value (UINT);
  • address like “51 – 58” mean a range of 8-bit values.

Command codes

CodePurpose
18220write settings to flash memory
18263load settings from flash memory
42228device restart
41672reset to factory settings
61989reset the impulse counter (this will clear all values stored in the flash memory)
NameDescriptionW/RAddress (DEC)
IdentifierDevice ID (value 28)R0
Firmware version12R1
Impulse counterW/R4:5
Measured value*R6
Temperature (× 0.1°С)R11
Humidity (× 0.1%)R12
Converted value**R16
Converted analog value***R17

Notes:

  • address of the form «1» means the value of 16 bits (INT);
  • address of the form «2:3» means 32-bit value (ULONG);
  • * Measured value from analog sensors (voltage, current, temperature);
  • ** Converted value of the measured value in accordance with the settings in the registers (addresses 131 - 134);
  • *** The measured value converted into an analog signal at the output in accordance with the settings in the registers (addresses 153 - 156)
NameDescriptionW/RAddress (DEC)
Status registersee Status bits belowR2:3

Status bits:

BitDescriptionEquals 0Equals 1
bit 0impulse counter (discrete)disabledenabled
bit 1counter on the leading edge of the pulsedisabledon
bit 2counter on the trailing edge of the pulsedisabledon
bit 3counter on both pulse edgesdisabledon
bit 4logical inputdisabledenabled
bit 5voltage measurementdisabledenabled
bit 6current measurementdisabledenabled
bit 7measurement by the NTC (10KB) sensordisabledenabled
bit 8measurement by PTC1000 sensordisabledenabled
bit 9measurement by PT1000 sensordisabledenabled
bit 10impulse counter (by voltage)disabledenabled
bit 11impulse counter (by current)disabledenabled
bit 12measurement by DS18B20 sensordisabledon
bit 13measurement by DHT11 sensordisabledon
bit 14measurement by DHT21 sensordisabledon
bit 15measurement by DHT22 sensordisabledon
bit 16automatic output modefor voltagefor current
bit 17manual output modefor voltagefor current
bit 18«IO2» inputopenclosed
bit 19exchange interfaceRS-485USB
bit 20overvoltagenodetected
bit 21undervoltagenodetected
bit 22overcurrentnodetected
bit 23undercurrentnodetected
bit 24temperature highnodetected
bit 25temperature lownodetected
bit 26humidity highnodetected
bit 27humidity lownodetected
bit 28voltage/current input value conversiondisabledenabled
bit 29device settings changessavednot saved
bit 30device calibrationcalibrateduncalibrated
bit 31analog output value conversiondisabledenabled

If the register (address 113) contains the value «0» (automatic selection of the interface), the device will automatically switch and work with USB, while OB-216 is connected to the PC via a USB cable (the RS-485 interface is unavailable while it does). Otherwise, if the cable is disconnected, the device works with the RS-485 interface.

To work with the RS-485 interface only , it is necessary to write the value «1», to the register (address 113); with this setting, the device will not switch to work with USB when the cable is connected.

To work with the USB interface only, it is necessary to write the value «2», to the register (address 113), with this setting the device will work only with the USB interface, and access to the device via RS-485 will be prohibited.

OB-216 allows data exchange with external devices using the Modbus protocol with a limited set of commands (the list is given in List of Supported Functions).

When building a network, the bus topology and master-slave organization is used, where OB-216 acts as a slave. Only one master can be present on the network with one or several slaves. A personal computer software or a programmable logic controller usually acts as a master node.

With this organization, only the master node can act as the initiator of exchange cycles. Host requests are individual (addressed to a specific device). OB-216 transmits in response to individual requests from the master.

If errors are detected in receiving requests, or if it is impossible to execute the received command, OB-216, as a response, generates an error message.

The addresses (in decimal) of the settings registers and their purpose are shown in Settings Registers.

The addresses (in decimal) of the command registers, commands and their purpose are shown in Command Registers.

Addresses (in decimal) of additional registers and their purpose are given in Additional Registers.

The address (in decimal) of the status register and its purpose is given in Status Register.

Function (hex)AppointmentNote
0x03Reading one or more registersMaximum 50
0x06Writing one value to a register
0x08Communication diagnostics

The exchange protocol has clearly defined message formats. Compliance with the formats ensures the correctness and stability of the network.

OB-216 is configured to operate with one of two formats of data bytes: with parity control (Figure 4) and without parity control (Figure 5). In parity control mode, the type of control is also indicated: Even or Odd. Transmission of data bits is performed by the least significant bits forward. By default (during manufacture) the device is configured to operate without parity control and with two stop bits.

Byte transfer is performed at speeds of 1200, 2400, 4800, 9600, 14400 and 19200 bps. By default, during manufacturing, the device is configured to operate at a speed of 9600 bps.

Byte format with and without parity control

Figure 4, 5 – Byte format with parity control (top) and without parity control (bottom)

The frame length cannot exceed 256 bytes for Modbus RTU and 513 bytes for Modbus ASCII.

In Modbus RTU mode the start and end of the frame are monitored by silence intervals of at least 3.5 bytes. The frame must be transmitted as a continuous byte stream. The correctness of frame acceptance is additionally controlled by checking the CRC checksum in the last two bytes.

The RTU address field occupies one byte. The addresses of the slaves are in the range from 1 to 247.

Figure 6 shows the RTU frame format.

RTU frame format

Figure 6 – RTU frame format

In Modbus ASCII mode the start and end of the frame are controlled by special characters:

  • symbol : (0x3A) – for start of the frame;
  • symbols \r\n or CR+LF (0x0D,0x0A) – for the end of the frame.

The frame must be transmitted as a continuous stream of hexadecimal characters. As the frame is bounded by special characters, the timings of the transmissions are not as strict as those for RTU frame. The correctness of frame acceptance is additionally controlled by checking the LRC checksum in the last two transmitted hexadecimal characters.

The address field occupies two hexadecimal characters. The addresses of the slaves are in the range from 1 to 247.

Figure 7 shows the ASCII frame format.

ASCII frame format

Figure 7 – ASCII frame format

The transmitting device generates a checksum for all bytes of the transmitted message. OB-216 similarly generates a checksum for all bytes of the received message and compares it with the checksum received from the transmitting device. If the generated and received checksums do not match, an error message is generated.

The checksum in the message is sent by the least significant byte forward. It is a cyclic redundant code verification based on the irreducible polynomial 0xA001.

Subroutine for CRC checksum generation in C language:

uint16_t GenerateCRC(uint8_t *pSendRecvBuf, uint16_t uCount)
{
const uint16_t Polynom = 0xA001;
uint16_t crc = 0xFFFF;
uint16_t i;
uint8_t byte;
for(i=0; i<(uCount-2); i++){
crc = crc ^ pSendRecvBuf[i];
for(byte=0; byte<8; byte++){
if((crc & 0x0001) == 0){
crc = crc >> 1;
}else{
crc = crc >> 1;
crc = crc ^ Polynom;
}
}
}
return crc;
}

The checksum in the message is transmitted by the most significant byte forward, which is a longitudinal redundancy check.

Subroutine for LRC checksum generation in C language:

uint8_t GenerateLRC(uint8_t *pSendRecvBuf, uint16_t uCount)
{
uint8_t lrc = 0x00;
uint16_t i;
for(i=0; i<(uCount-1); i++){
lrc = (lrc + pSendRecvBuf[i]) & 0xFF;
}
lrc = ((lrc ^ 0xFF) + 2) & 0xFF;
return lrc;
}

Function 0x03 – Reading a Group of Registers

Section titled “Function 0x03 – Reading a Group of Registers”

Function 0x03 provides reading of the contents of registers OB-216. The master query contains the address of the initial register, as well as the number of words to read.

The OB-216 response contains the number of bytes to return and the requested data. The number of registers returned is limited to 50. If the number of registers in the query exceeds 50 (100 bytes), the response is not divided into frames.

An example of the query and response in Modbus RTU is shown in Figure 8.

Example of reading registers (Function 0x03)

Figure 8 – Example of reading registers (Function 0x03)

The function 0x06 provides recording in one OB-216 register. The master query contains the address of the register and the data to be written.

The device response is the same as the master query and contains the register address and the set data. An example of the query and response in Modbus RTU mode is shown in Figure 9.

Example of writing to a register (Function 0x06)

Figure 9 – Example of writing to a register (Function 0x06)

Function 0x08 – Communication Diagnostics

Section titled “Function 0x08 – Communication Diagnostics”

Subfunction 0x00 - returns the received data, the response is identical to the request.

An example of a request and response is shown in Figure 10.

Example of communication diagnostics (Function 0x08)

Figure 10 – Example of communication diagnostics (Function 0x08)

Error codeNameComments
0x01ILLEGAL FUNCTIONIllegal function number
0x02ILLEGAL DATA ADDRESSIncorrect address
0x03ILLEGAL DATA VALUEInvalid data
0x04SERVER DEVICE FAILUREFailure of controller equipment
0x05ACKNOWLEDGEData is not ready
0x06SERVER DEVICE BUSYSystem is busy
0x08MEMORY PARITY ERRORMemory error