Transmitting Standard vs. Extended CAN frames using Visual Basic and the Gryphon DLL
The following code snippet works under the assumption that a Gryphon session has been activated¹, and that a channel handle has been obtained² for the desired CAN channel.
Dim tx_canframe(12) As Byte
Dim tx_gcframe As Long
tx_gcframe = dgCreateFrameHandle(FT_DATA)
' Fill the tx_canframe array with the desired CAN frame data.
' For example:
tx_canframe(0) = &H01
tx_canframe(1) = &H23
tx_canframe(2) = &H45
tx_canframe(3) = &H67
tx_canframe(4) = &H89
tx_canframe(5) = &Hab
tx_canframe(6) = &Hcd
tx_canframe(7) = &Hef
' To send the above example as a Standard CAN frame:
dgSetHeaderLength(tx_gcframe, 2)
dgSetHeaderBits(tx_gcframe, 11)
dgSetDataLength(tx_gcframe, 6)
' Else, to send it as an Extended CAN frame:
dgSetHeaderLength(tx_gcframe, 4)
dgSetHeaderBits(tx_gcframe, 29)
dgSetDataLength(tx_gcframe, 4)
' In both cases, follow with:
dgSetPayload(tx_gcframe, tx_canframe(0))
dgSendFrame(session, channel, tx_gcframe)
In summary: for Standard CAN the "HeaderLength" of the data frame is set to "2" and the "HeaderBits" is set to "11"; for Extended CAN, the "HeaderLength" is set to "4" and the "HeaderBits" is set to "29". The data frame is then used as a parameter in call to dgSendFrame(),
Note that in the above code snippets, function call return value checking is omitted in order to more clearly demonstrate the required logic. In a real program, however, it is strongly recommended that every return value be checked for error conditions, and acted upon accordingly.
Footnotes
1 See dgBeginSession(), Gryphon C Library User's Manual, Dearborn Group Inc.
2 See dgGetChannel(), Gryphon C Library User's Manual, Dearborn Group Inc.