FairCom provides special API actions for Modbus TCP connectors and transforms. The Modbus TCP service must be enabled in order to complete FairCom Modbus API actions.
Request examples
Note The FairCom createInput JSON action is used to define the specifics of a connector device and the desired data.
Minimal
{
"action": "createInput",
"params": {
"inputName": "modbusTCP",
"serviceName": "modbus",
"settings": {
"modbusProtocol": "TCP",
"modbusServer": "127.0.0.1",
"modbusServerPort": 502,
"propertyMapList": [
{
"propertyPath": "temperature",
"modbusDataAccess": "holdingregister",
"modbusDataAddress": 1199,
"modbusUnitId": 5,
"modbusDataLen": 1
}
]
},
"tableName": "modbusTableTCP"
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}RTU
{
"api": "hub",
"action": "createInput",
"params": {
"inputName": "modbusRTU",
"serviceName": "modbus",
"dataPersistenceStrategy": "onChange",
"dataCollectionIntervalMilliseconds": 5000,
"immediatelyCollectDataOnStart": true,
"dataCollectionBufferCount": 2,
"settings": {
"modbusProtocol": "RTU",
"modbusSerialPort": "COM2",
"modbusBaudRate": 19200,
"modbusParity": "None",
"modbusDataBits": 8,
"modbusStopBits": 2,
"propertyMapList": [
{
"propertyPath": "temperature",
"modbusDataAccess": "holdingregister",
"modbusDataAddress": 1199,
"modbusUnitId": 5,
"modbusDataLen": 1
}
]
},
"tableName": "modbusTableRTU"
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}Maximal
{
"api": "hub",
"action": "createInput",
"params": {
"inputName": "modbusTCP",
"serviceName": "modbus",
"dataCollectionIntervalMilliseconds": 5000,
"settings": {
"modbusProtocol": "TCP",
"modbusServer": "127.0.0.1",
"modbusServerPort": 502,
"modbusDataAddressType": "zeroBased",
"propertyMapList": [
{
"propertyPath": "temperature",
"modbusDataAddress": 1199,
"modbusDataAccess": "holdingregister",
"modbusUnitId": 1,
"modbusDataType": "int16SignedAB"
},
{
"propertyPath": "status",
"modbusDataAddress": 1199,
"modbusDataAccess": "inputregister",
"modbusUnitId": 1,
"modbusDataType": "int8Signed"
},
{
"propertyPath": "volume",
"modbusDataAddress": 1299,
"modbusDataAccess": "coil",
"modbusUnitId": 1,
"modbusDataType": "ieeeFloat32ABCD"
},
{
"propertyPath": "pressure",
"modbusDataAddress": 1499,
"modbusDataAccess": "inputregister",
"modbusUnitId": 1,
"modbusDataType": "int16SignedAB",
"modbusConvertToFloat": "divideByInteger",
"modbusDecimalDigits": 2,
"modbusDivisor": 1000
},
{
"propertyPath": "humidity",
"modbusDataAddress": 1599,
"modbusDataAccess": "holdingregister",
"modbusUnitId": 1,
"modbusDataType": "int16SignedAB",
"modbusDecimalDigits": 2,
"modbusConvertToFloat": "appendAdjacentRegisters"
},
{
"propertyPath": "sos",
"modbusDataAccess": "discreteinput",
"modbusDataAddress": 1024,
"modbusDataType": "bitBoolean",
"bitBooleanZeroValue": false,
"bitStartPosition": 0
},
{
"propertyPath": "batteryHealth",
"modbusDataAccess": "discreteinput",
"modbusDataAddress": 1024,
"modbusDataType": "bitString",
"bitStringZeroValue": "healthy",
"bitStringOneValue": "unhealthy",
"bitStartPosition": 1
},
{
"propertyPath": "voltageLevel",
"modbusDataAccess": "holdingregister",
"modbusDataAddress": 1024,
"modbusDataType": "bitInt",
"bitStartPosition": 2,
"bitEndPosition": 9,
"bitReverseOrder": false,
"bitIntSigned": false,
"bitLittleEndian": false
},
{
"propertyPath": "batteryStatus",
"modbusDataAccess": "holdingregister",
"modbusDataAddress": 1024,
"modbusDataType": "bitEnum",
"bitStartPosition": 10,
"bitEndPosition": 12,
"bitReverseOrder": false,
"bitLittleEndian": false,
"bitEnumValues": [
"0-low voltage error",
"1-low voltage",
"2-normal voltage",
"3-high voltage",
"4-high voltage error"
]
}
]
},
"ownerName": "admin",
"tableName": "modbusTableTCP",
"retentionPolicy": "autoPurge",
"retentionPeriod": 30,
"retentionUnit": "day",
"metadata": {
}
},
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Response examples
A response to a request is "0" when successful. A non-zero value response indicates an error occurred.
Successful
{
"result": {},
"requestId": "00000007",
"errorCode": 0,
"errorMessage": ""
}Error
{
"result": {},
"requestId": "00000011",
"debugInfo": {
"request": {
"api": "hub",
"action": "createInput",
"params": {
"inputName": "modbusTCP",
"serviceName": "modbus",
"settings": {
"modbusProtocol": "TCP",
"modbusServer": "127.0.0.1",
"modbusServerPort": 502,
"propertyMapList": [
{
"propertyPath": "temperature",
"modbusDataAddress": "holdingregister",
"modbusDataAddress": 1199,
"modbusUnitId": 5,
"modbusDataLen": 1
}
]
},
"tableName": "modbusTableTCP"
},
"requestId": "00000011",
"debug": "max",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
},
"errorCode": 12012,
"errorMessage": "There is already an integration with name of [modbusTCP].",
"authToken": "replaceWithAuthTokenFromCreateSession"
}
Properties
Request properties ("params")
| Property | Description | Default | Type | Limits (inclusive) |
|---|---|---|---|---|
dataCollectionBufferCount |
The This option combines multiple data collection events and inserts them into the integration table as one MQTT message. If this value is more than |
Optional with default of 1
|
integer |
1 to 65535
|
dataCollectionIntervalMilliseconds |
The |
Optional with default of 10000 (10 seconds). |
integer |
0 and negative values are invalid. |
dataPersistenceStrategy |
The
|
Optional with default of "onSchedule"
|
string |
|
enabled |
The "enabled" property turns on or off an input or output connector. Thus, it pauses or starts data collection or delivery. |
Optional with default of true
|
Boolean |
|
enabledFilter |
The "enabledFilter" property returns input connections that are enabled or not. Omit or set to null to match all connections. |
Optional with default of null
|
Boolean |
|
immediatelyCollectDataOnStart |
The
|
Optional with default of false
|
Boolean |
|
inputName |
The "params": {
"inputName": "modbusTCP",
"serviceName": "modbus"
} |
Required - No default value |
string | 1 to 100 bytes |
metadata |
The "metadata" property contains user-defined properties that add keywords and tags about the code package. The server indexes this field with a full-text index so you can search for any word or phrase to find code packages. |
Optional with default of {}
|
object | 0 or more key/value pairs |
ownerName |
The You specify this property when you want to use a different account instead of the default. Your session's account must have the appropriate privileges to access the code package. This property is useful because objects, such as tables and code packages, can have the same name in the same database as long as different accounts own each object. This feature allows you to create duplicate objects for different users on the same server and reuse the same JSON actions on those objects. For example, an administrator can copy objects from a production environment to her account so she can troubleshoot an issue using the same JSON actions, JavaScript, and SQL code. It is an error to set If no default owner is specified during |
Optional with default of the session's "defaultOwnerName" property |
string | 1 to 64 bytes |
retentionPeriod |
The |
Optional with default of |
integer |
1 to 100
|
retentionPolicy |
The If not specified, the default found in the
retentionPolicy values:
|
Optional with default of |
string |
|
retentionUnit |
The If not specified, the default found in the
|
Optional with default of |
string |
|
runningFilter |
The "runningFilter" property returns input connections that are running or not. Omit or set to null to match all connections. |
Optional with default of null
|
Boolean |
|
serviceName |
The See the The following services are available as of the V5 release:
|
Required - No default value | string | 1 to 64 bytes |
settings |
The
|
Optional with default of {}
|
object | |
|
settings .modbusBaudRate |
The "modbusBaudRate" property (RTU only) specifies the baud rate of the communication (9600, 19200, 57600, 115200, and so forth). |
Optional with default of 19200
|
int16 | Any baud rate |
|
settings .modbusDataAddressType |
The "modbusDataAddressType" property specifies if the modbusDataAddress is zero-based or one-based. |
Optional with default of "zeroBased"
|
string |
|
|
settings .modbusDataBits |
The "modbusDataBits" property (RTU only) specifies the number of bits of data. |
Optional with default of 8
|
int16 |
5, 6, 7, or 8
|
|
settings .modbusParity |
The "modbusParity" property (RTU only) specifies the data parity. |
Optional with default of "even"
|
string |
"none", "even", "odd"
|
|
settings .modbusProtocol |
The "modbusProtocol" property specifies the protocol used to connect to the Modbus server. |
Required - No default value | string |
|
|
settings .modbusSerialPort |
The On Windows, it is necessary to prepend the COM name with "\\.\" if the COM number is greater than 9. For example, "\\\\.\\COM10". For Windows naming conventions, see Naming Files, Paths, and Namespaces . |
Required - No default value | string | No limit |
|
settings .modbusServer |
The "modbusServer" property (TCP only) specifies the IP/hostname of the Modbus device. |
Required - No default value | string | No limit |
|
settings .modbusServerPort |
The "modbusServerPort" property (TCP only) specifies the IP Port for the Modbus device for modbusTCP. |
Required - No default value | int16 |
0 to 65535
|
|
settings .modbusStopBits |
The "modbusStopBits" property (RTU only) specifies the bits of stop. |
Optional with default of 1
|
int16 |
1 or 2
|
|
settings .propertyMapList |
The "propertyMapList" property specifies which data the connector requests and where to put it in the generated JSON. |
Required - No default value | array of objects |
zero or more objects containing zero or more of the following properties:
|
|
settings propertyMapList .bitBooleanZeroValue |
The |
Optional with default of false
|
Boolean |
|
|
settings propertyMapList .bitEndPosition |
The When When When For examples, see Modbus data types. |
Required if "modbusDataType" is "bitInt" or "bitEnum". Defaults to the value of the "bitStartPosition"
|
int16 |
0 to 15
|
|
settings propertyMapList .bitEnumValues |
The For examples, see Modbus data types. |
Required if "modbusDataType" is "bitEnum"
|
array of strings | 1 or more strings |
|
settings propertyMapList .bitIntSigned |
The When When When For examples, see Modbus data types. |
Optional with default of false
|
Boolean |
|
|
settings propertyMapList .bitLittleEndian |
The When When When For examples, see Modbus data types. |
Optional with default of false
|
Boolean |
|
|
settings propertyMapList .bitReverseOrder |
The When When For example, if When For examples, see Modbus data types. |
Optional with default of false
|
Boolean |
|
|
settings propertyMapList .bitStartPosition |
The When When When For examples, see Modbus data types. |
Required if modbusDataType is , "bitString", "bitInt", or "bitEnum"
|
int16 |
0 to 15
|
|
settings propertyMapList .bitStringOneValue |
The
The For examples, see Modbus data types. |
Required if "modbusDataType" is "bitString"
|
string | No limit |
|
settings propertyMapList .bitStringZeroValue |
The
The For examples, see Modbus data types. |
Required if "modbusDataType" is "bitString"
|
string | No limit |
|
settings propertyMapList .modbusConvertToFloat |
The "modbusConvertToFloat" property causes the connector to convert one or two register values into a JSON floating point number. |
Optional with default of "no"
|
string |
|
|
settings propertyMapList .modbusDataAccess |
The
|
Required - No default value | string |
|
|
settings propertyMapList .modbusDataAddress |
The Some vendors document data addresses as one-based values. Set the |
Required - No default value | int16 |
0 to 65536
|
|
settings propertyMapList .modbusDataLen |
The
|
Required if "modbusDataType" is not specified |
integer |
1, 2, or 4
|
|
settings propertyMapList .modbusDataType |
The "modbusDataType" property specifies how to convert Modbus binary data types to JSON types. Choose a type that matches the byte order of the data type. The byte order is specified using the letters ABCDEFGH. |
Optional with default of ""
|
string | Any Modbus Data Type |
|
settings propertyMapList .modbusDecimalDigits |
The |
Optional with default of 2
|
integer |
1 to 5
|
|
settings propertyMapList .modbusDivisor |
The |
Required if "modbusConvertToFloat" is "divideByInteger". Otherwise defaults to 1 |
integer |
Typical values are |
|
settings propertyMapList .modbusUnitId |
The The unit number uniquely identifies each of these devices. This property also applies to serial communications. For serial communication, the range is
|
Optional with default of 1
|
int16 |
0 to 255
|
|
settings propertyMapList .propertyPath |
The "propertyPath" property specifies the name of the data to be defined by "propertyValue". |
Required - No default value | string | 0 to 256 bytes |
tableName |
The See table name in System limits for the table naming requirements and limitations.
"params": {
"tableName": "ctreeTable"
} |
Required - No default value | string | 1 to 64 bytes |
Response properties ("result")
| Property | Description | Type | Limits (inclusive) |
|---|---|---|---|
data |
The |
array of objects | The action determines its contents. |
|
data .enabled |
|
boolean |
truefalse
|
|
data .running |
The "running" property is true when an input connector is collecting data or an output connector is delivering data; otherwise, it is false. A disabled connector will never be running. An enabled connector may or may not be running. |
Boolean |
|
|
data .stopCode |
The "stopCode" property is 0 when the connector is successfully connected to its device or software; otherwise, it is non-zero. |
integer |
-2147483648 to 2147483647
|
|
data .stopReason |
The "stopReason" property is "" when the input connector is collecting data; otherwise, it is a non-empty string. |
string | 0 to 256 bytes |