ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 7. 채널 정보 출력(CAN_FD)
    C#/XL_Driver 2020. 2. 10. 17:14

    CAN_FD의 채널 정보를 포함하는 class 구조는 다음과 같습니다

     

    public class xl_channel_config
    {
       public string name;
       public string transceiverName;
       public uint articleNumber;
       public uint serialNumber;
       public uint[] raw_data;
       public XLDefine.XL_InterfaceVersion interfaceVersion;
       public uint driverVersion;
       public xl_bus_params busParams;
       public XLDefine.XL_BusTypes connectedBusType;
       public uint[] reserved;
       public byte isOnBus;
       public XLDefine.XL_ChannelCapabilities channelCapabilities;
       public ulong channelMask;
       public byte channelIndex;
       public XLDefine.XL_Transceiver_Status transceiverState;
       public XLDefine.XL_Transceiver_Types transceiverType;
       public byte hwChannel;
       public byte hwIndex;
       public XLDefine.XL_HardwareType hwType;
       public XLDefine.XL_BusCapabilities channelBusCapabilities;
       
       public xl_channel_config();
    }

     

     

    이들 중, define, class 혹은 struct, 배열 자료형을 제외한 나머지 값들을 출력하면 다음과 같다

     

    ※ 참고 : 연결된 장치는 VN1630A와 VN1640A 각 1개씩 입니다.

     

    출력 결과

     

    -------------------------------------------------------------------
                        xlCANFDdemo.NET C# V11.0
    Copyright (c) 2019 by Vector Informatik GmbH.  All rights reserved.
    -------------------------------------------------------------------
    
    vxlapi_NET        : 11.0.14.22309
    Open Driver       : XL_SUCCESS
    Get Driver Config : XL_SUCCESS
    DLL Version       : 11.0.14
    Channels found    : 12
    
                       [0] VN1630A Channel 1
                        - CAN FD Support  : yes
                        - Name              : VN1630A Channel 1
                        - Transciver Name   : CANpiggy 1055cap (Lowspeed)
                        - Article Number    : 7113
                        - Serial  Number    : 540600
                        - Interface Version : XL_INTERFACE_VERSION_V4
                        - Driver Version    : 168361996
                        - isOnBus           : 0
                        - Capabilities      : 3791683607
                        - Channel Mask      : 1
                        - Channel Index     : 0
                        - Hw Channel        : 0
                        - Hw Index          : 0
                        - Hw Type           : XL_HWTYPE_VN1630
    
                       [1] VN1630A Channel 2
                        - CAN FD Support  : yes
                        - Name              : VN1630A Channel 2
                        - Transciver Name   : On board CAN 1051cap(Highspeed)
                        - Article Number    : 7113
                        - Serial  Number    : 540600
                        - Interface Version : XL_INTERFACE_VERSION_V4
                        - Driver Version    : 168361996
                        - isOnBus           : 0
                        - Capabilities      : 3791683607
                        - Channel Mask      : 2
                        - Channel Index     : 1
                        - Hw Channel        : 1
                        - Hw Index          : 0
                        - Hw Type           : XL_HWTYPE_VN1630
    
                       [2] VN1630A Channel 3
                        - CAN FD Support  : yes
                        - Name              : VN1630A Channel 3
                        - Transciver Name   : On board CAN 1051cap(Highspeed)
                        - Article Number    : 7113
                        - Serial  Number    : 540600
                        - Interface Version : XL_INTERFACE_VERSION_V4
                        - Driver Version    : 168361996
                        - isOnBus           : 0
                        - Capabilities      : 3791683607
                        - Channel Mask      : 4
                        - Channel Index     : 2
                        - Hw Channel        : 2
                        - Hw Index          : 0
                        - Hw Type           : XL_HWTYPE_VN1630
    
                       [3] VN1630A Channel 4
                        - CAN FD Support  : no
                        - Name              : VN1630A Channel 4
                        - Transciver Name   :
                        - Article Number    : 7113
                        - Serial  Number    : 540600
                        - Interface Version : 0
                        - Driver Version    : 168361996
                        - isOnBus           : 0
                        - Capabilities      : 1073741831
                        - Channel Mask      : 8
                        - Channel Index     : 3
                        - Hw Channel        : 3
                        - Hw Index          : 0
                        - Hw Type           : XL_HWTYPE_VN1630
    
                       [4] VN1630A Channel 5
                        - CAN FD Support  : no
                        - Name              : VN1630A Channel 5
                        - Transciver Name   : On board D/A IO 1021
                        - Article Number    : 7113
                        - Serial  Number    : 540600
                        - Interface Version : XL_INTERFACE_VERSION_V3
                        - Driver Version    : 168361996
                        - isOnBus           : 0
                        - Capabilities      : 1073774599
                        - Channel Mask      : 16
                        - Channel Index     : 4
                        - Hw Channel        : 4
                        - Hw Index          : 0
                        - Hw Type           : XL_HWTYPE_VN1630
    
                       [5] VN1640A Channel 1
                        - CAN FD Support  : yes
                        - Name              : VN1640A Channel 1
                        - Transciver Name   : CANpiggy 1057Gcap (Highspeed)
                        - Article Number    : 7114
                        - Serial  Number    : 26638
                        - Interface Version : XL_INTERFACE_VERSION_V4
                        - Driver Version    : 168361996
                        - isOnBus           : 0
                        - Capabilities      : 3791683607
                        - Channel Mask      : 32
                        - Channel Index     : 5
                        - Hw Channel        : 0
                        - Hw Index          : 0
                        - Hw Type           : XL_HWTYPE_VN1640
    
                       [6] VN1640A Channel 2
                        - CAN FD Support  : yes
                        - Name              : VN1640A Channel 2
                        - Transciver Name   : CANpiggy 1057Gcap (Highspeed)
                        - Article Number    : 7114
                        - Serial  Number    : 26638
                        - Interface Version : XL_INTERFACE_VERSION_V4
                        - Driver Version    : 168361996
                        - isOnBus           : 0
                        - Capabilities      : 3791683607
                        - Channel Mask      : 64
                        - Channel Index     : 6
                        - Hw Channel        : 1
                        - Hw Index          : 0
                        - Hw Type           : XL_HWTYPE_VN1640
    
                       [7] VN1640A Channel 3
                        - CAN FD Support  : yes
                        - Name              : VN1640A Channel 3
                        - Transciver Name   : CANpiggy 1057Gcap (Highspeed)
                        - Article Number    : 7114
                        - Serial  Number    : 26638
                        - Interface Version : XL_INTERFACE_VERSION_V4
                        - Driver Version    : 168361996
                        - isOnBus           : 0
                        - Capabilities      : 3791683607
                        - Channel Mask      : 128
                        - Channel Index     : 7
                        - Hw Channel        : 2
                        - Hw Index          : 0
                        - Hw Type           : XL_HWTYPE_VN1640
    
                       [8] VN1640A Channel 4
                        - CAN FD Support  : yes
                        - Name              : VN1640A Channel 4
                        - Transciver Name   : CANpiggy 1057Gcap (Highspeed)
                        - Article Number    : 7114
                        - Serial  Number    : 26638
                        - Interface Version : XL_INTERFACE_VERSION_V4
                        - Driver Version    : 168361996
                        - isOnBus           : 0
                        - Capabilities      : 3791683607
                        - Channel Mask      : 256
                        - Channel Index     : 8
                        - Hw Channel        : 3
                        - Hw Index          : 0
                        - Hw Type           : XL_HWTYPE_VN1640
    
                       [9] VN1640A Channel 5
                        - CAN FD Support  : no
                        - Name              : VN1640A Channel 5
                        - Transciver Name   : On board D/A IO 1021
                        - Article Number    : 7114
                        - Serial  Number    : 26638
                        - Interface Version : XL_INTERFACE_VERSION_V3
                        - Driver Version    : 168361996
                        - isOnBus           : 0
                        - Capabilities      : 1073774599
                        - Channel Mask      : 512
                        - Channel Index     : 9
                        - Hw Channel        : 4
                        - Hw Index          : 0
                        - Hw Type           : XL_HWTYPE_VN1640
    
                       [10] Virtual Channel 1
                        - CAN FD Support  : yes
                        - Name              : Virtual Channel 1
                        - Transciver Name   :  Virtual CAN
                        - Article Number    : 0
                        - Serial  Number    : 0
                        - Interface Version : XL_INTERFACE_VERSION_V4
                        - Driver Version    : 184680464
                        - isOnBus           : 0
                        - Capabilities      : 2684354567
                        - Channel Mask      : 1024
                        - Channel Index     : 10
                        - Hw Channel        : 0
                        - Hw Index          : 0
                        - Hw Type           : XL_HWTYPE_VIRTUAL
    
                       [11] Virtual Channel 2
                        - CAN FD Support  : yes
                        - Name              : Virtual Channel 2
                        - Transciver Name   :  Virtual CAN
                        - Article Number    : 0
                        - Serial  Number    : 0
                        - Interface Version : XL_INTERFACE_VERSION_V4
                        - Driver Version    : 184680464
                        - isOnBus           : 0
                        - Capabilities      : 2684354567
                        - Channel Mask      : 2048
                        - Channel Index     : 11
                        - Hw Channel        : 1
                        - Hw Index          : 0
                        - Hw Type           : XL_HWTYPE_VIRTUAL
    
    
    APPLICATION CONFIGURATION
    -------------------------------------------------------------------
    Configured Hardware Channel : VN1640A Channel 2
    Hardware Driver Version     : 10.9.12
    Used Transceiver            : CANpiggy 1057Gcap (Highspeed)
    -------------------------------------------------------------------
    Configured Hardware Channel : VN1630A Channel 2
    Hardware Driver Version     : 10.9.12
    Used Transceiver            : On board CAN 1051cap(Highspeed)
    -------------------------------------------------------------------
    
    
    
    Open Port             : XL_SUCCESS
    
    
    Set CAN FD Config     : XL_SUCCESS
    Set Notification      : XL_SUCCESS
    Activate Channel      : XL_SUCCESS
    demoToggleTimerRate, xlSetTimerRate (timerRate:100000) result: XL_SUCCESS
    CAN FD mode           : ISO
    TX Arb. BitRate       : 1000000Bd, Data Bitrate: 2000000Bd
    Start Rx thread...
    Press <ENTER> to transmit CAN messages
      <b>, <ENTER> to block Rx thread for rx-overrun-test
      <B>, <ENTER> burst of CAN TX messages
      <x>, <ENTER> to exit
    

     

     

     

     

     

    위 출력 결과의 소스코드와 설정, 실행 환경은 다음과 같습니다.

     

     

    /*-------------------------------------------------------------------------------------------
    | File        : Class1.cs
    | Project     : Vector CAN FD .NET Example
    |
    | Description : This example demonstrates the basic CAN FD functionality of the XL.NET Driver Library
    |--------------------------------------------------------------------------------------------
    | Copyright (c) 2019 by Vector Informatik GmbH.  All rights reserved.
    |-------------------------------------------------------------------------------------------*/
    
    using System;
    using System.Runtime.InteropServices;
    using System.Threading;
    using vxlapi_NET;
    
    
    namespace xlCANDemo
    {
        /// <summary>
        /// Summary description for Class1.
        /// </summary>
        class Class1
        {
            // -----------------------------------------------------------------------------------------------
            // DLL Import for RX events
            // -----------------------------------------------------------------------------------------------
            [DllImport("kernel32.dll", SetLastError = true)]
            static extern int WaitForSingleObject(int handle, int timeOut);
            // -----------------------------------------------------------------------------------------------
    
    
    
    
            // -----------------------------------------------------------------------------------------------
            // Global variables
            // -----------------------------------------------------------------------------------------------
            // Driver access through XLDriver (wrapper)
            private static XLDriver CANDemo                 = new XLDriver();
            private static String appName                   = "xlCANdemoNET";
    
            // Driver configuration
            private static XLClass.xl_driver_config driverConfig = new XLClass.xl_driver_config();
    
            // Variables required by XLDriver
            private static XLDefine.XL_HardwareType hwType  = XLDefine.XL_HardwareType.XL_HWTYPE_NONE;
            private static uint hwIndex                     = 0;
            private static uint hwChannel                   = 0;   
            private static int portHandle                   = -1;
            private static int eventHandle                  = -1;
            private static UInt64 accessMask                = 0;
            private static UInt64 permissionMask            = 0;
            private static UInt64 txMask                    = 0;
            private static UInt64 rxMask                    = 0;
            private static int txCi                         = 0;
            private static int rxCi                         = 0;
    
    
            private static uint canFdModeNoIso              = 0;      // Global CAN FD ISO (default) / no ISO mode flag
    
            // RX thread
            private static Thread rxThread;
            private static bool blockRxThread = false; 
            // -----------------------------------------------------------------------------------------------
    
    
    
    
            // -----------------------------------------------------------------------------------------------
            /// <summary>
            /// MAIN
            /// 
            /// Sends and receives CAN FD messages using main methods of the "XLDriver" class.
            /// This demo requires two connected CAN channels (Vector network interface). 
            /// The configuration is read from Vector Hardware Config (vcanconf.exe).
            /// </summary>
            // -----------------------------------------------------------------------------------------------
            [STAThread]
            static int Main(string[] args)
            {
                XLDefine.XL_Status status;
    
                Console.WriteLine("-------------------------------------------------------------------");
                Console.WriteLine("                    xlCANFDdemo.NET C# V11.0                       ");
                Console.WriteLine("Copyright (c) 2019 by Vector Informatik GmbH.  All rights reserved.");
                Console.WriteLine("-------------------------------------------------------------------\n");
    
                // print .NET wrapper version
                Console.WriteLine("vxlapi_NET        : " + typeof(XLDriver).Assembly.GetName().Version);
    
                // Open XL Driver
                status = CANDemo.XL_OpenDriver();
                Console.WriteLine("Open Driver       : " + status);
                if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError();
    
    
                // Get XL Driver configuration
                status = CANDemo.XL_GetDriverConfig(ref driverConfig);
                Console.WriteLine("Get Driver Config : " + status);
                if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError();
    
                // Convert the dll version number into a readable string
                Console.WriteLine("DLL Version       : " + CANDemo.VersionToString(driverConfig.dllVersion));
    
                // Display channel count
                Console.WriteLine("Channels found    : " + driverConfig.channelCount);
    
    
                // Display all found channels
                for (int i = 0; i < driverConfig.channelCount; i++)
                {
                    Console.WriteLine("\n                   [{0}] " + driverConfig.channel[i].name, i);
    
                    if ((driverConfig.channel[i].channelCapabilities & XLDefine.XL_ChannelCapabilities.XL_CHANNEL_FLAG_CANFD_ISO_SUPPORT) == XLDefine.XL_ChannelCapabilities.XL_CHANNEL_FLAG_CANFD_ISO_SUPPORT)
                        Console.WriteLine("                    - CAN FD Support  : yes");
                    else Console.WriteLine("                    - CAN FD Support  : no");
    
                    Console.WriteLine("                    - Name              : " + driverConfig.channel[i].name);
                    Console.WriteLine("                    - Transciver Name   : " + driverConfig.channel[i].transceiverName);
                    Console.WriteLine("                    - Article Number    : " + driverConfig.channel[i].articleNumber);
                    Console.WriteLine("                    - Serial  Number    : " + driverConfig.channel[i].serialNumber);
                    Console.WriteLine("                    - Interface Version : " + driverConfig.channel[i].interfaceVersion);
                    Console.WriteLine("                    - Driver Version    : " + driverConfig.channel[i].driverVersion);
                    Console.WriteLine("                    - isOnBus           : " + driverConfig.channel[i].isOnBus);
                    Console.WriteLine("                    - Capabilities      : " + driverConfig.channel[i].channelCapabilities);
                    Console.WriteLine("                    - Channel Mask      : " + driverConfig.channel[i].channelMask);
                    Console.WriteLine("                    - Channel Index     : " + driverConfig.channel[i].channelIndex);
                    Console.WriteLine("                    - Hw Channel        : " + driverConfig.channel[i].hwChannel);
                    Console.WriteLine("                    - Hw Index          : " + driverConfig.channel[i].hwIndex);
                    Console.WriteLine("                    - Hw Type           : " + driverConfig.channel[i].hwType);
                }
    
                // If the application name cannot be found in VCANCONF...
                if ((CANDemo.XL_GetApplConfig(appName, 0, ref hwType, ref hwIndex, ref hwChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN) != XLDefine.XL_Status.XL_SUCCESS) ||
                    (CANDemo.XL_GetApplConfig(appName, 1, ref hwType, ref hwIndex, ref hwChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN) != XLDefine.XL_Status.XL_SUCCESS))
                {
                    //...create the item with two CAN channels
                    CANDemo.XL_SetApplConfig(appName, 0, XLDefine.XL_HardwareType.XL_HWTYPE_NONE, 0, 0, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN);
                    CANDemo.XL_SetApplConfig(appName, 1, XLDefine.XL_HardwareType.XL_HWTYPE_NONE, 0, 0, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN);
                    PrintAssignErrorAndPopupHwConf();
                }
    
                // Request the user to assign channels until both CAN1 (Tx) and CAN2 (Rx) are assigned to usable channels
                while (!GetAppChannelAndTestIsOk(0, ref txMask, ref txCi) || !GetAppChannelAndTestIsOk(1, ref rxMask, ref rxCi))
                {
                    PrintAssignErrorAndPopupHwConf();
                }
    
                PrintConfig();
    
                accessMask = txMask | rxMask;
                permissionMask = accessMask;
    
                // --------------------
                // Open port
                // --------------------
                status = CANDemo.XL_OpenPort(ref portHandle, appName, accessMask, ref permissionMask, 16000, XLDefine.XL_InterfaceVersion.XL_INTERFACE_VERSION_V4, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN);
                Console.WriteLine("\n\nOpen Port             : " + status);
                if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError();
    
                // --------------------
                // Set CAN FD config
                // --------------------
                XLClass.XLcanFdConf canFdConf   = new XLClass.XLcanFdConf();
    
                // arbitration bitrate
                canFdConf.arbitrationBitRate    = 1000000;
                canFdConf.tseg1Abr              = 6;
                canFdConf.tseg2Abr              = 3;
                canFdConf.sjwAbr                = 2;
    
                // data bitrate
                canFdConf.dataBitRate           = canFdConf.arbitrationBitRate * 2;
                canFdConf.tseg1Dbr              = 6;
                canFdConf.tseg2Dbr              = 3;
                canFdConf.sjwDbr                = 2;
    
                if (canFdModeNoIso > 0)
                {
                    canFdConf.options = (byte)XLDefine.XL_CANFD_ConfigOptions.XL_CANFD_CONFOPT_NO_ISO;
                }
                else
                {
                    canFdConf.options = 0;
                }
    
                status = CANDemo.XL_CanFdSetConfiguration(portHandle, accessMask, canFdConf);
                Console.WriteLine("\n\nSet CAN FD Config     : " + status);
                if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError();
    
                // Get RX event handle
                status = CANDemo.XL_SetNotification(portHandle, ref eventHandle, 1);
                Console.WriteLine("Set Notification      : " + status);
                if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError();
    
                // Activate channel - with reset clock
                status = CANDemo.XL_ActivateChannel(portHandle, accessMask, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN, XLDefine.XL_AC_Flags.XL_ACTIVATE_RESET_CLOCK);
                Console.WriteLine("Activate Channel      : " + status);
                if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError();
    
                uint timer = 100000;
                //status = CANDemo.XL_SetTimerRate(portHandle, timer);
                //Console.WriteLine("Timer Set             : " + status);
                //if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError();
    
    
                // Get XL Driver configuration to get the actual setup parameter
                status = CANDemo.XL_GetDriverConfig(ref driverConfig);
                Console.WriteLine("demoToggleTimerRate, xlSetTimerRate (timerRate:{0}) result: {1}", timer, CANDemo.XL_GetErrorString(status));
    
                if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError();
    
                if (canFdModeNoIso > 0)
                {
                    Console.WriteLine("CAN FD mode           : NO ISO");
                }
                else
                {
                    Console.WriteLine("CAN FD mode           : ISO");
                }
                Console.WriteLine("TX Arb. BitRate       : " + driverConfig.channel[txCi].busParams.dataCanFd.arbitrationBitRate
                                + "Bd, Data Bitrate: " + driverConfig.channel[txCi].busParams.dataCanFd.dataBitRate + "Bd");
    
                // Run Rx thread
                Console.WriteLine("Start Rx thread...");
                rxThread = new Thread(new ThreadStart(RXThread));
                rxThread.Start();
    
                // User information
                Console.WriteLine("Press <ENTER> to transmit CAN messages \n  <b>, <ENTER> to block Rx thread for rx-overrun-test \n  <B>, <ENTER> burst of CAN TX messages \n  <x>, <ENTER> to exit");
    
                // Transmit CAN data
                while (true)
                {
                    if (blockRxThread)Console.WriteLine("Rx thread blocked.");
    
                        
                    // Read user input
                    string str = Console.ReadLine();
                    if (str == "b")blockRxThread = !blockRxThread;                        
                    else if (str == "B")
                    {
                        for (int i = 0; i < 1000; i++)
                        {
                            // Burst of CAN frames
                            CANFDTransmitDemo();
                        }
                    }
                    else if (str == "x") break; 
                    else
                    {
                        // Send CAN frames
                        CANFDTransmitDemo();
                    }
                }
    
                // Kill Rx thread
                rxThread.Abort();
                Console.WriteLine("Close Port                     : " + CANDemo.XL_ClosePort(portHandle));
                Console.WriteLine("Close Driver                   : " + CANDemo.XL_CloseDriver());
    
    
                return 0;
            }
            // -----------------------------------------------------------------------------------------------
    
    
    
    
            // -----------------------------------------------------------------------------------------------
            /// <summary>
            /// Error message/exit in case of a functional call does not return XL_SUCCESS
            /// </summary>
            // -----------------------------------------------------------------------------------------------
            private static int PrintFunctionError()
            {
                Console.WriteLine("\nERROR: Function call failed!\nPress any key to continue...");
                Console.ReadKey();
                return -1;
            }
            // -----------------------------------------------------------------------------------------------
    
    
    
    
            // -----------------------------------------------------------------------------------------------
            /// <summary>
            /// Displays the Vector Hardware Configuration.
            /// </summary>
            // -----------------------------------------------------------------------------------------------
            private static void PrintConfig()
            {
                Console.WriteLine("\n\nAPPLICATION CONFIGURATION");
    
                foreach (int channelIndex in new int[] { txCi, rxCi })
                {
                    Console.WriteLine("-------------------------------------------------------------------");
                    Console.WriteLine("Configured Hardware Channel : " + driverConfig.channel[channelIndex].name);
                    Console.WriteLine("Hardware Driver Version     : " + CANDemo.VersionToString(driverConfig.channel[channelIndex].driverVersion));
                    Console.WriteLine("Used Transceiver            : " + driverConfig.channel[channelIndex].transceiverName);
                }
    
                Console.WriteLine("-------------------------------------------------------------------\n");
            }
            // -----------------------------------------------------------------------------------------------
    
    
    
    
            // -----------------------------------------------------------------------------------------------
            /// <summary>
            /// Error message if channel assignment is not valid.
            /// </summary>
            // -----------------------------------------------------------------------------------------------
            private static void PrintAssignErrorAndPopupHwConf()
            {
                Console.WriteLine("\nPlease check application settings of \"" + appName + " CAN1/CAN2\",\nassign it to available hardware channels and press enter.");
                CANDemo.XL_PopupHwConfig();
                Console.ReadKey();
            }
            // -----------------------------------------------------------------------------------------------
    
    
            // -----------------------------------------------------------------------------------------------
            /// <summary>
            /// Retrieve the application channel assignment and test if this channel can be opened
            /// </summary>
            // -----------------------------------------------------------------------------------------------
            private static bool GetAppChannelAndTestIsOk(uint appChIdx, ref UInt64 chMask, ref int chIdx)
            {
                XLDefine.XL_Status status = CANDemo.XL_GetApplConfig(appName, appChIdx, ref hwType, ref hwIndex, ref hwChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN);
                if (status != XLDefine.XL_Status.XL_SUCCESS)
                {
                    Console.WriteLine("XL_GetApplConfig      : " + status);
                    PrintFunctionError();
                }
    
                chMask = CANDemo.XL_GetChannelMask(hwType, (int)hwIndex, (int)hwChannel);
                chIdx = CANDemo.XL_GetChannelIndex(hwType, (int)hwIndex, (int)hwChannel);
                if (chIdx < 0 || chIdx >= driverConfig.channelCount)
                {
                    // the (hwType, hwIndex, hwChannel) triplet stored in the application configuration does not refer to any available channel.
                    return false;
                }
    
                if ((driverConfig.channel[chIdx].channelBusCapabilities & XLDefine.XL_BusCapabilities.XL_BUS_ACTIVE_CAP_CAN) == 0)
                {
                    // CAN is not available on this channel
                    return false;
                }
    
                if (canFdModeNoIso > 0)
                {
                    if ((driverConfig.channel[chIdx].channelCapabilities & XLDefine.XL_ChannelCapabilities.XL_CHANNEL_FLAG_CANFD_BOSCH_SUPPORT) == 0)
                    {
                        Console.WriteLine("{0} ({1}) does not support CAN FD NO-ISO", driverConfig.channel[chIdx].name.TrimEnd(' ', '\0'),
                            driverConfig.channel[chIdx].transceiverName.TrimEnd(' ', '\0'));
                        return false;
                    }
                }
                else
                {
                    if ((driverConfig.channel[chIdx].channelCapabilities & XLDefine.XL_ChannelCapabilities.XL_CHANNEL_FLAG_CANFD_ISO_SUPPORT) == 0)
                    {
                        Console.WriteLine("{0} ({1}) does not support CAN FD ISO", driverConfig.channel[chIdx].name.TrimEnd(' ', '\0'),
                            driverConfig.channel[chIdx].transceiverName.TrimEnd(' ', '\0'));
                        return false;
                    }
                }
    
                return true;
            }
            // -----------------------------------------------------------------------------------------------
    
    
            // -----------------------------------------------------------------------------------------------
            /// <summary>
            /// Sends some CAN messages.
            /// </summary>
            // ----------------------------------------------------------------------------------------------- 
            public static void CANFDTransmitDemo()
            {
                XLDefine.XL_Status txStatus;
                
                // Create an event collection with 2 messages (events)
                XLClass.xl_canfd_event_collection xlEventCollection = new XLClass.xl_canfd_event_collection(1);
    
                // event 1
                xlEventCollection.xlCANFDEvent[0].tag               = XLDefine.XL_CANFD_TX_EventTags.XL_CAN_EV_TAG_TX_MSG;
                xlEventCollection.xlCANFDEvent[0].tagData.canId     = 0x100;
                xlEventCollection.xlCANFDEvent[0].tagData.dlc       = XLDefine.XL_CANFD_DLC.DLC_CAN_CANFD_8_BYTES;
                xlEventCollection.xlCANFDEvent[0].tagData.msgFlags  = XLDefine.XL_CANFD_TX_MessageFlags.XL_CAN_TXMSG_FLAG_BRS | XLDefine.XL_CANFD_TX_MessageFlags.XL_CAN_TXMSG_FLAG_EDL;
                xlEventCollection.xlCANFDEvent[0].tagData.data[0]   = 1;
                xlEventCollection.xlCANFDEvent[0].tagData.data[1]   = 1;
                xlEventCollection.xlCANFDEvent[0].tagData.data[2]   = 2;
                xlEventCollection.xlCANFDEvent[0].tagData.data[3]   = 2;
                xlEventCollection.xlCANFDEvent[0].tagData.data[4]   = 3;
                xlEventCollection.xlCANFDEvent[0].tagData.data[5]   = 3;
                xlEventCollection.xlCANFDEvent[0].tagData.data[6]   = 4;
                xlEventCollection.xlCANFDEvent[0].tagData.data[7]   = 4;
    
    
                //// event 2
                //xlEventCollection.xlCANFDEvent[1].tag               = XLDefine.XL_CANFD_TX_EventTags.XL_CAN_EV_TAG_TX_MSG;
                //xlEventCollection.xlCANFDEvent[1].tagData.canId     = 0x200;
                //xlEventCollection.xlCANFDEvent[1].tagData.dlc       = XLDefine.XL_CANFD_DLC.DLC_CANFD_64_BYTES;
                //xlEventCollection.xlCANFDEvent[1].tagData.msgFlags  = XLDefine.XL_CANFD_TX_MessageFlags.XL_CAN_TXMSG_FLAG_BRS | XLDefine.XL_CANFD_TX_MessageFlags.XL_CAN_TXMSG_FLAG_EDL;
                //xlEventCollection.xlCANFDEvent[1].tagData.data[0]   = 7;
                //xlEventCollection.xlCANFDEvent[1].tagData.data[1]   = 7;
                //xlEventCollection.xlCANFDEvent[1].tagData.data[2]   = 8;
                //xlEventCollection.xlCANFDEvent[1].tagData.data[3]   = 8;
                //xlEventCollection.xlCANFDEvent[1].tagData.data[4]   = 9;
                //xlEventCollection.xlCANFDEvent[1].tagData.data[5]   = 9;
                //xlEventCollection.xlCANFDEvent[1].tagData.data[6]   = 3;
                //xlEventCollection.xlCANFDEvent[1].tagData.data[7]   = 2;
                //xlEventCollection.xlCANFDEvent[1].tagData.data[8]   = 1;
                //xlEventCollection.xlCANFDEvent[1].tagData.data[63]  = 9;
    
    
                for (int i = 0; i < 10; i++)
                {
                    // Transmit events
                    uint messageCounterSent = 0;
                    txStatus = CANDemo.XL_CanTransmitEx(portHandle, txMask, ref messageCounterSent, xlEventCollection);
                    Console.WriteLine("Transmit Message ({0})     : " + txStatus, messageCounterSent);
                }
            }
            // -----------------------------------------------------------------------------------------------
    
    
    
    
            // -----------------------------------------------------------------------------------------------
            /// <summary>
            /// EVENT THREAD (RX)
            /// 
            /// RX thread waits for Vector interface events and displays filtered CAN messages.
            /// </summary>
            // ----------------------------------------------------------------------------------------------- 
            public static void RXThread()
            {
                // Create new object containing received data 
                XLClass.XLcanRxEvent receivedEvent = new XLClass.XLcanRxEvent();
    
                // Result of XL Driver function calls
                XLDefine.XL_Status xlStatus = XLDefine.XL_Status.XL_SUCCESS;
    
                // Result values of WaitForSingleObject 
                XLDefine.WaitResults waitResult = new XLDefine.WaitResults();
    
    
                // Note: this thread will be destroyed by MAIN
                while (true)
                {
                    // Wait for hardware events
                    waitResult = (XLDefine.WaitResults)WaitForSingleObject(eventHandle, 1000);
    
                    // If event occurred...
                    if (waitResult != XLDefine.WaitResults.WAIT_TIMEOUT)
                    {
                        // ...init xlStatus first
                        xlStatus = XLDefine.XL_Status.XL_SUCCESS;
    
                        // afterwards: while hw queue is not empty...
                        while (xlStatus != XLDefine.XL_Status.XL_ERR_QUEUE_IS_EMPTY)
                        {
                            // ...block RX thread to generate RX-Queue overflows
                            while (blockRxThread) Thread.Sleep(1000);
    
                            // ...receive data from hardware.
                            xlStatus = CANDemo.XL_CanReceive(portHandle, ref receivedEvent);
    
                            //  If receiving succeed....
                            if (xlStatus == XLDefine.XL_Status.XL_SUCCESS)
                            {
                                Console.WriteLine(CANDemo.XL_CanGetEventString(receivedEvent));
                            }
                        }
                    }
                    // No event occurred
                }
            }
            // -----------------------------------------------------------------------------------------------
        }
    }
    

     

     

     

    Vector Hardware Configuration 설정값

     

     

    VN1630A, VN1640A

     

    두 기기는 각각 채널2에 연결된 모습을 볼 수 있습니다.

    'C# > XL_Driver' 카테고리의 다른 글

    BRS, ISO 값 설정하기  (1) 2020.02.19
    TODO  (0) 2020.02.10
    6. 채널 정보 출력 2 ☆보완필요☆  (0) 2020.02.05
    5. 채널 정보 출력  (0) 2020.02.05
    4. channelCount  (0) 2020.02.05
Designed by Tistory.