cmseaton42 / node-ethernet-ip

A Lightweight Ethernet/IP API written to interface with Rockwell ControlLogix/CompactLogix Controllers.
MIT License
263 stars 105 forks source link

Multi Response (Read/Write) Packets #93

Open Mudrekh opened 2 years ago

Mudrekh commented 2 years ago

Multi Response (Read/Write) Packets

Description, Motivation, and Context

While running again a PLC with > 250 reads, we noticed that writes were being sent in parallel with the reads. This caused the buffer returned to _handleDataEvent to contain the response for both the read and write, however the parsing only ever parsed the first response in the header and threw away the other one. This change allows the remainder of the buffer to also be processed.

Aditionally, listeners are removed after failed calls and listeners are guranteed to be attached before the new write command is sent. This avoids possible race conditions in where a message could be recieved on the socket before the listener is set up.

An alternative solution to this would be to group read/write/groups in the same queue instead of individual queues so there is only ever 1 outstanding request.

How Has This Been Tested?

Tested against a PLC with > 250 reads and around 2 writes. When ever the writes would be would be executed, the subsequent read would always fail. I believe you can issue a write and read at the same time to reliably reproduce the error.

Screenshots (if appropriate):

Types of changes

Checklist:

Related Issue