1.0.51 • Published 2 years ago

@softchef/modbus-poll v1.0.51

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
2 years ago

Modbus Poll

npm version Release npm

Modbus Poll can automation polling the Modbus devices by Modbus map table and convert to JSON object by defined property. This package is used modbus-serial package to connect Modbus protocol and operate Modbus commands.

Installation

NPM

npm install @softchef/modbus-poll

Yarn

yarn add @softchef/modbus-poll

Try these options on npm install to build, if you have problems to install

--unsafe-perm --build-from-source

Compatibility

Version of NodeJS: This module has not been tested on every single version of NodeJS. For best results you should stick to LTS versions, which are denoted by even major version numbers e.g. 4.x, 6.x, 8.x.

Config definition

new ModbusPoll(config)

  • type```: dbus client type, supportModbusTCP,ModbusRTU,ModbusRTUBuffered`.
  • name: fine connection name.
  • path: e ModbusRTU serial port path, ex: /dev/ttyUSB0.
  • host: e ModbusTCP IP address.
  • port: e ModbusTCP port, default is 502.
  • serialPorptions: The ModbusRTU options. Reference modbus-serial
  • serialPorptions.baudRate: The serial port's baud rate. Default is 9600.
  • interval: Set the polling interval, Default is 3000ms.
  • timeout: Set Modbus command's timeout. Default is 3000ms.
  • delay: Set read/write command's delay time. Default is 50ms.
  • sensors: Array of Modbus address table for read.
  • sensors[].thingName: Define device name.
  • sensors[].property: Define data property name.
  • sensors[].slaveId: The Modbus device's slave ID.
  • sensors[].functionCode:: The Modbus function code. Supports 0x01, 0x02, 0x03, 0x04. Reference modbus-serial functions.
  • sensors[].address: The Modbus register address.
  • sensors[].quantity: Read data length.
  • sensors[].endian?: The payload's endial, little or big or raw, Default is raw.
  • sensors[].decimal?: When data is a numberic, decimal will convert decimal places. Default is 0. Ex: decimal is 2, data is 2635, result is 26.35.
  • actuators: Array of Modbus address table for control.
  • actuators[].thingName: Define device name.
  • actuators[].property: Define data property name.
  • actuators[].slaveId: The Modbus device's slave ID.
  • actuators[].functionCode:: The Modbus function code. Supports 0x05, 0x06, 0x14, 0x15, 0x16. Reference modbus-serial functions.
  • actuators[].address: The Modbus register address.

Example

Polling Modbus device's data

const config = {}; // Reference config definition
const modbusPoll = new ModbusPoll(config);
await modbusPoll.connect();
modbusPoll.startPolling();
modbusPoll.on('data', (data) => {
  console.log('Receive polling data:', data);
});

Control Modbus device

const config = {
  ...,
  actuators: [
    {
      thingName: 'relay',
      property: 'ch1',
      slaveId: 1,
      functionCode: '0x05',
      address: '0x00'
    }
  ]
};
const modbusPoll = new ModbusPoll(config);
await modbusPoll.connect();
// Control relay.ch1 to "on" and delay 1000 ms.
modbusPoll.write('relay.ch1', 1, 1000)
// Control relay.ch1 to "off" after 1000 ms
modbusPoll.write('relay.ch1', 0)
1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.40

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.48

2 years ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.49

2 years ago

1.0.51

2 years ago

1.0.50

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago