2 simple can data transmission, Simple can data transmission – Campbell Scientific SDM-CAN Datalogger to CANbus Interface User Manual

Page 46

Advertising
background image

SDM-CAN Datalogger-to-CANbus Interface

Const CMULT1 = 0.4 'Multiplier
Const COSET1 = 0 'Offset

Dim CANBlk1(CANREP1) 'Dimensioned source
'\\\\\\\\\\\\\\\\\\ ALIASES & OTHER VARIABLES //////////////////
Alias CANBlk1(1) = Engine_Speed 'Assign an alias name to CANBlk1(1)

'\\\\\\\\\\\\\\\\\\\\\\\\\\\ PROGRAM ///////////////////////////
BeginProg 'Program begins here
'MainSequence

Scan(PERIOD,P_UNITS,0,0) 'Scan once every 1 Secs, non-burst
'__________________________ CAN Blocks __________________________
'Retrieve Data from CAN network

CanBus(CANBlk1(),ADDR1,TQUANT,TSEG1,TSEG2,217056256,
DTYPE1,STBIT1,NBITS1,NVALS1,CMULT1,COSET1)

Next Scan 'Loop up for the next scan
EndProg 'Program ends here

4.2.2 Simple CAN Data Transmission

The following example transmits a 16 bit temperature value to a CAN network
running at 250K baud.

'Set scan rate
Const PERIOD = 1 'Scan interval number

Const P_UNITS = 2 'Scan interval units (Secs)
\\\\\\\\\\\\\\\\\\\\ THERMOCOUPLE CONSTANTS ////////////////////
'__________________________ Temp Block1 __________________________

Const TRNG1 = 17 'Block1 measurement range (50 mV)
Const TTYPE1 = 0 'Block1 thermocouple type (T)
Const TREP1 = 1 'Block1 repetitions

Const TSETL1 = 30 'Block1 settling time (usecs)
Const TINT1 = 20000 'Block1 integration time (usecs)

Const TMULT1 = 1 'Block1 default multiplier
Const TOSET1 = 0 'Block1 default offset
Dim TBlk1(TREP1) 'Block1 dimensioned source

Units TBlk1 = Deg_C 'Block1 default units (Deg_C)
'\\\\\\\\\\\\\\\\\\\\\\\\\ 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_________________________
'Send switch value Data type 32

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

Const DTYPE1 = 32 'Send switch value
Const STBIT1 = 0 'Start position in data frame
Const NBITS1 = 0 'Number of bits/value

Const NVALS1 = 0 'Number of values
Const CMULT1 = 1.0 'Multiplier
Const COSET1 = 0 'Offset

Dim Switches(CANREP1) 'Dimensioned source
'___________________________CANbus Block2_________________________
'Transmit 16 bit data value

'Data type 20, unsigned integer, least significant byte first
Const CANREP2 = 1 'Repetitions

Const ADDRESS2 = 0 'SDM address of SDM-CAN Module
Const DTYPE2 = 20 'Tx, unsigned int, LSB 1st
Const STBIT2 = 49 'Start position in data frame

Const NBITS2 = 16 'Number of bits/value
Const NVALS2 = 1 'Number of values
Const CMULT2 = 1 'Multiplier

Const COSET2 = 0 'Offset
'\\\\\\\\\\\\\\\\\\ ALIASES & OTHER VARIABLES //////////////////
Public Flag(8) 'General Purpose Flags
Dim TRef(1) 'Declare Reference Temp variable

38

Advertising