Cloud-Automation / node-modbus

Modbus TCP Client/Server implementation for Node.JS
466 stars 174 forks source link

ReadDiscrete use getInput #145

Closed davidonet closed 6 years ago

davidonet commented 7 years ago

Why does ReadDiscrete use Input Buffer it's a bit confusing ?

https://github.com/Cloud-Automation/node-modbus/blob/321f71f15ad7f6516665bd7cc755a71232fba1b8/src/handler/server/ReadDiscreteInputs.js#L38

I can't find getDiscrete method.

stefanpoeter commented 7 years ago

It is indeed confusing. I'll always used it this way, there was an issue some time back that adressed this issue too. I'll try to avoid this in the v3 release.

davidonet commented 7 years ago

How can I avoid collision between a ReadInput(0x00) and a ReadDiscrete(0x00) ?

stefanpoeter commented 7 years ago

If you want to do it right then I would make a pull request and replace the input buffer with a new discrete buffer. That way you are fine.

davidonet commented 7 years ago

Yes please :-)

stefanpoeter commented 6 years ago

Sorry for the long delay. Can you confirm that this is working the way you wanted it?

davidonet commented 6 years ago

I've seen a pull request that seems to fix it : https://github.com/Cloud-Automation/node-modbus/pull/154 But it doesn't seem to be integrated in the current master branch : https://github.com/Cloud-Automation/node-modbus/blob/1cc5a9088a904c60470ac865c4ab2d24445cf655/src/handler/server/ReadDiscreteInputs.js#L38 There is still a getInput buffer in the ReadDiscreteInput.

stefanpoeter commented 6 years ago

Yes, you need to confirm that the pull request fixed the issue before I merge it into the master branch.

davidonet commented 6 years ago

I don't know how to test it, I tried to fork the project but I can't merge the pull request in my fork.

davidonet commented 6 years ago

I figure how it can be done locally : https://help.github.com/articles/checking-out-pull-requests-locally/

davidonet commented 6 years ago

Yes it works Input buffer and Discrete buffer are distinct. tested with

// in SimpleServer
this.getInput().writeUInt16BE(0xff,0)
this.getDiscrete().writeUInt8(0xaa,0)

and on clientside

$ node ReadDiscreteInput.js localhost 8888 0 1
2017-11-07T11:57:45.570Z 'DEBUG :' 'init' 'connect'
2017-11-07T11:57:45.572Z 'DEBUG :' 'connect' 'connect'
2017-11-07T11:57:45.577Z 'DEBUG :' 'connect' 'ready'
2017-11-07T11:57:45.577Z 'DEBUG :' 'Trying to flush data.'
2017-11-07T11:57:45.577Z 'DEBUG :' 'ready' 'waiting'
2017-11-07T11:57:45.577Z 'DEBUG :' 'Sending pdu to the socket.'
2017-11-07T11:57:45.578Z 'DEBUG :' 'Data flushed.'
2017-11-07T11:57:45.583Z 'DEBUG :' 'received data'
2017-11-07T11:57:45.583Z 'DEBUG :' 'PDU extracted'
2017-11-07T11:57:45.583Z 'DEBUG :' 'received data'
2017-11-07T11:57:45.584Z 'DEBUG :' 'handling read discrete inputs response.'
2017-11-07T11:57:45.584Z 'DEBUG :' 'waiting' 'ready'
2017-11-07T11:57:45.585Z 'DEBUG :' 'Trying to flush data.'
2017-11-07T11:57:45.585Z 'DEBUG :' 'Nothing in request pipe.'
{ fc: 2,
  byteCount: 2,
  payload: <Buffer aa 00>,
  coils: 
   [ false,
     true,
     false,
     true,
     false,
     true,
     false,
     true,
     false,
     false,
     false,
     false,
     false,
     false,
     false,
     false ] }
2017-11-07T11:57:45.588Z 'DEBUG :' 'Closing client on purpose.'
2017-11-07T11:57:45.591Z 'DEBUG :' 'Socket closed with error' false
2017-11-07T11:57:45.591Z 'DEBUG :' 'ready' 'closed'
2017-11-07T11:57:45.591Z 'DEBUG :' 'Clearing timeout of the current request.'
2017-11-07T11:57:45.592Z 'DEBUG :' 'Cleaning up request fifo.'

$ node ReadInputRegister.js localhost 8888 0 1
2017-11-07T11:58:19.192Z 'DEBUG :' 'init' 'connect'
2017-11-07T11:58:19.194Z 'DEBUG :' 'connect' 'connect'
2017-11-07T11:58:19.198Z 'DEBUG :' 'connect' 'ready'
2017-11-07T11:58:19.199Z 'DEBUG :' 'Trying to flush data.'
2017-11-07T11:58:19.199Z 'DEBUG :' 'ready' 'waiting'
2017-11-07T11:58:19.199Z 'DEBUG :' 'Sending pdu to the socket.'
2017-11-07T11:58:19.199Z 'DEBUG :' 'Data flushed.'
2017-11-07T11:58:19.202Z 'DEBUG :' 'received data'
2017-11-07T11:58:19.203Z 'DEBUG :' 'PDU extracted'
2017-11-07T11:58:19.203Z 'DEBUG :' 'received data'
2017-11-07T11:58:19.203Z 'DEBUG :' 'handling read input registers response.'
2017-11-07T11:58:19.204Z 'DEBUG :' 'waiting' 'ready'
2017-11-07T11:58:19.204Z 'DEBUG :' 'Trying to flush data.'
2017-11-07T11:58:19.204Z 'DEBUG :' 'Nothing in request pipe.'
{ fc: 4,
  byteCount: 2,
  payload: <Buffer 00 ff>,
  register: [ 255 ] }
2017-11-07T11:58:19.207Z 'DEBUG :' 'Closing client on purpose.'
2017-11-07T11:58:19.209Z 'DEBUG :' 'Socket closed with error' false
2017-11-07T11:58:19.209Z 'DEBUG :' 'ready' 'closed'
2017-11-07T11:58:19.209Z 'DEBUG :' 'Clearing timeout of the current request.'
2017-11-07T11:58:19.209Z 'DEBUG :' 'Cleaning up request fifo.'
stefanpoeter commented 6 years ago

Can you also copy the output from the command line. Thanks.

davidonet commented 6 years ago

done

stefanpoeter commented 6 years ago

Thanks, I'll merge it soon then.

stefanpoeter commented 6 years ago

Sorry for the long delay, v2.4.0 has been released.