feat(modbus): implement COM port sharing and robust connection management (#211)#2200
feat(modbus): implement COM port sharing and robust connection management (#211)#2200lookmydog wants to merge 1 commit intofrangoteam:masterfrom
Conversation
…tion logic (frangoteam#211) Refactored the communication layer to allow a single COM port to be shared across multiple slave devices. Key enhancements: ConnectionManager, Reference Counting, Skip Mechanism, Queue System, Timeout Management, and Concurrency Control. Fixes frangoteam#211
|
Wow, great job, TCP could also need queue in case that serial devices are using a shared gateway. |
Regarding the TCP 'reuseserial' mode, I've implemented a handling mechanism identical to RTU, as the device-side hardware is RTU-based. This has been included in the current Pull Request. However, I must apologize for refactoring the mutex implementation you used into a queue-based mechanism. |
|
Don't need apologies, I just copied the strategy from the SocketReuse of the ModbusTcp. |
|
@lookmydog Thanks a lot for this work, the overall direction is great and the refactor is a strong step forward for Modbus connection robustness and shared COM/TCP handling. I did a brief review with Codex support and found a couple of small improvements before merge. I also want to be transparent: I could not test COM sharing deeply, because I don’t currently use RTU hardware in my setup. |
|
I've tested this on my modbus RTU hardware and it is working quite well, it has prevented the crashing I was experiencing when using a slider to send lots of commands very quickly. However I still see lots of CRC errors and data length errors, which I am getting on the latest fuxa release too. I don't know if this is just my device or hardware setup, but I don't see these errors when I use QModbus for example. |
|
Thanks for the feedback! It is interesting that QModbus works fine; this suggests the hardware itself can handle the communication, but the timing logic in FUXA might need further tuning. These errors could be caused by serial packet fragmentation (sticky packets) or improper frame segmentation. To help us analyze and reproduce the issue, could you please provide the following information?
This will help us determine if the issue is related to Node.js event loop latency or the way the serial buffer is being parsed. Thanks! |
Description
This PR refactors the Modbus communication layer to support multiple slave devices sharing a single COM port. It introduces a centralized management system to ensure stability and efficiency in industrial environments.
Key Mechanisms Implemented:
Impact
Related Issue
Fixes #211