Skip to content

Instructions - Modbus


MODBUS_OPEN - Open Modbus Connection

Description

Opens a Modbus communication connection

Parameter List

ParameterTypeRequiredDescription
IDintYesModbus master station process number, value range [1,9]
logoutboolNoWhether commented out. true: this instruction will not be executed in the job file; false: not commented, executable
modTypestringYesMaster/Slave. "Master": master station; "Slave": slave station
typeintYesMODBUS_OPEN is 210 in the enumeration sequence type
userParamIntintNoCustomer custom in secondary development, currently no meaning
userParamStringstringNoCustomer custom in secondary development, currently no meaning

Example

json
{
  "ID": 5,
  "logout": false,
  "modType": "Master",
  "type": 210,
  "userParamInt": 0,
  "userParamString": ""
}

MODBUS_CLOSE - Close Modbus Connection

Description

Disconnects a Modbus communication connection

Parameter List

ParameterTypeRequiredDescription
IDintYesModbus master station process number, value range [1,9]
logoutboolNoWhether commented out. true: this instruction will not be executed in the job file; false: not commented, executable
modTypestringYesMaster/Slave. "Master": master station; "Slave": slave station
typeintYesMODBUS_CLOSE is 211 in the enumeration sequence type
userParamIntintNoCustomer custom in secondary development, currently no meaning
userParamStringstringNoCustomer custom in secondary development, currently no meaning

Example

json
{
  "ID": 9,
  "logout": false,
  "modType": "Master",
  "type": 211,
  "userParamInt": 0,
  "userParamString": "",
  "variable": {"data": 0.0, "secondvalue": 0, "value": 0, "varname": ""}
}

MODBUS_CONNECTION_STATUS - Get Modbus Connection Status

Description

Stores the Modbus communication connection status into a variable. When the connection is successful, the variable value is set to 1; when the connection fails, the selected variable is set to 0

Parameter List

ParameterTypeRequiredDescription
IDintYesModbus master station process number, value range [1,9]
logoutboolNoWhether commented out. true: this instruction will not be executed in the job file; false: not commented, executable
modTypestringYesMaster/Slave. "Master": master station; "Slave": slave station
typeintYesGet Modbus connection status is 212 in the enumeration sequence type
userParamIntintNoCustomer custom in secondary development, currently no meaning
userParamStringstringNoCustomer custom in secondary development, currently no meaning

Example

json
{
  "ID": 1,
  "logout": false,
  "modType": "Master",
  "type": 212,
  "userParamInt": 0,
  "userParamString": "",
  "variable": {"data": 0.0, "secondvalue": 1, "value": 6, "varname": "GB[GI001]"}
}

MODBUS_READ - Modbus Read

Description

Reads the value at the corresponding address in Modbus. Stores the obtained status into a variable (bool type variable or bound variable, global or local).

Address Type Description:

Address TypeDescription
3xReads the value at the corresponding address in Modbus
4xSame as 3x
3x-bitReads the status of any bit of the value stored at the selected address
4x-bitSame as 3x-bit
0xReadable and writable device type, equivalent to operating PLC output points
1xRead-only device type, equivalent to operating PLC input points

When the address type is 3X-bit, the slave address count range is [0,16]

When the address type is 3X-bit, the 17th bit stored in the variable is the sign bit, 0 means positive, 1 means negative

When reading characters, all read values are stored into one variable. Unlike integer, floating-point, and boolean variables, it does not store sequentially into other variables based on the set first address and slave address count

Parameter List

ParameterTypeRequiredDescription
IDintYesModbus master station process number, value range [1,9]
addressNumberobjectYesSlave address count to read. Manual or int type variable or bound variable, global or local. The number of addresses to read. If the slave address count is set to 3, after executing the read instruction, 3 addresses will be read from the Modbus first address (including the first address, reading 3 in total)
addressTypestringYesAddress type. Available values: 3x, 4x, 3x-bit, 4x-bit, 0x, 1x
dataTypestringYesData type. When the first variable for data storage is I or GI, the slave data type can be short or ushort (corresponding to short integer and unsigned short integer, the former range is [-32768,32767], the latter range is [0,65535]). The data type must match the slave data type when the first data storage variable is I or GI, otherwise data errors may occur
dataVariableobjectYesFirst variable for data storage. All variables or bound variables can be used. Stores the read parameters into variables. If the first variable is I001 and the address count is 3, after executing the read instruction, the parameter values will be sequentially stored into I001, I002, I003
firstAddressobjectYesSlave register first address. Manual or int type variable or bound variable, global or local. Reads parameter values based on the first address set in the instruction parameters. If the first address is 5, after executing the read instruction, reading starts from the 5th Modbus address
logoutboolNoWhether commented out. true: this instruction will not be executed in the job file; false: not commented, executable
modTypestringYesMaster/Slave. "Master": master station; "Slave": slave station
typeintYesMODBUS_READ is 213 in the enumeration sequence type
userParamIntintNoCustomer custom in secondary development, currently no meaning
userParamStringstringNoCustomer custom in secondary development, currently no meaning

Example

json
{
  "ID": 3,
  "addressNumber": {"data": 0.0, "secondvalue": 1, "value": 4, "varname": "GI[I001]"},
  "addressType": "4x-bit",
  "dataType": "short",
  "dataVariable": {"data": 0.0, "secondvalue": 1, "value": 9, "varname": "GS[GI001]"},
  "firstAddress": {"data": 0.0, "secondvalue": 1, "value": 4, "varname": "GI[GI001]"},
  "logout": false,
  "modType": "Master",
  "type": 213,
  "userParamInt": 0,
  "userParamString": ""
}

MODBUS_WRITE - Modbus Write

Description

This instruction is used to write variables to the corresponding address in the slave register via Modbus

Address Type Description:

Address TypeDescription
4xWrites the value from the variable to the address code
4x-bitComposes the variable into 16-bit binary code and writes it to the address code
0xWrites the variable value to the address code, only "0" and "1" states, if the variable has a value it writes 1, if not it writes 0

Parameter List

ParameterTypeRequiredDescription
IDintYesModbus master station process number, value range [1,9]
addressNumberobjectYesSlave address count to read. Manual or int type variable or bound variable, global or local. The number of addresses to read. If the slave address count is set to 3, after executing the read instruction, 3 addresses will be read from the Modbus first address (including the first address, reading 3 in total)
addressTypestringYesAddress type. Available values: 4x, 4x-bit, 0x
dataVariableobjectYesFirst variable for data storage, the variable type to write. Manual or all variables or bound variables can be used
firstAddressobjectYesSlave register first address. Manual or int type variable or bound variable, global or local. The first address to start writing. If the first address is 5, after executing the write instruction, writing starts from the 5th Modbus address
logoutboolNoWhether commented out. true: this instruction will not be executed in the job file; false: not commented, executable
modTypestringYesMaster/Slave. "Master": master station; "Slave": slave station
typeintYesMODBUS_WRITE is 214 in the enumeration sequence type
userParamIntintNoCustomer custom in secondary development, currently no meaning
userParamStringstringNoCustomer custom in secondary development, currently no meaning

Example

json
{
  "ID": 5,
  "addressNumber": {"data": 0.0, "secondvalue": 0, "value": 1, "varname": "I001"},
  "addressType": "0x",
  "dataVariable": {"data": 0.0, "secondvalue": 1, "value": 4, "varname": "GI[GI001]"},
  "firstAddress": {"data": 0.0, "secondvalue": 1, "value": 1, "varname": "I[GI001]"},
  "logout": false,
  "modType": "Master",
  "type": 214,
  "userParamInt": 0,
  "userParamString": ""
}