Helper for modbus-serial package in async/await.
const modbusHelper = require('@iqrok/modbus.helper');
const modbus =new modbusHelper({
ip: '127.0.0.1',
port: 502,
id: 1,
byteOrder: [1,0,3,2],
decimalDigits: null,
debug: true,
timeout: 1000,
});
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ip |
string | IP destination for modbus TCP | ||
port |
number|string | Port number for modbus TCP or path to serial port for modbus RTU | ||
baud |
number | Baud Rate for modbus RTU | ||
byteOrder |
Array.<number> | <optional> | [1,0,3,2] | byte order of modbus register |
decimalDigits |
number | <optional> <nullable> | number of decimals for floating point | |
timeout |
number | <optional> | 100 | timeout in ms |
debug |
boolean | <optional> | false | Print debug message |
Size of data type in bytes
Name | Type | Description |
---|---|---|
type |
"UINT16" | "INT16" | "UINT32" | "INT32" | "FLOAT" | "FLOAT32" | "DOUBLE" | "FLOAT64" | number data type |
- data type size in bytes
Convert number into array of unsigned integer 16-bits numbers
Name | Type | Description |
---|---|---|
number |
number | number to be converted |
type |
"UINT16" | "INT16" | "UINT32" | "INT32" | "FLOAT" | "FLOAT32" | "DOUBLE" | "FLOAT64" | number data type |
- array of uint16 numbers
Read Coils (FC=1)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
addr |
number | address to read from | ||
len |
number | <optional> | 1 | number of addresses to read |
- resolve false if reading is failed, otherwise resolve array of coils status
Read Discrete Inputs (FC=2)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
addr |
number | address to read from | ||
len |
number | <optional> | 1 | number of addresses to read |
- resolve false if reading is failed, otherwise resolve array of discrete inputs status
Read Holding Register (FC=3)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
addr |
number | address to read from | ||
len |
number | <optional> | 1 | number of addresses to read |
- resolve false if reading is failed, otherwise resolve read Buffer
Read Input Register (FC=4)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
addr |
number | address to read from | ||
len |
number | <optional> | 1 | number of addresses to read |
- resolve false if reading is failed, otherwise resolve read Buffer
Size of data type in words
Name | Type | Description |
---|---|---|
type |
"UINT16" | "INT16" | "UINT32" | "INT32" | "FLOAT" | "FLOAT32" | "DOUBLE" | "FLOAT64" | number data type |
- data type size in words
Convert Words received from modbus to number
Name | Type | Attributes | Description |
---|---|---|---|
words |
Buffer | Array.<uint16> | |
type |
"UINT16" | "INT16" | "UINT32" | "INT32" | "FLOAT" | "FLOAT32" | "DOUBLE" | "FLOAT64" | number data type | |
digits |
number | <optional> <nullable> | number of decimal digits for float, will be default to set decimalDigits in config if left undefined |
- converted number
Write Single Coil (modified FC=15)
Name | Type | Description |
---|---|---|
addr |
number | address to write |
values |
boolean | array of values to write |
- resolve false if reading is failed, otherwise resolve address and length of written registers
Write multiple Coils (FC=15)
Name | Type | Description |
---|---|---|
addr |
number | address to write |
values |
Array.<boolean> | array of values to write |
- resolve false if reading is failed, otherwise resolve address and length of written registers
Write single Holding Register (FC=6)
Name | Type | Description |
---|---|---|
addr |
number | address to write |
value |
number | value to write |
- resolve false if reading is failed, otherwise resolve address and length of written registers
Write multiple Holding Registers (FC=16)
Name | Type | Description |
---|---|---|
addr |
number | address to write |
values |
Array.<number> | array of valuess to write |
- resolve false if reading is failed, otherwise resolve address and length of written registers