Changing bus speed using Visual Basic and the Gryphon DLL

This example assumes the use of a single wire CAN channel, and illustrates how to change the channel's transceiver to GMLAN SWC Low Speed and High Speed modes.  The method used here is the modification of the channel's Bus Timing Register values via the Gryphon Protocol IOCtl mechanism.

The following code snippet works under the assumption that a Gryphon session has been activated¹, and that the channel handle has been obtained² for the desired single wire CAN channel.

Dim ioctl_num As Long
Dim ioctl_data(2) As Byte

dgGetSetSpeedIOCtl(hChannel, ioctl_num)

' GMLAN SWC High Speed BTRs: 0x47 0x98
ioctl_data(0) = &H47
ioctl_data(1) = &H98

dgIOCtl(hChannel, ioctl_num, ioctl_data(0), 2)
dgInit(hChannel, 0)

MsgBox ("channel is now in
GMLAN SWC High Speed mode")

' GMLAN SWC Low Speed BTRs: 0x4f 0xaa
ioctl_data(0) = &H4F
ioctl_data(1) = &HAA

dgIOCtl(hChannel, ioctl_num, ioctl_data(0), 2)
dgInit(hChannel, 0)

MsgBox ("channel is now in
GMLAN SWC Low Speed mode")

Note that in the above code snippet, 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.