Campbell Scientific CR9000X Measurement and Control System User Manual

Page 249

Advertising
background image

Section 7. Measurement Instructions

7-25

SDMCAN Example 2
The following example uses the request/receive capability of the SDMCan to
request a data frame with an 11 bit identifier in the Slow Sequence Scan.













































' /////////////////////// DECLARATIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'_________________________ Volt Block 1 _________________________

Public VBlk1(1): Units VBlk1 = mVolts

' _____________ CANBUS _________________________/
'Setup SDMCANBus Address and CAN Network Communication Values

Const CanAddress=0 : Const CanQuanta=1 : Const CanSeg1=5 : Const CanSeg2=2
Public CanSwitchTx, CanSwitchRx

'Config values to send (Tx) and confirm (Rx) on SDM-CAN

Public Can001(1) : Units Can001 = kPAbsolute : Alias Can001(1) = P0BIntakeMAP
Public Flag(8)

'General Purpose Flags

'

\\\\\\\\\\\\\\\\\\\\\\\\ OUTPUT SECTION ////////////////////////

DataTable(Table1,True,-1)

'Trigger, auto size

DataInterval(0,1,Sec,100)

'1 Sec interval, 100 lapses, autosize

Sample (1,VBlk1(),IEEE4)

'1 Reps,Source,Res

Sample (1,Can001(),IEEE4)

'1 Reps,Source,Res

EndTable

'End of table Table1

'\\\\\\\\\\\\\\\\\\\\\\\\\\\\ PROGRAM ////////////////////////////

BeginProg

'Preliminary CanBUS Configuration Scan(s)

CanSwitchTx=0004

'EnableTransmit, UseOldData

Scan(1,Sec,0,10)

'Set Switches - NAN and TxEnable

'CANBUS ID 1 = Config SDM-CAN, DataType32 = SetSwitch, NumVals = 1

SDMCAN(

CanSwitchTx,CanAddress,CanQuanta,CanSeg1,CanSeg2,1,32,0,0,1,1.

0,0.0)

'CANBUS

ID 1 = Config SDM-CAN, DataType33 = ReadSwitch, NumVals = 1

SDMCAN

(CanSwitchRx,CanAddress,CanQuanta,CanSeg1,CanSeg2,1,33,0,0,1,1.0,0.0)

If CanSwitchRx = CanSwitchTx Then ExitScan

' Exit Scan once setting is verified

NextScan

' \\\\\\\\\\\\\\\\\\\\\ MAIN SCAN ///////////////////////////

Scan(10,mSec,10,0)

'Scan once every 10 mSecs, non-burst

VoltDiff(VBlk1(),1,17,4,1,True,30,100,1,0)
CallTable Table1
Next Scan

'Loop up for the next scan

SlowSequence

'Used for slow measurements

Dim idx

'Index for looping through Rx Retries

Public ByteTx(8),ByteRx(8)

'Intermediate Transmit and Receive placeholders

Do

'For CANBUS TxRx, we need mult, repeating scans

Scan(20,mSec,0,1)

' Back Ground Calibration Scan once during every Do-loop

Calibrate

'Corrects ADC offset and gain

BiasComp

'Corrects ADC bias current

Next Scan

'Loop up for the next scan

'Setup Transmit Data Frame: &H02010B0000000000 for J1979 Legislative PID $0B

'This request is for the Intake manifold absolute pressure.

ByteTx(8)=&H02 : ByteTx(7)=&H01 : ByteTx(6)=&H0B : ByteTx(5)=&H00
ByteTx(4)=&H00 : ByteTx(3)=&H00 : ByteTx(2)=&H00 : ByteTx(1)=&H00

SDMCan

(ByteTx(),CanAddress,CanQuanta,CanSeg1,CanSeg2,-&H7DF,19,1,8,8,1,0)

For idx=0 to 50

'Look for the Rx that matches the Tx 50 times

Delay(1,20,mSec)

'Wait for 20msec - timing issue

SDMCan

(ByteRx(),CanAddress,CanQuanta,CanSeg1,CanSeg2,-&H7E8,1,1,8,8,1,0)

'Check the Rx value just obtained; if it matches &HXX410BXXXXXXXXXX -decode it

If (ByteRx(6) = &H0B) And (ByteRx(7) = &H41) Then

'DataType=1, StartBit=33, NumberofBits=8, NumberofValues=1, Mult=1, Offset=0

SDMCan

(Can001(),CanAddress,CanQuanta,CanSeg1,CanSeg2,-&H7E8,1,33,8,1,1,0)

ExitFor
EndIf
Next
idx

'Return for next time through the loop

Loop

'Loop back to the "DO"

EndProg

'Program ends here

Advertising