ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 5. 채널 정보 출력
    C#/XL_Driver 2020. 2. 5. 16:55

    앞서 보여드린 4번 게시글의 예제에서 채널의 개수를 확인하는 코드를 보았습니다.

     

    이번 게시글에서는 7개 채널들 각각의 정보를 출력하는 방법을 알아보겠습니다.

     

    우선 driverConfig 클래스의 형태를 알아야 합니다. 구성요소는 아래와 같습니다.

     


    (참고) class XLClass 내부에 선언되었습니다

     

    public class xl_driver_config 구조

    public class xl_driver_config
    {
    	public uint dllVersion;
    	public uint channelCount;
    	public uint[] reserved;
    	public xl_channel_config[] channel;
    
    	public xl_driver_config();
    }

     

     

     

    위 클래스에서 xl_channel_config 구조를 살펴보면 다음과 같습니다

     

    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();
            }

     

    배열로 선언된 위 구조는 해당 채널의 정보를 포함하고 있습니다.

     

     

     

     

    다시 예제로 돌아와서 각 채널들의 정보를 출력해보겠습니다.

     

    xl_channel_coxl_driver_config 클래스의 xl_channel_config 클래스로 선언된

    channel 변수의 멤버변수들을 접근하면 됩니다.


    예제 코드

     

    using System;
    using System.Threading;
    using Microsoft.Win32.SafeHandles;
    using vxlapi_NET;
    
    namespace XLpractice
    {
        class Class1
        {
            // Driver access through XLDriver (wrapper)
            private static XLDriver CANDemo = new XLDriver();
    
            // Driver configuration
            private static XLClass.xl_driver_config driverConfig = new XLClass.xl_driver_config();
    
    
            [STAThread]
            static int Main(string[] args)
            {
                XLDefine.XL_Status status;
    
                Console.WriteLine("-------------------------------------------------------------------");
                Console.WriteLine("                     xlCANdemo.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();
    
                // 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);
                    Console.WriteLine("  - Channel Mask    : " + driverConfig.channel[i].channelMask);
                    Console.WriteLine("  - Transceiver Name: " + driverConfig.channel[i].transceiverName);
                    Console.WriteLine("  - Serial Number   : " + driverConfig.channel[i].serialNumber);
                    Console.WriteLine("  - hwtype          : " + driverConfig.channel[i].hwType);
                    Console.WriteLine("  - hwIndex         : " + driverConfig.channel[i].hwIndex);
                    Console.WriteLine("  - hwChannel       : " + driverConfig.channel[i].hwChannel);
                    Console.WriteLine("  - Channel Index   : " + driverConfig.channel[i].channelIndex);
                }
    
                return 0;
            }
    
            private static int PrintFunctionError()
            {
                Console.WriteLine("\nERROR: Function call failed!\nPress any key to continue...");
                Console.ReadKey();
                return -1;
            }
        }
    }
    

     

    앞서 말씀드린 클래스 구조의 channel 변수의 모든 배열을 반복문으로 접근하여

    각각의 멤버변수에 접근하는것을 볼 수 있습니다.

     

     


    출력 결과

     

    -------------------------------------------------------------------
                         xlCANdemo.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
    Channels found    : 7
    
                       [0] VN1640A Channel 1
                        - Channel Mask    : 1
                        - Transceiver Name: CANpiggy 1057Gcap (Highspeed)
                        - Serial Number   : 26638
                        - hwtype          : XL_HWTYPE_VN1640
                        - hwIndex         : 0
                        - hwChannel       : 0
                        - Channel Index   : 0
    
                       [1] VN1640A Channel 2
                        - Channel Mask    : 2
                        - Transceiver Name: CANpiggy 1057Gcap (Highspeed)
                        - Serial Number   : 26638
                        - hwtype          : XL_HWTYPE_VN1640
                        - hwIndex         : 0
                        - hwChannel       : 1
                        - Channel Index   : 1
    
                       [2] VN1640A Channel 3
                        - Channel Mask    : 4
                        - Transceiver Name: CANpiggy 1057Gcap (Highspeed)
                        - Serial Number   : 26638
                        - hwtype          : XL_HWTYPE_VN1640
                        - hwIndex         : 0
                        - hwChannel       : 2
                        - Channel Index   : 2
    
                       [3] VN1640A Channel 4
                        - Channel Mask    : 8
                        - Transceiver Name: CANpiggy 1057Gcap (Highspeed)
                        - Serial Number   : 26638
                        - hwtype          : XL_HWTYPE_VN1640
                        - hwIndex         : 0
                        - hwChannel       : 3
                        - Channel Index   : 3
    
                       [4] VN1640A Channel 5
                        - Channel Mask    : 16
                        - Transceiver Name: On board D/A IO 1021
                        - Serial Number   : 26638
                        - hwtype          : XL_HWTYPE_VN1640
                        - hwIndex         : 0
                        - hwChannel       : 4
                        - Channel Index   : 4
    
                       [5] Virtual Channel 1
                        - Channel Mask    : 32
                        - Transceiver Name:  Virtual CAN
                        - Serial Number   : 0
                        - hwtype          : XL_HWTYPE_VIRTUAL
                        - hwIndex         : 0
                        - hwChannel       : 0
                        - Channel Index   : 5
    
                       [6] Virtual Channel 2
                        - Channel Mask    : 64
                        - Transceiver Name:  Virtual CAN
                        - Serial Number   : 0
                        - hwtype          : XL_HWTYPE_VIRTUAL
                        - hwIndex         : 0
                        - hwChannel       : 1
                        - Channel Index   : 6
    계속하려면 아무 키나 누르십시오 . . .

     

    위 출력결과에서 물리채널들의 Serial Number 들과 각 채널들의 Mask 값과 정보들을 볼 수 있습니다.

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

    7. 채널 정보 출력(CAN_FD)  (0) 2020.02.10
    6. 채널 정보 출력 2 ☆보완필요☆  (0) 2020.02.05
    4. channelCount  (0) 2020.02.05
    3. dllVersion  (0) 2020.02.05
    2. OpenDriver, GetDriverConfig  (0) 2020.02.05
Designed by Tistory.