CAN interface
Read_Msg
ADwin
154
ADwin-Gold II
, Manual February 2013
Example
Rem Please select the appropriate include for ADbasic /
TiCoBasic
#Include
ADwinGoldII.inc / GoldIITiCo.inc
REM If a new message with the correct identifier is received
REM the data is read out. The first 4 bytes of the message are
REM combined to a float value of length 32 bit. (Sending a
REM float value see example of
).
Dim
n
As
Long
Init:
Par_1
=
0
Init_CAN
(
1
)
'Initialize CAN controller 1
En_Receive
(
1
,
1
,
40
,
0
)
'Initialize the message object 1
'to receive CAN messages with
'identifier 40
Event:
REM If the message is changed
,
read out the received data
REM from object 1 a
n
d transfer the identifier to parameter 9.
REM The data bytes are in the array CAN_Msg[].
Par_9
=
Read_Msg
(
1
,
1
)
If
(
Par_9
=
40
)
Then
REM New message for message object with the identifier 40
REM has arrived
Par_1
=
CAN_Msg
[
1
]
'Read out high-byte
For
n
=
2
To
4
'Combine with remaining 3 bytes
'to
Par_1
=
Shift_Left
(
Par_1
,
8
)
+
CAN_Msg
[
n
]
'a 32-bit value
Next
n
REM Convert the bit pattern in Par_1 to data type FLOAT and
REM assig
n
to the variable FPar_1.
FPar_1
=
Cast_LongToFloat
(
Par_1
)
EndIf
Sending a float value see example at