The client.poll method optimizes multiple Modbus requests by building an efficient polling map. It can handle various function codes (fc), addresses (single or arrays), and data types.
Key options:
map: An array of objects defining the registers to read/write. If type is omitted, it defaults to int16.onProgress: A callback function receiving progress (a float from 0 to 1) and the data from the current request.maxChunkSize: The maximum number of registers allowed per request.skipErrors: If false, the polling process stops on error and returns a partial result. If true, it continues through errors.
const response = await client.poll({
unit: 1,
map: [
{ fc: 3, address: [10011, 10013, 10018], type: "int32" },
{ fc: 3, address: 10003, type: "int32" },
{ fc: 3, address: 10005, type: "int32" },
{ fc: 3, address: 10007, type: "int32" },
{ fc: 3, address: 10009, type: "int32" },
{ fc: 2, address: [1,2,3]},
{ fc: 1, address: [1,2,3]},
{ fc: 1, address: 4},
{ fc: 1, address: 5},
{ fc: 1, address: 6},
{ fc: 3, address: [10001]}, // default type is int16
{ fc: 3, address: [10020, 10023, 10026], type: "float"},
{ fc: 3, address: [10030, 10034], type: "double"}
],
onProgress: (progress, data) => {
console.log(
progress, // Poll progress from 0...1 where 1 means 100%
data, // Data from the current request
);
},
maxChunkSize: 32, // max registers per request
skipErrors: false, // if false it will stop poll and return PARTIAL result
})