Cloud-Automation/node-modbus

how to read registers from meter?

Closed this issue · 8 comments

Hi Guys,

I have a meter and a modbus server (I used some old npm library).

The server is listening to incoming connections from the meter and upon an incoming connection, I call connection.readInputRegisters..

How can I implement the same with this library?

Thanks
Dekel

I guess you want to read data from the meter? Isn't that supposed to be the server? Or is you meter connecting to a modbus server and therefor acts like a client?

Ok, this way you simply need to start a modbus server and setup the buffers for the input registers. Data will then be stored in the buffers and you can read it at any given time. If you want to intercept or handle the writeInputRegisters Requests there are pre and post handler.

how do I implement the 'on connection received' event in the server?

`
const modbus = require('jsmodbus')
const net = require('net')
const netServer = new net.Server()
const server = new modbus.server.TCP(netServer)

netServer.listen(502)
`

Someone told me that the first connection is to wake up the meter and only then you can read the values.

the following code throws

UserRequestError { err: 'Offline', message: 'no connection to modbus server', response: undefined }

netServer.on('connection', function (socket) {
console.log('netServer incoming connection')
const client = new Modbus.client.TCP(socket, 'unitId')

client.readCoils(0, 13).then(function (res) {
console.log('readCoils', res)
}).catch(e => console.error(e))
})

netServer.listen(502)

What kind of meter are you using? Every modbus meter I have ever used acts as its own server and you connect to it over port 502 as a client.

I would like to reopen the discussion.
We are using SATEC meter.

The way it works, the meter open connection to the server and then the server request for holding registers.
this way, you don't need to know the meter ip and the meter can be configured with DHCP.