before posting this question, I read all the forum messages relating to the modbus RTU RS485. I hope you can help me.
I want to retrieve data from a CO2 sensor using the Modbus RTU protocol
1.hardware and connections
One CR300 logger
One cable (between CR300 COMRS232 & Adapter) which connects the gounrd (pin 5) together, the Rx from the first DB9 to the Tx second DB9 and the Tx from the first DB9 to the Rx second DB9, that’s all.
One CO2 sensor: https://www.evikon.eu/pdf/evikon/E2618-CO2_UM_EN.pdf The sensor (tested by a USB / RS485 interface and supplier software) is functional. It physical address is 01h and the other parameters are those listed in the data sheet
Between the RS485 bus cables, I placed a 100 Ohm resistor. The length of the bus is about 20 inch (50 cm) .... I use electric cables that do not have the right characteristic impedance
2. The little program
The idea of this code, at first, is simply to retrieve the serial number of the sensor
'Declare Variables and Units
Public ModbusData(20) 'Création d'une variable
Units PTemp_C=Deg C
'Define Data Tables
'Default CR300 Datalogger Battery Voltage measurement 'BattV'
'Default CR300 Datalogger Processor Temperature measurement 'PTemp_C'
'Récupération des données Modbus. ModbusMaster(ResultCode, ComPort, BaudRate, ModbusAddr, Function, Variable, Start, Length, Tries, TimeOut, ModbusOption)
3. the problems
4. My tests
A. RS485 adapter Output
To be sure that the frame is well generated at the output of the RS232 / RS485 adapter, I put the oscilloscope. We can see the frame every 3 seconds.
To make sure that pins 2 and 3 of my cable must be crossed, I tested with Rx on Rx and Tx on TX. Under these conditions, no frame is generated.
B. Pinout connexion of the sensor
the CO2 sensor informs the terminal connexiotn by A and B (name for which there is often confusion compared to the standard) while the adapter informs + and -, I tested the two combinations, without success
C. Device configuration Terminal
Through the terminal, I make sure that the hex values correspond to the needs of the C02 sensor ....
As the oscillospce can influence the impedance of the bus, I unplug it to do the tests.
In advance, thank you for your feedback and your sharing of skills.
After having carried out many tests, I was finally able to understand. The registers of the sensors are on 1 byte while the request waited for 32 bits.
It was therefore a simple code error
Happy you were able to solve the problem. In the end - how did you resolve the mismatch between sizes of the request and registers on the sensor?
I am struggling with a similar problem (I think) - connection keeps timing out and the Modbus variable remains zero.
the problem came from the "Length" parameter and the choice of the "modbus option" parameter. it obviously depends on your sensor (16 bits or 32 ...)
the combination of the two is important