Hello everyone,
I just acquired a CR6 data logger and I need to recover data from a pressure sensor. I'm not familiar with CRBasic at all (or Modbus protocol) and I'm in a hurry to make it works.
I'm looking for an example of a code that allows me to read the data from the sensor and store it on the SD memory card. I didn't find an easy way to code it in Shortcut so I need to write it myself but I don't know where to start.
Does anyone has a code that I could use or any tips on how to start?
The characteristic of the sensor are:
- RS 485 with Modbus RTU
-it's a master-slave system so I need to request the data
- 9600 baud rate
- two actives channels which are in the register 0x0100 (so I need to read 4 registers (2*32bit)
Thanks a lot for your help.
Best,
N. de Ville
Hi Nicolas
Have you had a look at the ModBusMaster instruction in CRBasic
The help section is very comprehensive and also includes a working programming example.
BR
IOG
Hello IOG,
Thanks for your reply.
Yes I have checked the ModBusMaster instruction in CRBasic but I can't find exactly how I must write the communication code between the Modbus master (CR6) and Modbus slave (pressure sensor). I started from the provided working example in CRBasic then I'm not sure how I must proceed.
I read from the sensor communication protocol that it's a binary protocol, not an ASCII thus should I code it differently? Should I use the ModbusMaster function or the SerialOpen function?
Also I don't know where I should write the register address in the reading function...
Attached is the communication protocol of the sensor.
Honnestly I don't really know where to start so any help would be very welcome
Thanks.
Best,
N. de ville
http://www.keller-druck.com/picts/pdf/engl/comm_protocol_e.pdf
Hi Nicolas
Use the ModBusMaster instruction.
Please see my email.
We are usung Keller-Druck PA36 and PA33 pressure sensors with CR6. We use this code:
Public PTemp
Public batt
Public ModBus (2), Result
Alias ModBus(1)= PA36_Pressure
Alias ModBus(2)= PA36_Temp
DataTable (Your_Table_Name,True,-1)
DataInterval (0,1,Sec,10)
Minimum (1,batt,FP2,False,False)
Average (1,PA36_Pressure,IEEE4,False)
Average (1,PTemp,FP2,False)
Average (1,PA36_Temp,FP2,False)
EndTable
'Main Program
BeginProg
'Turn power on for Keller sensor @SW12 #2
SW12 (2,1 )
'Define com port parameters for Keller sensor communication
SerialOpen (ComC1,9600,0,0,50,4)
Scan (100,mSec,0,0)
'Panel Temperature
PanelTemp (PTemp,15000)
'Main battery voltage
Battery (batt)
'PA36 Pressure Transducer Water level and water temperature measurements, ModBus data
ModbusMaster (Result,ComC1,9600,1,3,ModBus(),257,2,1,3,2)
'Call Output Tables
CallTable Your_Table_Name
NextScan
EndProg
The above program read both water level and water temperature that the Keller-Druck sensor measure. If you want to send data to the microSD card use the following line in the 3rd section of the program, after "DataInterval (0,1,Sec,10)":
TableFile ("CRD:Your_Table_Name",64,-1,0,24,Hr,0,0)
This example will store the data in a 24 hours data files (one for each day).
You need to connect the sensor 485B cable to C1 and 485A cable to C2 on the CR6.
Uri you are my savior.
I will try your code at my office today but I already thank you a lot.
Have a nice day,
BR
N. de Ville
I just tested the code and it works perfectly!
Thanks again,
N. de Ville
You welcome.
The credit for the code should go to the engineer at meteo-tech ltd. Campbell sci. local distributor and technical support.
He told me that Keller use a modified vertion of modbus which they call kellerbus. It took him quite a while to finalize the communication parameters in the 'ModbusMaster' instruction.
glad to help
Actually Keller can use two kind of protocol, Kellerbus or Modbus RTU (just a precision for people that would need it)
The problem in my code was that I didn't parametrize the Com port with SerialOpen before using the ModbusMaster function.
Thanks Guys
I had overlooked the required SerialOpen command
I suppose that is the beauty of the forum
Hello!
I´m trying to configure a CR6 like a slave in a Modbus network. I found the code for a CR1000, some information in the manual and here that is for a Modbus master.
I´m trying to communicate with a simulator (Modbus Master Simulator), but it doesn't work.
The test is very basic, i´m just trying to communicate with other PC, and send some information, like temperature and voltage level of the battery, for the moment.
I leave the code, if you can help me with this, i will very thankfull.
'Declare Public Variables
Public PTemp, batt_volt
Public Modbus(2) As Long
Public Xvar As Boolean
Units PTemp=Grados
Units batt_volt=Volts
'Define Data Tables.
DataTable (Tabla,True,-1)
DataInterval (0,1,Min,10)
Sample (1,PTemp,FP2)
Minimum (1,batt_volt,FP2,False,False)
EndTable
'Main Program
BeginProg
SerialOpen(COMRS232,9600,3,100,0,0)
Scan (1,Sec,0,0)
PanelTemp (PTemp,50)
Battery (batt_volt)
ModbusSlave(COMRS232,9600,10,Modbus(),Xvar,0)
Modbus(1)=PTemp
Modbus(2)=batt_volt
CallTable Tabla
NextScan
EndProg
GonzaloSotoUribe
I suggest looking at the white paper about using the datalogger as a Modbus slave device:
https://s.campbellsci.com/documents/us/technical-papers/dataloggers-as-modbus-slave-devices.pdf