Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

CR1000 communication via Modbus protocol


chliao Jun 2, 2009 10:48 PM

Hi

I am trying to "just collect" data from a CR1000 to my PC (not sending data or writing data to CR1000). I want to make the CR1000 as a Modbus slave and make my pc (running with NI LabView) as a Modbus server without going through LoggerNet btwn LabView and CR1000.

From the CR1000's manual and CRBasic's help (Modbus slave example), I compiled and sent the following CRBasic code via LoggerNet (on different pc) to CR1000. Then connected the CR1000 w/ RF416 to the PC (Modbus server) to excute it. I wonder is the code correct? Shall I use ComSDC7 or ComRS232 in the ModBusSlave line?

My system is: one AM25T connects to CR1000;
CR1000 connects to RF416s
RF416 connects to PC(as Modbus server)
Any feedback is appreciated. Thank you,

Hsien

Public BattV
Public RTempC
Public Temp_F(25)

Units BattV=Volts
Units RTempC=Deg C
Units Temp_F=Deg F

'Define Data Tables
DataTable(TableTC,True,-1)
DataInterval(0,10,Min,10)
Average(1,BattV,FP2,False)
Average(1,Temp_F(1),FP2,False)
Average(1,Temp_F(2),FP2,False)
Average(1,Temp_F(3),FP2,False)
Average(1,Temp_F(4),FP2,False)
Average(1,Temp_F(5),FP2,False)
Average(1,Temp_F(6),FP2,False)
Average(1,Temp_F(7),FP2,False)
Average(1,Temp_F(8),FP2,False)
Average(1,Temp_F(9),FP2,False)
Average(1,Temp_F(10),FP2,False)
Average(1,Temp_F(11),FP2,False)
Average(1,Temp_F(12),FP2,False)
Average(1,Temp_F(13),FP2,False)
Average(1,Temp_F(14),FP2,False)
Average(1,Temp_F(15),FP2,False)
Average(1,Temp_F(16),FP2,False)
Average(1,Temp_F(17),FP2,False)
Average(1,Temp_F(18),FP2,False)
Average(1,Temp_F(19),FP2,False)
Average(1,Temp_F(20),FP2,False)
Average(1,Temp_F(21),FP2,False)
Average(1,Temp_F(22),FP2,False)
Average(1,Temp_F(23),FP2,False)
Average(1,Temp_F(24),FP2,False)
Average(1,Temp_F(25),FP2,False)
EndTable

'Main Program
BeginProg
ModBusSlave (ComSDC7,9600,1,Temp_F(),0)

Scan(2,Sec,1,0)
'Default Datalogger Battery Voltage measurement BattV
Battery(BattV)
'Type K (copper-constantan) Thermocouple measurements Temp_F() on the AM25T Multiplexer
AM25T(Temp_F(),25,mV250C,1,1,TypeK,RTempC,1,2,1,True,0,_60Hz,1.8,32)
'Call Data Tables and Store Data
CallTable(TableTC)
NextScan
EndProg


denyan Jun 3, 2009 10:23 AM

Dear Chliao,
I would like to send data through modbus communication too, but I don't know which kind of instruction Labview must sent so that the cr1000 can send the variables, such as Temp(0), Temp(1), Temp(2), and so on...

Regards
Deny


chliao Jun 3, 2009 05:16 PM

Hi Deny,

Honestly, I am new on the Campbell SCI system and have no idea. So far, I use "VISA WRITE" and "VISA READ" only. When I send \n\r to CR1000 via VISA WRITE, I can read "CR1000> " in the buffer only. People in NI discussion forum suggested using DSC to communicate with CR1000 directly. Or use Modbus liberary if dont have DSC module.

From my understanding (not sure if correct or not), the CR1000 itself excutes the CRBASIC program to serve as Modbus slave.

Do you have any information to share ?

Regards,
chliao


MattPerry Jun 3, 2009 09:13 PM

I want to make the CR1000 as a Modbus slave and make my pc (running with NI LabView) as a Modbus server without going through LoggerNet btwn LabView and CR1000.

ModBus RTU Master, NI LabView-(RS-232)--- (RS-232)-RF416 --- RF416-(CSI/O)-Modbus RTU Slave, CR1000

Each device in this application needs to be configured appropriately. Each device is configured to match the configuration of the device it is attached to. For example, the RS-232 baud rate of the RF416 needs to match the RS-232 baud rate of the Modbus master (8-N-1). The RF416's should be in Transparent mode. The active interface for the RF416 on the PC should be RS-232. The active interface for the RF416 on the CR1000 should be Datalogger Modem Enable and the CS I/O ME Baud Rate should be set to match the BaudRate of the CR1000's CS I/O port which is defined in the ModBusSlave instruction of the CR1000 program file. The ModBusSlave instruction sets up the datalogger as a ModBus slave device and configures the Modbus settings and com port:

