I'm working on a project where I need to run a ModbusRTU Server on my Raspberry Pi Pico. I've chosen to use the ArduinoModbus library(ArduinoModbus), but I'd like to avoid the Arduino core due to its overhead and speed limitations.
I'm aware that the RS485 driver in this library relies on Arduino-specific functions, particularly the HardwareSerial and Stream classes. My objective is to replace these dependencies with their equivalents from the Pico SDK.
Additionally, I've noticed that libmodbus can be built for different platforms like WIN32, Arduino, and others. What would be the best approach to port libmodbus specifically for the Pico? Would I need to implement certain functions from scratch, or can I leverage the existing Arduino port and simply replace the Arduino-specific functions with those from the Pico SDK?
Is there any other aspect of the library's structure or dependencies that I might have overlooked and would need to consider when porting to the Pico?
Any guidance or suggestions would be greatly appreciated. Thank you!
There are no equivalents of the HardwareSerial and Stream classes in the Pico SDK, since these are interface classes, and SDK mainly contains low-level functions.
Perhaps you had in mind to rewrite HardwareSerial and Stream using SDK? But why would you think that now they are not written using sdk functions?
Could you please provide more details about your project. What is the point of writing your own server - is this a learning task?
Thank you for your feedback. To clarify, my company manufactures infield industrial devices, currently using RS232 for communication. We aim to upgrade to RS485, allowing simultaneous communication with multiple devices. We're considering the modbusRTU protocol, using the Raspberry Pi Pico as our microcontroller and the MAX485 chip for RS485.
I tried to write the HardwareSerial class using Pico functions, but I soon realized that it would be very hard to do so. For example, the SDK lacks a direct equivalent to the available function that returns byte count. Instead, it only indicates if data is present. Are there any modbusRTU libraries that would be easier to port to the Pico?
It’s still not entirely clear to me why you necessarily want to port something? Why not take a ready-made ArduinoModbus library compatible with Pico?
If you are afraid that it will be too slow, I would start by running tests. Perhaps the standard library is quite suitable for your needs.