pazzarpj / aiomodbus

Asyncio Library for Modbus
MIT License
5 stars 1 forks source link

Remove loop stop on serial connection lost #28

Closed nicomt closed 3 years ago

nicomt commented 3 years ago

I was wondering if this line is necessary and if it can be removed. https://github.com/pazzarpj/aiomodbus/blob/2c8dae8eeb19d137ed5cb3a9ebdd0bbf84518752/aiomodbus/serial.py#L78

Stoping the loop will prevent tasks scheduled outside of this library from finishing.

pazzarpj commented 3 years ago

Hi @nicomt You are absolutely right. I'm not sure how I didn't hit that problem before. I wasn't sure anyone else but me was using the library so if you have any questions I'm happy to answer the best I can and start documenting.

nicomt commented 3 years ago

Hi @pazzarpj Thanks for the quick reply. 😀 Yeah, I started using this library for a project at work, and so far, it's been working pretty well. We began with pymodbus, but their asyncio implementation has a lot of issues.

Thanks for the offer; I will take you up on it if I get confused. The code is easy to read, so it hasn't been hard to figure out how to use the library.

Anyway, it's not a big issue because serial connections should be stable most of the time, but it does come up for us because we are using a virtual serial port over TCP/IP.

Should I make a pull request?

pazzarpj commented 3 years ago

Hi @nicomt Raise a PR and I'll merge it. Better for you to get credit for it anyway. I actually started this project over two nights because I couldn't get pymodbus asyncio to be stable and I thought, how hard could it be?

The virtual serial port over TCP/IP can come with another whole host of issues that cannot be resolved in the library. The interchar timeout of 2.5 byte characters for modbus reads can't be strict because of the guarantees of TCP/IP. Fortunately, a lot of slave devices kinda ignore that part of the modbus spec allowing for a lot more generous timings.

We had issues of this running the devices a few km away. So we opted for using modbus RTU/TCP protocol converters close to the slave device instead of virtual serial ports.

If you come up with any suggestions or improvements, I'm happy to investigate as I'm using this in production for our IOT stuff.

nicomt commented 3 years ago

I did PR Let me know if there is anything else I can do. Also thanks for letting me know about the interchar timeout. I wasn't aware that was part of the Modbus spec I'll keep an eye on that to see if we get any issues with our setup. Thanks