CAN DragonEmSA

Quick Start

This guide walks you through the minimum path to connect a CAN Dragon and exchange your first CAN frame. Each step links to deeper documentation — click any API name to jump to its reference.

Before you begin

  1. Install the CAN Dragon driver on Windows (Requirements)
  2. Connect your CAN Dragon via USB-C
  3. Ensure your app and EmSACAN.dll target the same CPU architecture (x64 or x86)

Six-step path

Driver, USB device, matching CPU architecture

Read full guide →

Interactive program flow

Interactive Program FlowClick a step to explore
StartupEnumerateConnectConfigureOpen ChannelRead / WriteCloseDisconnectShutdown

Initialize the library once per process. Choose shared (0) or exclusive (1) mode.

Minimal C example

#include "EmSACAN.h"

int main(void)
{
    emsacan_handle_t handle = 0;
    emsacan_interface_t ifaces[8];
    int count = 8;

    if (EmSACAN_Startup(0) != EMSACAN_OK) return 1;

    if (EmSACAN_EnumerateInterfaces(ifaces, &count) != EMSACAN_OK || count == 0) {
        EmSACAN_Shutdown();
        return 1;
    }

    if (EmSACAN_Connect(ifaces[0].SerialNumber, 0, &handle) != EMSACAN_OK) {
        EmSACAN_Shutdown();
        return 1;
    }

    emsacan_channel_config_t cfg = {
        .flags = EMSACAN_CONFIG_FLAGS_NONE,
        .termination = EMSACAN_TERMINATION_120,
        .nominal_kbps = 500,
        .data_kbps = 2000
    };
    EmSACAN_WriteParameter(handle, EMSACAN_PARAM_CHANNELCONFIG, 0,
                           (uint8_t *)&cfg, sizeof(cfg));

    EmSACAN_OpenChannel(handle, 0, NULL, NULL);

    emsacan_msg_t tx = { .id = 0x123, .len = 4, .type = EMSACAN_MSGTYPE_NONE };
    tx.data[0] = 1; tx.data[1] = 2; tx.data[2] = 3; tx.data[3] = 4;
    EmSACAN_Write(handle, 0, &tx);

    emsacan_msg_t rx;
    if (EmSACAN_Read(handle, 0, &rx) == EMSACAN_OK) {
        /* use rx.id, rx.data, rx.timestamp */
    }

    EmSACAN_CloseChannel(handle, 0);
    EmSACAN_Disconnect(handle);
    EmSACAN_Shutdown();
    return 0;
}

Minimal C# example

using EmSACAN;

EmSACANLibrary.Startup(enableExclusiveMode: false);
try
{
    var list = EmSACANLibrary.EnumerateInterfaces();
    if (list.Count == 0) return;

    using (CanDragonDevice device = CanDragonDevice.Connect(list[0].SerialNumber, false))
    {
        device.WriteChannelConfig(new EmSACANChannelConfig
        {
            Termination = EmSACANTermination.Term120,
            NominalKbps = 500,
            DataKbps = 2000
        }, channelNumber: 0);

        device.OpenChannel(0);
        device.Write(0, 0x123, new byte[] { 1, 2, 3, 4 });

        EmSACANMessage? msg = device.Read(0);
        if (msg.HasValue)
            Console.WriteLine($"RX 0x{msg.Value.Id:X} len={msg.Value.Length}");

        device.CloseChannel(0);
    }
}
finally
{
    EmSACANLibrary.Shutdown();
}

Next steps