CIRCUITSTATE / CSE_ModbusRTU

Arduino library for implementing Modbus RTU communication protocols using hardware/software serial ports.
MIT License
6 stars 1 forks source link

Multiple Slaves? #2

Open RobWPink opened 8 months ago

RobWPink commented 8 months ago

All the examples and explainations are for a single master and slave. Do I need to make multiple Client objects?

vishnumaiea commented 8 months ago

The CSE_ModbusRTU library supports multiple Servers and Clients running on a single device. You can create as many objects as you want. Just make sure to use unique addresses (and names optionally) to identify them on the bus.

RobWPink commented 8 months ago

Ok great, Thank you! Last question, it appears this library uses std::vector, which Arduino AVR's standard library doesn't (and can't) include, is there anyway around this? I'm using an Arduino Mega for its multiple Serial ports.

vishnumaiea commented 8 months ago

I think I overlooked that side of the library. Since Modbus data sizes will be fixed and only set during the instantiation, we can use fixed memory allocation for them. I will soon add a workaround for the problem.

PedroPiko commented 8 months ago

Hi Vishnu. First of all a would like to appreciate your effort to create this library. I have started to implement it to Mega 2560. I have been facing an issue with std::vector. Finally I have found an solution for that and I put this line to code #include . This library is a port of uClibc++ Arduino library. Also I have some issue to compile code with SoftwareSerial. Finally I have commented out all SoftwareSerial lines in CSE_485.h, nevertheless I am using hardware ports only. My project is about to control heat recovery ventilation unit in house. I am able to read som input registers now (ADU, CRC, send, receive on serial monitor is correct). I am trying to use class CSE_ModbusRTU_ADU. I have defined CSE_ModbusRTU_ADU adu; and than in setup() CSE_ModbusRTU_ADU(); and in the loop () I put this line: unsigned int aduwrd = adu.getLength(); or getByte ..... but I get always 0x00 even though on serial monitor all ADU data is present and correct. Is it possible to explain how to use this in some sample code? Thank you. Mega 2560 board is client and ventilation unit is server.

vishnumaiea commented 7 months ago

Hi @PedroPiko. Thanks for sharing the workaround for using CSE_ModbusRTU library with Arduino AVR boards. I will try to fix the compatibility issue in the upcoming version.