我正在尝试使用 modbus-serial 库从名为 TUF_2000 的流量计设备读取数据 我试图读取的数据在两个寄存器中,但我不知道如何读取,我得到的结果是显示 2 个缓冲区。
const ModbusRTU = require("modbus-serial");
const client = new ModbusRTU();
// open connection to a serial port
client.connectRTUBuffered("/dev/ttyUSB0", { baudRate: 9600 })
.then(setClient)
.then(function() {
console.log("Connected"); })
function setClient() {
// set the client's unit id
// set a timout for requests default is null (no timeout)
client.setID(1);
client.setTimeout(1000);
// run program
FlowForYear();
}
function FlowForYear() {
// read the 2 registers starting at address 145
client.readHoldingRegisters(145, 2)
.then(function(d) {
console.log("FlowForYear:", d.data); })
这是我的代码,我设备上的数据显示 -2.5132 但这就是我得到的
Connected
FlowForYear: [ 65535, 62901 ]