morkai / h5.modbus

Implementation of the MODBUS IP/ASCII/RTU master and slave over TCP/UDP/Serial for Node.js.
https://miracle.systems/p/h5.modbus
MIT License
28 stars 21 forks source link

Added "write" eventemitter to improve logging output and added a serial ... #2

Closed deldrid1 closed 10 years ago

deldrid1 commented 10 years ago

...example

morkai commented 10 years ago

Thanks, I always said to myself that I need to add the write events whenever I started a new project using this library. I guess the time is now, because someone else needs it too!

I've added the write events to all Connections, but before the call to the underlying socket's/serial port's write()/send() (as it's meant as a diagnostic event and I think it should be emitted even if the write/send throws an exception).

Also, instead of the Master emitting a write event (with Transaction.getRequest() as the first argument) after sending the MODBUS frame, all Transports now emit a request event (with the Transaction object as the first argument) after constructing the MODBUS frame, but before sending it (so the request event is emitted before the write event).