labgrid
labgrid copied to clipboard
feat: add remote modbus rtu driver support, refactor ModbusRTUDriver to use SerialPort directly
Description
This PR adds support for using Modbus RTU serial ports remotely. It does that by removing the ModbusRTU resource, and let the driver use SerialPort and NetworkSerialPort resources directly.
In order to archieve this, I moved the fields timeout and address into the driver.
My reasoning is that it makes more sense to let the resource manage the entire bus, and let the driver only control one slave (= address). Same for the timeout, this can be slave-specific.
It seems to be working fine remotely with a Waveshare RTU relay, so far I only tested it with a low baudrate 9600 so I don't know how well the remote serial connection behaves with higher rates.
as mentioned in #1370 I am unsure if it is "okay" to replace the ModbusRTU resource, because this is obviously a breaking change. Adding a exported NetworkModbusRTU resource would be the alternative, but it would mean a lot of repetition with NetworkSerialPort. But I might have missed intentional architectural decisions here, so I can implement whatever makes the most sense!
Once this is resolved/merged, I'll follow up with an added WaveshareRTURelay driver
Checklist
- [x] Documentation for the feature
- [x] Tests for the feature
- [x] The arguments and description in doc/configuration.rst have been updated
- [x] PR has been tested
@b2vn As you contributed the original Modbus RTU support in https://github.com/labgrid-project/labgrid/pull/806, do you have an opinion regarding this refactoring and my suggested approach in https://github.com/labgrid-project/labgrid/pull/1394#pullrequestreview-2182947267?