CIRCUITSTATE / CSE_ModbusRTU

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

CSE_ModbusRTU_ADU class #3

Open PedroPiko opened 8 months ago

PedroPiko commented 8 months ago

My project is about to control heat recovery ventilation unit in house. I am able to read some 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 then 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 CSE_ModbusRTU_ADU class in some sample code? Thank you. My Mega 2560 board is client and ventilation unit is server.

vishnumaiea commented 7 months ago

Hi @PedroPiko. Sorry for the delay after our first interaction. I am editing the styling of your comment to make it easy to read.

The class CSE_ModbusRTU_ADU can be used to create standlone ModbusRTU packets. The usage is well explained in the API.md document. In order to read from the ADU, you will need to first write data to it. When the CSE_ModbusRTU_ADU class is used in conjunction with the CSE_ModbusRTU_Server and CSE_ModbusRTU_Client classes, they take care of writing to the ADUs.

So when using the CSE_ModbusRTU_ADU directly, you need to make sure that you add data to the object first.

I also don't understand why you have,

CSE_ModbusRTU_ADU();

in your setup() function. It is unnecessary. Global objects are instantiated where they are declared.

Please let me know if you have gained a better understanding of the library while I was away, and any other suggestions for improving the library and its documentation.