CAN DragonEmSA
functionChannel Lifecycle

EmSACAN_OpenChannel

Prototype

emsacan_result_t EmSACAN_OpenChannel(
    emsacan_handle_t Handle,
    uint8_t ChannelNumber,
    emsacan_channel_connection_callback_fn ConnectionCallback,
    void *UserContext );

Description

Opens the connection to a specific CAN port so traffic can flow.

Parameters

ParameterDirectionTypeDescription
Handleinemsacan_handle_tSession handle from EmSACAN_Connect.
ChannelNumberinuint8_tZero-based port index.
ConnectionCallbackinemsacan_channel_connection_callback_fnOptional callback for USB disconnect/reconnect while this port stays open; pass NULL to disable notifications for this port.
UserContextinvoidOpaque pointer passed to ConnectionCallback.

Return value

EMSACAN_OK on success, or another emsacan_result_t code on failure.

Example

void __cdecl OnConn(emsacan_handle_t h, uint8_t ch,
                    emsacan_channel_connection_event_t ev, void *ctx)
{
    /* EMSACAN_CHANNEL_CONNECTION_DISCONNECTED or _RECONNECTED */
}

emsacan_result_t rc = EmSACAN_OpenChannel(handle, 0, OnConn, NULL);
if (rc != EMSACAN_OK) { /* failed to open port 0 */ }

See also