4.Modbus and Campbell Scientific Dataloggers

4.1Description

CRBasic is the programming language used with all Campbell Scientific CRBasic data loggers. Campbell Scientific's LoggerNet software is typically used when programming in CRBasic.

Campbell Scientific's CR6 datalogger can directly communicate with the Model 8960-01C interface, using the RS-485 protocol. However, the CR1000 and CR800 dataloggers don’t support the RS-485 protocol.  To accomodate this, geokon provides the Model 8020-38 RS-485 to TTL/USB converter.

4.2Model 8020-38 RS-485 to TTL/USB Converter

geokon makes the Model 8020-38 Addressable Bus Converter for connecting addressable strings to personal computers, readouts, dataloggers, and programmable logic controllers. The converter acts as a bridge using the TTL or USB protocols between readers and the geokon RS-485-enabled sensor strings.

For more information, please refer to the Model 8020-38 instruction manual.

04_Modbus_And_Campbell_Scientific_Dataloggers00079.png

 

Figure 11: Model 8020-38 RS-485 to TTL/USB Converter

Note: The datalogger you use must have the appropriate port available.

If your datalogger does not have built-in RS-485 communications, connect the wiring using the diagram in Figure 12.

04_Modbus_And_Campbell_Scientific_Dataloggers00080.png

 

Figure 12: Wiring of Datalogger without built-in RS-485 Conversion

If your datalogger has built-in RS-485 communications, connect the wiring using the diagram in Figure 13.

04_Modbus_And_Campbell_Scientific_Dataloggers00081.png

 

Figure 13: Wiring of Datalogger with built-in RS-485 Conversion

4.3Sample Program

The following program uses a Model 8960-01C interface to directly connect to any single geokon vibrating wire sensor. The 8960-01C interface uses MODBUS RTU commands and returns a frequency (Hz) reading for the vibrating wire.  It returns a resistance reading (Ohms) for the thermistor.

Note: The 8960-01C MODBUS RTU table register numbers begin with 0. Campbell Scientific Dataloggers recognize MODBUS RTU table register numbers as beginning with 1. All CRBasic register numbers are +1. Example: ModbusMaster won't send 0x118 unless "&H119" is entered in the command line.

 

'Define address of the 8960-01C

Const Address = 1      'Address of Interface, used in variable declaration

 

'Constants used in Steinhart-Hart equation to calculate sensor temperature

'for 3k thermistor

 Const    A = 1.4051E-3

Const B = 2.369E-4

Const C = 1.019E-7

 

Public ErrorCode         'Error Code sent back from ModBus command

Public Hz(Address)   'Frequency (Hz) from incoming data

Public Digits(Address)   'Calculated Digits

Public Res(Address)   'Resistance (Ohms) from incoming data

Public Celsius(Address)   'Calculated temperature (Celsius)

'Define Data Tables

DataTable (Test, 1,-1)

  Sample (Address,Digits(),IEEE4)

  Sample (Address,Celsius(),IEEE4)

EndTable

'Main Program

BeginProg

 'Open COMport with RS-485 communications at 115200 baud rate

   SerialOpen (ComC1,115200,16,0,50,3)   'CR6 program

   SerialOpen (Com1,115200,16,0,50)   'CR1000 program

 'Read the interface/sensor every 30 seconds

   Scan (30,Sec,0,0)

 'Reset temporary storage for both Resistance and Hz so not to retain

 'previous reading

   Res(Address) = 0

   Hz(Address) = 0

  'Flush Serial between readings

   SerialFlush (ComC1)

  'Write to register 0x118 to trigger interface

  'NOTE: ModbusMaster won't send 0x118 unless "&H119" is entered

   ModbusMaster (ErrorCode,ComC1,115200,Address,6,1,&H119,1,1,10,0)

  'Delay after triggering the measurement

   Delay (1,1,Sec)

  'Use Modbus command to retrieve Hertz from string

   ModbusMaster (ErrorCode,ComC1,115200,Count,3,Hz(Address),&H101,1,1,10,0)

  'Calculate Digits from Hertz

   Digits(Address) = (Hz(Address)^2)/1000

  'Use Modbus command to retrieve thermistor resistance

   ModbusMaster (ErrorCode,ComC1,115200,Address,3,Res(Address),&H103,1,1,10,0)

  'Calculate thermistor temperature from Ohms to Celsius using Steinhart-Hart

  'equation

   Celsius(Address) = 1/(A+B*LN(Res(Address))+C*LN(Res(Address))^3)-273.15

  Next

 'Call table to store data

 CallTable Test

NextScan

EndProg