Kvaser J1939 Library
Channel Management

Create and open a J1939 channel

The function j1939_create_channel is used to create a J1939 channel and j1939_open_channel is used to open the channel for communication.

The channel may be opened and closed multiple times during its lifetime and this is similar to bus on and bus off in CANlib.

Example. Create and open a channel.

// Define channel parameters
.channel = 0,
.support_virtual = true,
.bit_rate = 250000,
};
// Create a channel
if (ch_result.result != J1939_STATUS_OK) {
// Handle error
}
int channel_handle = ch_result.handle;
// Open the channel
int status = j1939_open_channel(channel_handle);
if (status != J1939_STATUS_OK) {
// Handle error
}
// Destroy the channel when done
status = j1939_close_channel(channel_handle);
status = j1939_destroy_channel(channel_handle);
J1939ChannelResult j1939_create_channel(const J1939ChannelParams params)
Create a J1939 channel.
J1939Result j1939_destroy_channel(J1939ChannelHandle hnd)
Destroy a J1939 channel.
J1939Result j1939_close_channel(J1939ChannelHandle hnd)
Close a J1939 channel and go off bus.
J1939Result j1939_open_channel(J1939ChannelHandle hnd)
Open a J1939 channel and go on bus.
@ J1939_STATUS_OK
Operation completed successfully.
Definition: kvj1939lib_types.h:18
A struct that holds the parameters for creating a j1939 channel.
Definition: kvj1939lib_types.h:77
uint32_t channel
The CANlib channel number to use.
Definition: kvj1939lib_types.h:79
A struct that holds the result and handle for creating a j1939 channel.
Definition: kvj1939lib_types.h:91
J1939Result result
The result of the operation.
Definition: kvj1939lib_types.h:93

Channel configuration

The J1939ChannelParams structure passed to j1939_create_channel is used to configure a J1939 channel. The bit_rate parameter is used to set the CAN bitrate for the channel. In order to set the bit rate, the CANlib channel must be opened with init access. If the CANlib channel is already opened with init access then j1939_create_channel will fail. If the bit_rate parameter is 0, the channel will not attempt to set the bit rate and will use the existing bit rate of the CAN channel.

Additional channel options can be set using j1939_set_channel_option, see J1939ChannelOption for available configuration options.