CMB27 / ModbusRTUSlave

This is an Arduino library that implements the slave/server logic of the Modbus RTU protocol.
MIT License
67 stars 21 forks source link

Arduino Leonardo and the Serial USB #42

Closed Antoine2211 closed 1 month ago

Antoine2211 commented 1 month ago

Hello, @CMB27

Is it possible to use the library with an Arduino Leonardo and the Serial USB?

https://github.com/CMB27/ModbusRTUSlave/blob/db7627af7d716035225d3b7a42b2cff8c30fde55/examples/ModbusRTUSlaveExample/ModbusRTUSlaveExample.ino#L81

regards,

CMB27 commented 1 month ago

It should work, but I haven't tested it. Don't set a dePin, when you try: use ModbusRTUSlave modbus(Serial); instead.

errno commented 1 month ago

Be aware of Arduino rebooting when built-in USBtoSerial is used. I stumbled upon this effect just now. I use pymodbus on my Raspberry as master and Arduino Nano connected via USB. Each time I open /dev/ttyUSB0 Arduino restarts. This is required for programming via USB to work and is not related to communication.

Antoine2211 commented 1 month ago

ok it works fine with the Arduino Leonardo <-> PC Be aware on the PC side to open the Serial Port with the option Dtr (DtrEnable at true in C#) if not the Serial.write doesn't work on the Arduino Leonardo side.