'ModBusSlave ( ComPort, BaudRate, ModBusAddr, ModBusVariable, BooleanVariable)
ModBusSlave (ComME,-9600,1,ModBusVariable(),Variable())

Device Configuration Utility works great for configuring the RF416's and CR1000.


denyan Jun 4, 2009 09:18 AM

Dear MattPerry,
which kind of instruction can I use if my control software is Labview for example?
What is the sequence of commands in order to the cr1000 sends a reply in modbus slave option?

Kind regards
Deny Antonino


MattPerry Jun 4, 2009 03:14 PM

Assuming LabView supports ModBus RTU, you can use the ModBusSlave instruction in the datalogger program file. This will set the datalogger up as a ModBusSlave device. The datalogger will act as a ModBusSlave device and respond to requests (funtions) from a ModBusMaster Here is a program example:

Public PTemp, batt_volt, ModResult,I
Public ModIn(80)

'Main Program
BeginProg

'ModBusSlave ( ComPort, BaudRate, ModBusAddr, ModBusVariable, BooleanVariable)

ModBusSlave (ComRS232,9600,1,ModIn(),0)

Scan (2,Sec,0,0)

PanelTemp (PTemp,250)

Battery (Batt_volt)

ModIn(1) = batt_volt
ModIn(2) = PTemp
ModIn(3) = ModResult

NextScan
EndProg

----
In this example, the ModBusSlave instruction has:

1. Defined the RS232 port of the datalogger as the communication port that will be used for this instruction,
2. Set the rate, in bps, for communication at 9600,
3. Set the ModBusSlave (CR1000) address to 1,
4. Specified the variable array that is used as the source of data for the ModBusMaster as ModIn().
5. Mapped discrete commands to control ports 1 through 8.

When the CR1000 receives a Function command of either 3 (read holding registers) or 4 (read input registers), it will respond with the data defined in the ModIn() variable array, which for this example will be batt_volt, PTemp, and ModResult. These variables are floating point variables and they take two ModBus registers each. The ModBus input registers are offset by 30000; ModBus holding registers are offset by 40000. Therefore, the first register corresponding to any array location X is holding register 40000+2X-1. For example, to retrieve array value number 3, the ModBusMaster would ask for two registers starting with 40005.


chliao Jun 4, 2009 08:42 PM

Dear Matt,

On CR1000's manual 15.2.3.4, it lists the following Function commands 01, 02, 03, 04, 05 ,15 and 16.

But What are Function commands 6,7 and 9 represent for?

I sent command 7 to CR1000 and received the table array I specified in CRBasic. Does command 7 requests CR1000 to send back the data stored in the memory?

If I send command 9, I continuously receive an array of codes. What is the type of this codes? ASCII or Hex?

Thank you very much.
chliao


MattPerry Jun 4, 2009 10:02 PM

Chliao,

I apologize, but I'm not going to be much help with this set of questions. I can not comment on how the CR1000 is going to respond to these non-supported functions. I did, however, find a great website on modbus protocol and functions:

http://www.lammertbies.nl/comm/info/modbus.html#func

-Matt

* Last updated by: MattPerry on 6/4/2009 @ 4:02 PM *


chliao Jun 4, 2009 11:37 PM

Dear Matt,

Thank you for the useful website. By sending command "\n\r7" (hyperterminal) to CR1000, I am able to retrive the data I want. Thank you.

Denyan,

In LabView, I just use the "write visa" to send above command to CR1000 and I can read the data in the buffer by using "read visa". Good luck to you,

Chliao


denyan Jun 5, 2009 02:22 PM

Thank you very much for your support.
Now I try to experiment this code....


Regards
Deny


denyan Jun 5, 2009 02:59 PM

Dear Chliao,
I have sent through hyperterminal the following instruction: "\n\r7" but the cr1000 doesn't give me the variables indicated in ModbusSlave.
The example of program is:

Public PTemp, batt_volt, ModResult,I
Public ModIn(80)

'Main Program
BeginProg

'ModBusSlave ( ComPort, BaudRate, ModBusAddr, ModBusVariable, BooleanVariable)

ModBusSlave (ComRS232,9600,1,ModIn(),0)

Scan (2,Sec,0,0)

PanelTemp (PTemp,250)

Battery (Batt_volt)

ModIn(1) = batt_volt
ModIn(2) = PTemp
ModIn(3) = ModResult

NextScan
EndProg


Is there any problem in the code?

Regards
Deny


Sam May 13, 2013 02:12 AM

\n\r7

Is referring to the terminal interface of the logger. Pressing Enter on the keyboard gets you the CR1000 prompt. Entering 7 will show you a list of variables/values.

This functionality is unrelated to the ModbusSlave instruction.

ModbusSlave is intended to set the datalogger up to listen for data queries using the Modbus protocol. Going back to how I arrived here .... Yes Modbus is one viable method for retrieving realtime data from a Campbell logger using LabView.

Log in or register to post/reply in the forum.