1 reading can data, Reading can data – Campbell Scientific SDM-CAN Datalogger to CANbus Interface User Manual

Page 45

Advertising
background image

SDM-CAN Datalogger-to-CANbus Interface

require an update to your CRBASIC editor to get the full help screens. Contact
Campbell Scientific if you need advice about upgrading your operating system.

The CANBUS instruction takes the form:

CANBUS(CANDATA(),ADDRESS,TIMEQUANTA,TSEG1,TSEG2,ID,
DATATYPE,STARTBIT,NUMBITS,NUMVALS,MULT,OFFSET)

where:

CANDATA is a variable or array which either holds data to be transmitted or
will hold data that is to be read from the CAN-Bus.

ADDRESS is the SDM address of the SDM-CAN in question.

TQUANTA, TSEG1 and TSEG2 have the same function as in P118 above.

ID is the CAN ID, where the ID is entered as a single decimal equivalent.
Entering the number as a negative value signifies it is an 11 bit ID, otherwise it
is a 29-bit ID.

Due to current system constraints the ID parameter must be
entered directly into the CanBus instruction.

NOTE

DATATYPE is the same as in P118.

STARTBIT is the same as in P118, except you enter a negative number
instead of ‘indexing’ the number to signify lefthand referencing.

NUMBITS is the same, and again a negative number is equivalent to indexing
the value to enable an interrupt.

NUMVALS, MULT and OFFSET all have the same function.

4.2.1 Reading CAN Data

The following example reads a 16 bit engine speed value from a CAN network
running at 250K baud.

'Set scan rate
Const PERIOD = 1 'Scan interval number
Const P_UNITS = 2 'Scan interval units (Secs)

'\\\\\\\\\\\\\\\\\\\\\\\\\ CANBUS CONSTANTS //////////////////////
'------------------- Physical Network Parameters -----------------
Const TQUANT = 4 ')Set SDM-CAN to 250K

Const TSEG1 = 5 ')Network speed
Const TSEG2 = 2 ')
'---------------------- Data Frame Parameters --------------------

'___________________________CANbus Block1_________________________
'Collect and retrieve 16 bit data value
'Data type 2, unsigned integer, least significant byte first

Const CANREP1 = 1 'Repetitions
Const ADDR1 = 0 'SDM address of SDM-CAN Module

Const DTYPE1 = 2 'Collect and retrieve data values
Const STBIT1 = 33 'Start position in data frame
Const NBITS1 = 16 'Number of bits/value
Const NVALS1 = 1 'Number of values

37

Advertising