Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 50.83 KB | None | 0 0
  1. //  PCANBasic.cs
  2. //
  3. //  ~~~~~~~~~~~~
  4. //
  5. //  PCAN-Basic API
  6. //
  7. //  ~~~~~~~~~~~~
  8. //
  9. //  ------------------------------------------------------------------
  10. //  Author : Keneth Wagner
  11. //  Last change: 13.11.2017 Wagner
  12. //
  13. //  Language: C# 1.0
  14. //  ------------------------------------------------------------------
  15. //
  16. //  Copyright (C) 1999-2017  PEAK-System Technik GmbH, Darmstadt
  17. //  more Info at http://www.peak-system.com
  18. //
  19. using System;
  20. using System.Text;
  21. using System.Runtime.InteropServices;
  22.  
  23. namespace Peak.Can.Basic
  24. {    
  25.     using TPCANHandle = System.UInt16;    
  26.     using TPCANBitrateFD = System.String;
  27.     using TPCANTimestampFD = System.UInt64;
  28.    
  29.     #region Enumerations
  30.     /// <summary>
  31.     /// Represents a PCAN status/error code
  32.     /// </summary>
  33.     [Flags]
  34.     public enum TPCANStatus : uint
  35.     {
  36.         /// <summary>
  37.         /// No error
  38.         /// </summary>
  39.         PCAN_ERROR_OK           = 0x00000,
  40.         /// <summary>
  41.         /// Transmit buffer in CAN controller is full
  42.         /// </summary>
  43.         PCAN_ERROR_XMTFULL      = 0x00001,
  44.         /// <summary>
  45.         /// CAN controller was read too late        
  46.         /// </summary>
  47.         PCAN_ERROR_OVERRUN      = 0x00002,  
  48.         /// <summary>
  49.         /// Bus error: an error counter reached the 'light' limit
  50.         /// </summary>
  51.         PCAN_ERROR_BUSLIGHT     = 0x00004,  
  52.         /// <summary>
  53.         /// Bus error: an error counter reached the 'heavy' limit
  54.         /// </summary>
  55.         PCAN_ERROR_BUSHEAVY     = 0x00008,  
  56.         /// <summary>
  57.         /// Bus error: an error counter reached the 'warning' limit
  58.         /// </summary>
  59.         PCAN_ERROR_BUSWARNING   = PCAN_ERROR_BUSHEAVY,
  60.         /// <summary>
  61.         /// Bus error: the CAN controller is error passive
  62.         /// </summary>
  63.         PCAN_ERROR_BUSPASSIVE   = 0x40000,     
  64.         /// <summary>
  65.         /// Bus error: the CAN controller is in bus-off state
  66.         /// </summary>
  67.         PCAN_ERROR_BUSOFF       = 0x00010,  
  68.         /// <summary>
  69.         /// Mask for all bus errors
  70.         /// </summary>
  71.         PCAN_ERROR_ANYBUSERR = (PCAN_ERROR_BUSWARNING | PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF | PCAN_ERROR_BUSPASSIVE),
  72.         /// <summary>
  73.         /// Receive queue is empty
  74.         /// </summary>
  75.         PCAN_ERROR_QRCVEMPTY    = 0x00020,  
  76.         /// <summary>
  77.         /// Receive queue was read too late
  78.         /// </summary>
  79.         PCAN_ERROR_QOVERRUN     = 0x00040,  
  80.         /// <summary>
  81.         /// Transmit queue is full
  82.         /// </summary>
  83.         PCAN_ERROR_QXMTFULL     = 0x00080,  
  84.         /// <summary>
  85.         /// Test of the CAN controller hardware registers failed (no hardware found)
  86.         /// </summary>
  87.         PCAN_ERROR_REGTEST      = 0x00100,
  88.         /// <summary>
  89.         /// Driver not loaded
  90.         /// </summary>
  91.         PCAN_ERROR_NODRIVER     = 0x00200,
  92.         /// <summary>
  93.         /// Hardware already in use by a Net
  94.         /// </summary>
  95.         PCAN_ERROR_HWINUSE      = 0x00400,
  96.         /// <summary>
  97.         /// A Client is already connected to the Net
  98.         /// </summary>
  99.         PCAN_ERROR_NETINUSE     = 0x00800,
  100.         /// <summary>
  101.         /// Hardware handle is invalid
  102.         /// </summary>
  103.         PCAN_ERROR_ILLHW        = 0x01400,
  104.         /// <summary>
  105.         /// Net handle is invalid
  106.         /// </summary>
  107.         PCAN_ERROR_ILLNET       = 0x01800,
  108.         /// <summary>
  109.         /// Client handle is invalid
  110.         /// </summary>
  111.         PCAN_ERROR_ILLCLIENT    = 0x01C00,
  112.         /// <summary>
  113.         /// Mask for all handle errors
  114.         /// </summary>
  115.         PCAN_ERROR_ILLHANDLE    = (PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT),
  116.         /// <summary>
  117.         /// Resource (FIFO, Client, timeout) cannot be created
  118.         /// </summary>
  119.         PCAN_ERROR_RESOURCE     = 0x02000,
  120.         /// <summary>
  121.         /// Invalid parameter
  122.         /// </summary>
  123.         PCAN_ERROR_ILLPARAMTYPE = 0x04000,
  124.         /// <summary>
  125.         /// Invalid parameter value
  126.         /// </summary>
  127.         PCAN_ERROR_ILLPARAMVAL  = 0x08000,
  128.         /// <summary>
  129.         /// Unknown error
  130.         /// </summary>
  131.         PCAN_ERROR_UNKNOWN      = 0x10000,
  132.         /// <summary>
  133.         /// Invalid data, function, or action.
  134.         /// </summary>
  135.         PCAN_ERROR_ILLDATA      = 0x20000,
  136.         /// <summary>
  137.         /// An operation was successfully carried out, however, irregularities were registered
  138.         /// </summary>
  139.         PCAN_ERROR_CAUTION = 0x2000000,
  140.         /// <summary>
  141.         /// Channel is not initialized
  142.         /// <remarks>Value was changed from 0x40000 to 0x4000000</remarks>
  143.         /// </summary>
  144.         PCAN_ERROR_INITIALIZE = 0x4000000,
  145.         /// <summary>
  146.         /// Invalid operation
  147.         /// <remarks>Value was changed from 0x80000 to 0x8000000</remarks>
  148.         /// </summary>
  149.         PCAN_ERROR_ILLOPERATION = 0x8000000,
  150.     }
  151.  
  152.     /// <summary>
  153.     /// Represents a PCAN device
  154.     /// </summary>
  155.     public enum TPCANDevice : byte
  156.     {
  157.         /// <summary>
  158.         /// Undefined, unknown or not selected PCAN device value
  159.         /// </summary>
  160.         PCAN_NONE = 0,
  161.         /// <summary>
  162.         /// PCAN Non-Plug and Play devices. NOT USED WITHIN PCAN-Basic API
  163.         /// </summary>
  164.         PCAN_PEAKCAN = 1,
  165.         /// <summary>
  166.         /// PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus
  167.         /// </summary>
  168.         PCAN_ISA = 2,
  169.         /// <summary>
  170.         /// PCAN-Dongle
  171.         /// </summary>
  172.         PCAN_DNG = 3,
  173.         /// <summary>
  174.         /// PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express
  175.         /// </summary>
  176.         PCAN_PCI = 4,
  177.         /// <summary>
  178.         /// PCAN-USB and PCAN-USB Pro
  179.         /// </summary>
  180.         PCAN_USB = 5,
  181.         /// <summary>
  182.         /// PCAN-PC Card
  183.         /// </summary>
  184.         PCAN_PCC = 6,
  185.         /// <summary>
  186.         /// PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API
  187.         /// </summary>
  188.         PCAN_VIRTUAL = 7,
  189.         /// <summary>
  190.         /// PCAN Gateway devices
  191.         /// </summary>
  192.         PCAN_LAN = 8
  193.     }
  194.  
  195.     /// <summary>
  196.     /// Represents a PCAN parameter to be read or set
  197.     /// </summary>
  198.     public enum TPCANParameter : byte
  199.     {
  200.         /// <summary>
  201.         /// PCAN-USB device number parameter
  202.         /// </summary>
  203.         PCAN_DEVICE_NUMBER       = 1,
  204.         /// <summary>
  205.         /// PCAN-PC Card 5-Volt power parameter
  206.         /// </summary>
  207.         PCAN_5VOLTS_POWER        = 2,
  208.         /// <summary>
  209.         /// PCAN receive event handler parameter
  210.         /// </summary>
  211.         PCAN_RECEIVE_EVENT       = 3,
  212.         /// <summary>
  213.         /// PCAN message filter parameter
  214.         /// </summary>
  215.         PCAN_MESSAGE_FILTER      = 4,
  216.         /// <summary>
  217.         /// PCAN-Basic API version parameter
  218.         /// </summary>
  219.         PCAN_API_VERSION         = 5,
  220.         /// <summary>
  221.         /// PCAN device channel version parameter
  222.         /// </summary>
  223.         PCAN_CHANNEL_VERSION     = 6,
  224.         /// <summary>
  225.         /// PCAN Reset-On-Busoff parameter
  226.         /// </summary>
  227.         PCAN_BUSOFF_AUTORESET    = 7,
  228.         /// <summary>
  229.         /// PCAN Listen-Only parameter
  230.         /// </summary>
  231.         PCAN_LISTEN_ONLY         = 8,
  232.         /// <summary>
  233.         /// Directory path for log files
  234.         /// </summary>
  235.         PCAN_LOG_LOCATION        = 9,
  236.         /// <summary>
  237.         /// Debug-Log activation status
  238.         /// </summary>
  239.         PCAN_LOG_STATUS          = 10,
  240.         /// <summary>
  241.         /// Configuration of the debugged information (LOG_FUNCTION_***)
  242.         /// </summary>
  243.         PCAN_LOG_CONFIGURE       = 11,
  244.         /// <summary>
  245.         /// Custom insertion of text into the log file
  246.         /// </summary>
  247.         PCAN_LOG_TEXT            = 12,
  248.         /// <summary>
  249.         /// Availability status of a PCAN-Channel
  250.         /// </summary>
  251.         PCAN_CHANNEL_CONDITION   = 13,
  252.         /// <summary>
  253.         /// PCAN hardware name parameter
  254.         /// </summary>
  255.         PCAN_HARDWARE_NAME       = 14,
  256.         /// <summary>
  257.         /// Message reception status of a PCAN-Channel
  258.         /// </summary>
  259.         PCAN_RECEIVE_STATUS      = 15,
  260.         /// <summary>
  261.         /// CAN-Controller number of a PCAN-Channel
  262.         /// </summary>
  263.         PCAN_CONTROLLER_NUMBER   = 16,
  264.         /// <summary>
  265.         /// Directory path for PCAN trace files
  266.         /// </summary>
  267.         PCAN_TRACE_LOCATION      = 17,
  268.         /// <summary>
  269.         /// CAN tracing activation status
  270.         /// </summary>
  271.         PCAN_TRACE_STATUS        = 18,
  272.         /// <summary>
  273.         /// Configuration of the maximum file size of a CAN trace
  274.         /// </summary>
  275.         PCAN_TRACE_SIZE          = 19,
  276.         /// <summary>
  277.         /// Configuration of the trace file storing mode (TRACE_FILE_***)
  278.         /// </summary>
  279.         PCAN_TRACE_CONFIGURE     = 20,
  280.         /// <summary>
  281.         /// Physical identification of a USB based PCAN-Channel by blinking its associated LED
  282.         /// </summary>
  283.         PCAN_CHANNEL_IDENTIFYING = 21,
  284.         /// <summary>
  285.         /// Capabilities of a PCAN device (FEATURE_***)
  286.         /// </summary>
  287.         PCAN_CHANNEL_FEATURES    = 22,
  288.         /// <summary>
  289.         /// Using of an existing bit rate (PCAN-View connected to a channel)
  290.         /// </summary>
  291.         PCAN_BITRATE_ADAPTING    = 23,
  292.         /// <summary>
  293.         /// Configured bit rate as Btr0Btr1 value
  294.         /// </summary>
  295.         PCAN_BITRATE_INFO        = 24,
  296.         /// <summary>
  297.         /// Configured bit rate as TPCANBitrateFD string
  298.         /// </summary>
  299.         PCAN_BITRATE_INFO_FD     = 25,
  300.         /// <summary>
  301.         /// Configured nominal CAN Bus speed as Bits per seconds
  302.         /// </summary>
  303.         PCAN_BUSSPEED_NOMINAL    = 26,  
  304.         /// <summary>
  305.         /// Configured CAN data speed as Bits per seconds
  306.         /// </summary>
  307.         PCAN_BUSSPEED_DATA       = 27,
  308.         /// <summary>
  309.         /// Remote address of a LAN channel as string in IPv4 format
  310.         /// </summary>
  311.         PCAN_IP_ADDRESS          = 28,
  312.         /// <summary>
  313.         /// Status of the Virtual PCAN-Gateway Service
  314.         /// </summary>
  315.         PCAN_LAN_SERVICE_STATUS  = 29,
  316.         /// <summary>
  317.         /// Status messages reception status within a PCAN-Channel
  318.         /// </summary>
  319.         PCAN_ALLOW_STATUS_FRAMES = 30,
  320.         /// <summary>
  321.         /// RTR messages reception status within a PCAN-Channel
  322.         /// </summary>
  323.         PCAN_ALLOW_RTR_FRAMES = 31,
  324.         /// <summary>
  325.         /// Error messages reception status within a PCAN-Channel
  326.         /// </summary>
  327.         PCAN_ALLOW_ERROR_FRAMES = 32,
  328.         /// <summary>
  329.         /// Delay, in microseconds, between sending frames
  330.         /// </summary>
  331.         PCAN_INTERFRAME_DELAY = 33,
  332.         /// <summary>
  333.         /// Filter over code and mask patterns for 11-Bit messages
  334.         /// </summary>
  335.         PCAN_ACCEPTANCE_FILTER_11BIT = 34,
  336.         /// <summary>
  337.         /// Filter over code and mask patterns for 29-Bit messages
  338.         /// </summary>
  339.         PCAN_ACCEPTANCE_FILTER_29BIT = 35,
  340.         /// <summary>
  341.         /// Output mode of 32 digital I/O pin of a PCAN-USB Chip. 1: Output-Active 0 : Output Inactive
  342.         /// </summary>
  343.         PCAN_IO_DIGITAL_CONFIGURATION = 36,
  344.         /// <summary>
  345.         /// Value assigned to a 32 digital I/O pins of a PCAN-USB Chip
  346.         /// </summary>
  347.         PCAN_IO_DIGITAL_VALUE = 37,
  348.         /// <summary>
  349.         /// Value assigned to a 32 digital I/O pins of a PCAN-USB Chip - Multiple digital I/O pins to 1 = High
  350.         /// </summary>
  351.         PCAN_IO_DIGITAL_SET = 38,
  352.         /// <summary>
  353.         /// Clear multiple digital I/O pins to 0
  354.         /// </summary>
  355.         PCAN_IO_DIGITAL_CLEAR = 39,
  356.         /// <summary>
  357.         /// Get value of a single analog input pin
  358.         /// </summary>
  359.         PCAN_IO_ANALOG_VALUE = 40,
  360.     }
  361.  
  362.     /// <summary>
  363.     /// Represents the type of a PCAN message
  364.     /// </summary>
  365.     [Flags]
  366.     public enum TPCANMessageType : byte
  367.     {
  368.         /// <summary>
  369.         /// The PCAN message is a CAN Standard Frame (11-bit identifier)
  370.         /// </summary>
  371.         PCAN_MESSAGE_STANDARD  = 0x00,
  372.         /// <summary>
  373.         /// The PCAN message is a CAN Remote-Transfer-Request Frame
  374.         /// </summary>
  375.         PCAN_MESSAGE_RTR       = 0x01,
  376.         /// <summary>
  377.         /// The PCAN message is a CAN Extended Frame (29-bit identifier)
  378.         /// </summary>
  379.         PCAN_MESSAGE_EXTENDED  = 0x02,
  380.         /// <summary>
  381.         /// The PCAN message represents a FD frame in terms of CiA Specs
  382.         /// </summary>
  383.         PCAN_MESSAGE_FD = 0x04,
  384.         /// <summary>
  385.         /// The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate)
  386.         /// </summary>
  387.         PCAN_MESSAGE_BRS = 0x08,
  388.         /// <summary>
  389.         /// The PCAN message represents a FD error state indicator(CAN FD transmitter was error active)
  390.         /// </summary>
  391.         PCAN_MESSAGE_ESI = 0x10,
  392.         /// <summary>
  393.         /// The PCAN message represents an error frame
  394.         /// </summary>
  395.         PCAN_MESSAGE_ERRFRAME = 0x40,
  396.         /// <summary>
  397.         /// The PCAN message represents a PCAN status message
  398.         /// </summary>
  399.         PCAN_MESSAGE_STATUS    = 0x80,
  400.     }
  401.  
  402.     /// <summary>
  403.     /// Represents a PCAN filter mode
  404.     /// </summary>
  405.     public enum TPCANMode : byte
  406.     {
  407.         /// <summary>
  408.         /// Mode is Standard (11-bit identifier)
  409.         /// </summary>
  410.         PCAN_MODE_STANDARD = TPCANMessageType.PCAN_MESSAGE_STANDARD,
  411.         /// <summary>
  412.         /// Mode is Extended (29-bit identifier)
  413.         /// </summary>
  414.         PCAN_MODE_EXTENDED = TPCANMessageType.PCAN_MESSAGE_EXTENDED,
  415.     }
  416.  
  417.     /// <summary>
  418.     /// Represents a PCAN Baud rate register value
  419.     /// </summary>
  420.     public enum TPCANBaudrate : ushort
  421.     {
  422.         /// <summary>
  423.         /// 1 MBit/s
  424.         /// </summary>
  425.         PCAN_BAUD_1M      = 0x0014,
  426.         /// <summary>
  427.         /// 800 KBit/s
  428.         /// </summary>
  429.         PCAN_BAUD_800K    = 0x0016,
  430.         /// <summary>
  431.         /// 500 kBit/s
  432.         /// </summary>
  433.         PCAN_BAUD_500K    = 0x001C,
  434.         /// <summary>
  435.         /// 250 kBit/s
  436.         /// </summary>
  437.         PCAN_BAUD_250K    = 0x011C,
  438.         /// <summary>
  439.         /// 125 kBit/s
  440.         /// </summary>
  441.         PCAN_BAUD_125K    = 0x031C,
  442.         /// <summary>
  443.         /// 100 kBit/s
  444.         /// </summary>
  445.         PCAN_BAUD_100K    = 0x432F,
  446.         /// <summary>
  447.         /// 95,238 KBit/s
  448.         /// </summary>
  449.         PCAN_BAUD_95K     = 0xC34E,
  450.         /// <summary>
  451.         /// 83,333 KBit/s
  452.         /// </summary>
  453.         PCAN_BAUD_83K     = 0x852B,
  454.         /// <summary>
  455.         /// 50 kBit/s
  456.         /// </summary>
  457.         PCAN_BAUD_50K     = 0x472F,
  458.         /// <summary>
  459.         /// 47,619 KBit/s
  460.         /// </summary>
  461.         PCAN_BAUD_47K     = 0x1414,
  462.         /// <summary>
  463.         /// 33,333 KBit/s
  464.         /// </summary>
  465.         PCAN_BAUD_33K     = 0x8B2F,
  466.         /// <summary>
  467.         /// 20 kBit/s
  468.         /// </summary>
  469.         PCAN_BAUD_20K     = 0x532F,
  470.         /// <summary>
  471.         /// 10 kBit/s
  472.         /// </summary>
  473.         PCAN_BAUD_10K     = 0x672F,
  474.         /// <summary>
  475.         /// 5 kBit/s
  476.         /// </summary>
  477.         PCAN_BAUD_5K      = 0x7F7F,
  478.     }
  479.  
  480.     /// <summary>
  481.     /// Represents the type of PCAN (non plug and play) hardware to be initialized
  482.     /// </summary>
  483.     public enum TPCANType : byte
  484.     {
  485.         /// <summary>
  486.         /// PCAN-ISA 82C200
  487.         /// </summary>
  488.         PCAN_TYPE_ISA           = 0x01,
  489.         /// <summary>
  490.         /// PCAN-ISA SJA1000
  491.         /// </summary>
  492.         PCAN_TYPE_ISA_SJA       = 0x09,
  493.         /// <summary>
  494.         /// PHYTEC ISA
  495.         /// </summary>
  496.         PCAN_TYPE_ISA_PHYTEC    = 0x04,
  497.         /// <summary>
  498.         /// PCAN-Dongle 82C200
  499.         /// </summary>
  500.         PCAN_TYPE_DNG           = 0x02,
  501.         /// <summary>
  502.         /// PCAN-Dongle EPP 82C200
  503.         /// </summary>
  504.         PCAN_TYPE_DNG_EPP       = 0x03,
  505.         /// <summary>
  506.         /// PCAN-Dongle SJA1000
  507.         /// </summary>
  508.         PCAN_TYPE_DNG_SJA       = 0x05,
  509.         /// <summary>
  510.         /// PCAN-Dongle EPP SJA1000
  511.         /// </summary>
  512.         PCAN_TYPE_DNG_SJA_EPP   = 0x06,
  513.     }
  514.     #endregion
  515.  
  516.     #region Structures
  517.     /// <summary>
  518.     /// Represents a PCAN message
  519.     /// </summary>
  520.     public struct TPCANMsg
  521.     {
  522.         /// <summary>
  523.         /// 11/29-bit message identifier
  524.         /// </summary>
  525.         public uint ID;
  526.         /// <summary>
  527.         /// Type of the message
  528.         /// </summary>
  529.         [MarshalAs(UnmanagedType.U1)]
  530.         public TPCANMessageType MSGTYPE;  
  531.         /// <summary>
  532.         /// Data Length Code of the message (0..8)
  533.         /// </summary>
  534.         public byte LEN;      
  535.         /// <summary>
  536.         /// Data of the message (DATA[0]..DATA[7])
  537.         /// </summary>
  538.         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
  539.         public byte[] DATA;  
  540.     }
  541.  
  542.     /// <summary>
  543.     /// Represents a timestamp of a received PCAN message.
  544.     /// Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow
  545.     /// </summary>
  546.     public struct TPCANTimestamp
  547.     {
  548.         /// <summary>
  549.         /// Base-value: milliseconds: 0.. 2^32-1
  550.         /// </summary>
  551.         public uint millis;            
  552.         /// <summary>
  553.         /// Roll-arounds of millis
  554.         /// </summary>
  555.         public ushort millis_overflow;  
  556.         /// <summary>
  557.         /// Microseconds: 0..999
  558.         /// </summary>
  559.         public ushort micros;
  560.     }
  561.  
  562.     /// <summary>
  563.     /// Represents a PCAN message from a FD capable hardware
  564.     /// </summary>
  565.     public struct TPCANMsgFD
  566.     {
  567.         /// <summary>
  568.         /// 11/29-bit message identifier
  569.         /// </summary>
  570.         public uint ID;
  571.         /// <summary>
  572.         /// Type of the message
  573.         /// </summary>
  574.         [MarshalAs(UnmanagedType.U1)]
  575.         public TPCANMessageType MSGTYPE;
  576.         /// <summary>
  577.         /// Data Length Code of the message (0..15)
  578.         /// </summary>
  579.         public byte DLC;
  580.         /// <summary>
  581.         /// Data of the message (DATA[0]..DATA[63])
  582.         /// </summary>
  583.         [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
  584.         public byte[] DATA;
  585.     }
  586.     #endregion
  587.  
  588.     #region PCANBasic class
  589.     /// <summary>
  590.     /// PCAN-Basic API class implementation
  591.     /// </summary>
  592.     public static class PCANBasic
  593.     {
  594.         #region PCAN-BUS Handles Definition
  595.         /// <summary>
  596.         /// Undefined/default value for a PCAN bus
  597.         /// </summary>
  598.         public const TPCANHandle PCAN_NONEBUS = 0x00;
  599.        
  600.         /// <summary>
  601.         /// PCAN-ISA interface, channel 1
  602.         /// </summary>
  603.         public const TPCANHandle PCAN_ISABUS1 = 0x21;
  604.         /// <summary>
  605.         /// PCAN-ISA interface, channel 2
  606.         /// </summary>
  607.         public const TPCANHandle PCAN_ISABUS2 = 0x22;
  608.         /// <summary>
  609.         /// PCAN-ISA interface, channel 3
  610.         /// </summary>
  611.         public const TPCANHandle PCAN_ISABUS3 = 0x23;
  612.         /// <summary>
  613.         /// PCAN-ISA interface, channel 4
  614.         /// </summary>
  615.         public const TPCANHandle PCAN_ISABUS4 = 0x24;
  616.         /// <summary>
  617.         /// PCAN-ISA interface, channel 5
  618.         /// </summary>
  619.         public const TPCANHandle PCAN_ISABUS5 = 0x25;
  620.         /// <summary>
  621.         /// PCAN-ISA interface, channel 6
  622.         /// </summary>
  623.         public const TPCANHandle PCAN_ISABUS6 = 0x26;
  624.         /// <summary>
  625.         /// PCAN-ISA interface, channel 7
  626.         /// </summary>
  627.         public const TPCANHandle PCAN_ISABUS7 = 0x27;
  628.         /// <summary>
  629.         /// PCAN-ISA interface, channel 8
  630.         /// </summary>
  631.         public const TPCANHandle PCAN_ISABUS8 = 0x28;
  632.        
  633.         /// <summary>
  634.         /// PPCAN-Dongle/LPT interface, channel 1
  635.         /// </summary>
  636.         public const TPCANHandle PCAN_DNGBUS1 = 0x31;
  637.  
  638.         /// <summary>
  639.         /// PCAN-PCI interface, channel 1
  640.         /// </summary>
  641.         public const TPCANHandle PCAN_PCIBUS1 = 0x41;
  642.         /// <summary>
  643.         /// PCAN-PCI interface, channel 2
  644.         /// </summary>
  645.         public const TPCANHandle PCAN_PCIBUS2 = 0x42;
  646.         /// <summary>
  647.         /// PCAN-PCI interface, channel 3
  648.         /// </summary>
  649.         public const TPCANHandle PCAN_PCIBUS3 = 0x43;
  650.         /// <summary>
  651.         /// PCAN-PCI interface, channel 4
  652.         /// </summary>
  653.         public const TPCANHandle PCAN_PCIBUS4 = 0x44;
  654.         /// <summary>
  655.         /// PCAN-PCI interface, channel 5
  656.         /// </summary>
  657.         public const TPCANHandle PCAN_PCIBUS5 = 0x45;
  658.         /// <summary>
  659.         /// PCAN-PCI interface, channel 6
  660.         /// </summary>
  661.         public const TPCANHandle PCAN_PCIBUS6 = 0x46;
  662.         /// <summary>
  663.         /// PCAN-PCI interface, channel 7
  664.         /// </summary>
  665.         public const TPCANHandle PCAN_PCIBUS7 = 0x47;
  666.         /// <summary>
  667.         /// PCAN-PCI interface, channel 8
  668.         /// </summary>
  669.         public const TPCANHandle PCAN_PCIBUS8 = 0x48;
  670.         /// <summary>
  671.         /// PCAN-PCI interface, channel 9
  672.         /// </summary>
  673.         public const TPCANHandle PCAN_PCIBUS9 = 0x409;
  674.         /// <summary>
  675.         /// PCAN-PCI interface, channel 10
  676.         /// </summary>
  677.         public const TPCANHandle PCAN_PCIBUS10 = 0x40A;
  678.         /// <summary>
  679.         /// PCAN-PCI interface, channel 11
  680.         /// </summary>
  681.         public const TPCANHandle PCAN_PCIBUS11 = 0x40B;
  682.         /// <summary>
  683.         /// PCAN-PCI interface, channel 12
  684.         /// </summary>
  685.         public const TPCANHandle PCAN_PCIBUS12 = 0x40C;
  686.         /// <summary>
  687.         /// PCAN-PCI interface, channel 13
  688.         /// </summary>
  689.         public const TPCANHandle PCAN_PCIBUS13 = 0x40D;
  690.         /// <summary>
  691.         /// PCAN-PCI interface, channel 14
  692.         /// </summary>
  693.         public const TPCANHandle PCAN_PCIBUS14 = 0x40E;
  694.         /// <summary>
  695.         /// PCAN-PCI interface, channel 15
  696.         /// </summary>
  697.         public const TPCANHandle PCAN_PCIBUS15 = 0x40F;
  698.         /// <summary>
  699.         /// PCAN-PCI interface, channel 16
  700.         /// </summary>
  701.         public const TPCANHandle PCAN_PCIBUS16 = 0x410;
  702.  
  703.         /// <summary>
  704.         /// PCAN-USB interface, channel 1
  705.         /// </summary>
  706.         public const TPCANHandle PCAN_USBBUS1 = 0x51;
  707.         /// <summary>
  708.         /// PCAN-USB interface, channel 2
  709.         /// </summary>
  710.         public const TPCANHandle PCAN_USBBUS2 = 0x52;
  711.         /// <summary>
  712.         /// PCAN-USB interface, channel 3
  713.         /// </summary>
  714.         public const TPCANHandle PCAN_USBBUS3 = 0x53;
  715.         /// <summary>
  716.         /// PCAN-USB interface, channel 4
  717.         /// </summary>
  718.         public const TPCANHandle PCAN_USBBUS4 = 0x54;
  719.         /// <summary>
  720.         /// PCAN-USB interface, channel 5
  721.         /// </summary>
  722.         public const TPCANHandle PCAN_USBBUS5 = 0x55;
  723.         /// <summary>
  724.         /// PCAN-USB interface, channel 6
  725.         /// </summary>
  726.         public const TPCANHandle PCAN_USBBUS6 = 0x56;
  727.         /// <summary>
  728.         /// PCAN-USB interface, channel 7
  729.         /// </summary>
  730.         public const TPCANHandle PCAN_USBBUS7 = 0x57;
  731.         /// <summary>
  732.         /// PCAN-USB interface, channel 8
  733.         /// </summary>
  734.         public const TPCANHandle PCAN_USBBUS8 = 0x58;
  735.         /// <summary>
  736.         /// PCAN-USB interface, channel 9
  737.         /// </summary>
  738.         public const TPCANHandle PCAN_USBBUS9 = 0x509;
  739.         /// <summary>
  740.         /// PCAN-USB interface, channel 10
  741.         /// </summary>
  742.         public const TPCANHandle PCAN_USBBUS10 = 0x50A;
  743.         /// <summary>
  744.         /// PCAN-USB interface, channel 11
  745.         /// </summary>
  746.         public const TPCANHandle PCAN_USBBUS11 = 0x50B;
  747.         /// <summary>
  748.         /// PCAN-USB interface, channel 12
  749.         /// </summary>
  750.         public const TPCANHandle PCAN_USBBUS12 = 0x50C;
  751.         /// <summary>
  752.         /// PCAN-USB interface, channel 13
  753.         /// </summary>
  754.         public const TPCANHandle PCAN_USBBUS13 = 0x50D;
  755.         /// <summary>
  756.         /// PCAN-USB interface, channel 14
  757.         /// </summary>
  758.         public const TPCANHandle PCAN_USBBUS14 = 0x50E;
  759.         /// <summary>
  760.         /// PCAN-USB interface, channel 15
  761.         /// </summary>
  762.         public const TPCANHandle PCAN_USBBUS15 = 0x50F;
  763.         /// <summary>
  764.         /// PCAN-USB interface, channel 16
  765.         /// </summary>
  766.         public const TPCANHandle PCAN_USBBUS16 = 0x510;
  767.  
  768.         /// <summary>
  769.         /// PCAN-PC Card interface, channel 1
  770.         /// </summary>
  771.         public const TPCANHandle PCAN_PCCBUS1 = 0x61;
  772.         /// <summary>
  773.         /// PCAN-PC Card interface, channel 2
  774.         /// </summary>
  775.         public const TPCANHandle PCAN_PCCBUS2 = 0x62;
  776.  
  777.         /// <summary>
  778.         /// PCAN-LAN interface, channel 1
  779.         /// </summary>
  780.         public const TPCANHandle PCAN_LANBUS1 = 0x801;
  781.         /// <summary>
  782.         /// PCAN-LAN interface, channel 2
  783.         /// </summary>
  784.         public const TPCANHandle PCAN_LANBUS2 = 0x802;
  785.         /// <summary>
  786.         /// PCAN-LAN interface, channel 3
  787.         /// </summary>
  788.         public const TPCANHandle PCAN_LANBUS3 = 0x803;
  789.         /// <summary>
  790.         /// PCAN-LAN interface, channel 4
  791.         /// </summary>
  792.         public const TPCANHandle PCAN_LANBUS4 = 0x804;
  793.         /// <summary>
  794.         /// PCAN-LAN interface, channel 5
  795.         /// </summary>
  796.         public const TPCANHandle PCAN_LANBUS5 = 0x805;
  797.         /// <summary>
  798.         /// PCAN-LAN interface, channel 6
  799.         /// </summary>
  800.         public const TPCANHandle PCAN_LANBUS6 = 0x806;
  801.         /// <summary>
  802.         /// PCAN-LAN interface, channel 7
  803.         /// </summary>
  804.         public const TPCANHandle PCAN_LANBUS7 = 0x807;
  805.         /// <summary>
  806.         /// PCAN-LAN interface, channel 8
  807.         /// </summary>
  808.         public const TPCANHandle PCAN_LANBUS8 = 0x808;
  809.         /// <summary>
  810.         /// PCAN-LAN interface, channel 9
  811.         /// </summary>
  812.         public const TPCANHandle PCAN_LANBUS9 = 0x809;
  813.         /// <summary>
  814.         /// PCAN-LAN interface, channel 10
  815.         /// </summary>
  816.         public const TPCANHandle PCAN_LANBUS10 = 0x80A;
  817.         /// <summary>
  818.         /// PCAN-LAN interface, channel 11
  819.         /// </summary>
  820.         public const TPCANHandle PCAN_LANBUS11 = 0x80B;
  821.         /// <summary>
  822.         /// PCAN-LAN interface, channel 12
  823.         /// </summary>
  824.         public const TPCANHandle PCAN_LANBUS12 = 0x80C;
  825.         /// <summary>
  826.         /// PCAN-LAN interface, channel 13
  827.         /// </summary>
  828.         public const TPCANHandle PCAN_LANBUS13 = 0x80D;
  829.         /// <summary>
  830.         /// PCAN-LAN interface, channel 14
  831.         /// </summary>
  832.         public const TPCANHandle PCAN_LANBUS14 = 0x80E;
  833.         /// <summary>
  834.         /// PCAN-LAN interface, channel 15
  835.         /// </summary>
  836.         public const TPCANHandle PCAN_LANBUS15 = 0x80F;
  837.         /// <summary>
  838.         /// PCAN-LAN interface, channel 16
  839.         /// </summary>
  840.         public const TPCANHandle PCAN_LANBUS16 = 0x810;
  841.         #endregion
  842.  
  843.         #region FD Bit rate parameters
  844.         /// <summary>
  845.         /// Clock frequency in Herz (80000000, 60000000, 40000000, 30000000, 24000000, 20000000)
  846.         /// </summary>
  847.         public const string PCAN_BR_CLOCK = "f_clock";
  848.         /// <summary>
  849.         /// Clock frequency in Megaherz (80, 60, 40, 30, 24, 20)
  850.         /// </summary>
  851.         public const string PCAN_BR_CLOCK_MHZ = "f_clock_mhz";     
  852.         /// <summary>
  853.         /// Clock prescaler for nominal time quantum
  854.         /// </summary>
  855.         public const string PCAN_BR_NOM_BRP = "nom_brp";
  856.         /// <summary>
  857.         /// TSEG1 segment for nominal bit rate in time quanta
  858.         /// </summary>
  859.         public const string PCAN_BR_NOM_TSEG1 = "nom_tseg1";
  860.         /// <summary>
  861.         /// TSEG2 segment for nominal bit rate in time quanta
  862.         /// </summary>
  863.         public const string PCAN_BR_NOM_TSEG2 = "nom_tseg2";
  864.         /// <summary>
  865.         /// Synchronization Jump Width for nominal bit rate in time quanta
  866.         /// </summary>
  867.         public const string PCAN_BR_NOM_SJW = "nom_sjw";
  868.         /// <summary>
  869.         /// Sample point for nominal bit rate
  870.         /// </summary>
  871.         public const string PCAN_BR_NOM_SAMPLE = "nom_sam";
  872.         /// <summary>
  873.         /// Clock prescaler for highspeed data time quantum
  874.         /// </summary>
  875.         public const string PCAN_BR_DATA_BRP = "data_brp";
  876.         /// <summary>
  877.         /// TSEG1 segment for fast data bit rate in time quanta
  878.         /// </summary>
  879.         public const string PCAN_BR_DATA_TSEG1 = "data_tseg1";
  880.         /// <summary>
  881.         /// TSEG2 segment for fast data bit rate in time quanta
  882.         /// </summary>
  883.         public const string PCAN_BR_DATA_TSEG2 = "data_tseg2";
  884.         /// <summary>
  885.         /// Synchronization Jump Width for highspeed data bit rate in time quanta
  886.         /// </summary>
  887.         public const string PCAN_BR_DATA_SJW = "data_sjw";
  888.         /// <summary>
  889.         /// Secondary sample point delay for highspeed data bit rate in cyles
  890.         /// </summary>
  891.         public const string PCAN_BR_DATA_SAMPLE = "data_ssp_offset";
  892.         #endregion
  893.  
  894.         #region Parameter values definition
  895.         /// <summary>
  896.         /// The PCAN parameter is not set (inactive)
  897.         /// </summary>
  898.         public const int PCAN_PARAMETER_OFF = 0;
  899.         /// <summary>
  900.         /// The PCAN parameter is set (active)
  901.         /// </summary>
  902.         public const int PCAN_PARAMETER_ON = 1;
  903.         /// <summary>
  904.         /// The PCAN filter is closed. No messages will be received
  905.         /// </summary>
  906.         public const int PCAN_FILTER_CLOSE = 0;
  907.         /// <summary>
  908.         /// The PCAN filter is fully opened. All messages will be received
  909.         /// </summary>
  910.         public const int PCAN_FILTER_OPEN = 1;
  911.         /// <summary>
  912.         /// The PCAN filter is custom configured. Only registered
  913.         /// messages will be received
  914.         /// </summary>
  915.         public const int PCAN_FILTER_CUSTOM = 2;
  916.         /// <summary>
  917.         /// The PCAN-Channel handle is illegal, or its associated hardware is not available
  918.         /// </summary>
  919.         public const int PCAN_CHANNEL_UNAVAILABLE = 0;
  920.         /// <summary>
  921.         /// The PCAN-Channel handle is available to be connected (Plug and Play Hardware: it means furthermore that the hardware is plugged-in)
  922.         /// </summary>
  923.         public const int PCAN_CHANNEL_AVAILABLE = 1;
  924.         /// <summary>
  925.         /// The PCAN-Channel handle is valid, and is already being used
  926.         /// </summary>
  927.         public const int PCAN_CHANNEL_OCCUPIED = 2;
  928.         /// <summary>
  929.         /// The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect
  930.         /// </summary>
  931.         public const int PCAN_CHANNEL_PCANVIEW = (PCAN_CHANNEL_AVAILABLE | PCAN_CHANNEL_OCCUPIED);
  932.  
  933.         /// <summary>
  934.         /// Logs system exceptions / errors
  935.         /// </summary>
  936.         public const int LOG_FUNCTION_DEFAULT = 0x00;
  937.         /// <summary>
  938.         /// Logs the entries to the PCAN-Basic API functions
  939.         /// </summary>
  940.         public const int LOG_FUNCTION_ENTRY = 0x01;
  941.         /// <summary>
  942.         /// Logs the parameters passed to the PCAN-Basic API functions
  943.         /// </summary>
  944.         public const int LOG_FUNCTION_PARAMETERS = 0x02;
  945.         /// <summary>
  946.         /// Logs the exits from the PCAN-Basic API functions
  947.         /// </summary>
  948.         public const int LOG_FUNCTION_LEAVE = 0x04;
  949.         /// <summary>
  950.         /// Logs the CAN messages passed to the CAN_Write function
  951.         /// </summary>
  952.         public const int LOG_FUNCTION_WRITE = 0x08;
  953.         /// <summary>
  954.         /// Logs the CAN messages received within the CAN_Read function
  955.         /// </summary>
  956.         public const int LOG_FUNCTION_READ = 0x10;
  957.         /// <summary>
  958.         /// Logs all possible information within the PCAN-Basic API functions
  959.         /// </summary>
  960.         public const int LOG_FUNCTION_ALL = 0xFFFF;
  961.  
  962.         /// <summary>
  963.         /// A single file is written until it size reaches PAN_TRACE_SIZE
  964.         /// </summary>
  965.         public const int TRACE_FILE_SINGLE = 0x00;
  966.         /// <summary>
  967.         /// Traced data is distributed in several files with size PAN_TRACE_SIZE
  968.         /// </summary>
  969.         public const int TRACE_FILE_SEGMENTED = 0x01;
  970.         /// <summary>
  971.         /// Includes the date into the name of the trace file
  972.         /// </summary>
  973.         public const int TRACE_FILE_DATE = 0x02;
  974.         /// <summary>
  975.         /// Includes the start time into the name of the trace file
  976.         /// </summary>
  977.         public const int TRACE_FILE_TIME = 0x04;
  978.         /// <summary>
  979.         /// Causes the overwriting of available traces (same name)
  980.         /// </summary>
  981.         public const int TRACE_FILE_OVERWRITE = 0x80;
  982.  
  983.         /// <summary>
  984.         /// Device supports flexible data-rate (CAN-FD)
  985.         /// </summary>
  986.         public const int FEATURE_FD_CAPABLE = 0x01;
  987.         /// <summary>
  988.         /// Device supports a delay between sending frames (FPGA based USB devices)
  989.         /// </summary>
  990.         public const int FEATURE_DELAY_CAPABLE = 0x02;
  991.         /// <summary>
  992.         /// Device supports I/O functionality for electronic circuits (USB-Chip devices)
  993.         /// </summary>
  994.         public const int FEATURE_IO_CAPABLE = 0x04;
  995.  
  996.         /// <summary>
  997.         /// The service is not running
  998.         /// </summary>
  999.         public const int SERVICE_STATUS_STOPPED = 0x01;
  1000.         /// <summary>
  1001.         /// The service is running
  1002.         /// </summary>
  1003.         public const int SERVICE_STATUS_RUNNING = 0x04;
  1004.         #endregion
  1005.  
  1006.         #region PCANBasic API Implementation
  1007.         /// <summary>
  1008.         /// Initializes a PCAN Channel
  1009.         /// </summary>
  1010.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1011.         /// <param name="Btr0Btr1">The speed for the communication (BTR0BTR1 code)</param>
  1012.         /// <param name="HwType">NON PLUG and PLAY: The type of hardware and operation mode</param>
  1013.         /// <param name="IOPort">NON PLUG and PLAY: The I/O address for the parallel port</param>
  1014.         /// <param name="Interrupt">NON PLUG and PLAY: Interrupt number of the parallel por</param>
  1015.         /// <returns>A TPCANStatus error code</returns>
  1016.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_Initialize")]
  1017.         public static extern TPCANStatus Initialize(
  1018.             [MarshalAs(UnmanagedType.U2)]
  1019.             TPCANHandle Channel,
  1020.             [MarshalAs(UnmanagedType.U2)]
  1021.             TPCANBaudrate Btr0Btr1,
  1022.             [MarshalAs(UnmanagedType.U1)]
  1023.             TPCANType HwType,
  1024.             UInt32 IOPort,
  1025.             UInt16 Interrupt);
  1026.  
  1027.         /// <summary>
  1028.         /// Initializes a PCAN Channel
  1029.         /// </summary>
  1030.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1031.         /// <param name="Btr0Btr1">The speed for the communication (BTR0BTR1 code)</param>
  1032.         /// <returns>A TPCANStatus error code</returns>        
  1033.         public static TPCANStatus Initialize(
  1034.             TPCANHandle Channel,
  1035.             TPCANBaudrate Btr0Btr1)
  1036.         {
  1037.             return Initialize(Channel, Btr0Btr1, (TPCANType)0, 0, 0);
  1038.         }
  1039.  
  1040.         /// <summary>
  1041.         /// Initializes a FD capable PCAN Channel
  1042.         /// </summary>
  1043.         /// <param name="Channel">The handle of a FD capable PCAN Channel</param>
  1044.         /// <param name="BitrateFD">The speed for the communication (FD bit rate string)</param>
  1045.         /// <remarks> See PCAN_BR_* values
  1046.         /// Bit rate string must follow the following construction rules:
  1047.         /// * parameters and values must be separated by '='
  1048.         /// * Couples of Parameter/value must be separated by ','
  1049.         /// * Following Parameter must be filled out: f_clock, data_brp, data_sjw, data_tseg1, data_tseg2,
  1050.         ///   nom_brp, nom_sjw, nom_tseg1, nom_tseg2.
  1051.         /// * Following Parameters are optional (not used yet): data_ssp_offset, nom_sam</remarks>
  1052.         /// <example>f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1</example>
  1053.         /// <returns>A TPCANStatus error code</returns>
  1054.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_InitializeFD")]
  1055.         public static extern TPCANStatus InitializeFD(
  1056.             [MarshalAs(UnmanagedType.U2)]
  1057.             TPCANHandle Channel,
  1058.             TPCANBitrateFD BitrateFD);
  1059.  
  1060.         /// <summary>
  1061.         /// Uninitializes one or all PCAN Channels initialized by CAN_Initialize
  1062.         /// </summary>
  1063.         /// <remarks>Giving the TPCANHandle value "PCAN_NONEBUS",
  1064.         /// uninitialize all initialized channels</remarks>
  1065.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1066.         /// <returns>A TPCANStatus error code</returns>
  1067.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_Uninitialize")]
  1068.         public static extern TPCANStatus Uninitialize(
  1069.             [MarshalAs(UnmanagedType.U2)]
  1070.             TPCANHandle Channel);
  1071.  
  1072.         /// <summary>
  1073.         /// Resets the receive and transmit queues of the PCAN Channel
  1074.         /// </summary>
  1075.         /// <remarks>A reset of the CAN controller is not performed</remarks>
  1076.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1077.         /// <returns>A TPCANStatus error code</returns>
  1078.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_Reset")]
  1079.         public static extern TPCANStatus Reset(
  1080.             [MarshalAs(UnmanagedType.U2)]
  1081.             TPCANHandle Channel);
  1082.  
  1083.         /// <summary>
  1084.         /// Gets the current status of a PCAN Channel
  1085.         /// </summary>
  1086.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1087.         /// <returns>A TPCANStatus error code</returns>
  1088.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetStatus")]
  1089.         public static extern TPCANStatus GetStatus(
  1090.             [MarshalAs(UnmanagedType.U2)]
  1091.             TPCANHandle Channel);
  1092.  
  1093.         /// <summary>
  1094.         /// Reads a CAN message from the receive queue of a PCAN Channel
  1095.         /// </summary>
  1096.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1097.         /// <param name="MessageBuffer">A TPCANMsg structure buffer to store the CAN message</param>
  1098.         /// <param name="TimestampBuffer">A TPCANTimestamp structure buffer to get
  1099.         /// the reception time of the message</param>
  1100.         /// <returns>A TPCANStatus error code</returns>
  1101.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_Read")]
  1102.         public static extern TPCANStatus Read(
  1103.             [MarshalAs(UnmanagedType.U2)]
  1104.             TPCANHandle Channel,
  1105.             out TPCANMsg MessageBuffer,
  1106.             out TPCANTimestamp TimestampBuffer);
  1107.  
  1108.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_Read")]
  1109.         private static extern TPCANStatus Read(
  1110.             [MarshalAs(UnmanagedType.U2)]
  1111.             TPCANHandle Channel,
  1112.             out TPCANMsg MessageBuffer,
  1113.             IntPtr bufferPointer);
  1114.  
  1115.         /// <summary>
  1116.         /// Reads a CAN message from the receive queue of a PCAN Channel
  1117.         /// </summary>
  1118.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1119.         /// <param name="MessageBuffer">A TPCANMsg structure buffer to store the CAN message</param>        
  1120.         /// <returns>A TPCANStatus error code</returns>
  1121.         public static TPCANStatus Read(
  1122.             TPCANHandle Channel,
  1123.             out TPCANMsg MessageBuffer)
  1124.         {
  1125.             return Read(Channel, out MessageBuffer, IntPtr.Zero);
  1126.         }
  1127.  
  1128.         /// <summary>
  1129.         /// Reads a CAN message from the receive queue of a FD capable PCAN Channel
  1130.         /// </summary>
  1131.         /// <param name="Channel">The handle of a FD capable PCAN Channel</param>
  1132.         /// <param name="MessageBuffer">A TPCANMsgFD structure buffer to store the CAN message</param>
  1133.         /// <param name="TimestampBuffer">A TPCANTimestampFD buffer to get the
  1134.         /// reception time of the message</param>
  1135.         /// <returns>A TPCANStatus error code</returns>
  1136.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_ReadFD")]
  1137.         public static extern TPCANStatus ReadFD(
  1138.             [MarshalAs(UnmanagedType.U2)]
  1139.             TPCANHandle Channel,
  1140.             out TPCANMsgFD MessageBuffer,
  1141.             out TPCANTimestampFD TimestampBuffer);
  1142.  
  1143.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_ReadFD")]
  1144.         private static extern TPCANStatus ReadFD(
  1145.             [MarshalAs(UnmanagedType.U2)]
  1146.             TPCANHandle Channel,
  1147.             out TPCANMsgFD MessageBuffer,
  1148.             IntPtr TimestampBuffer);
  1149.  
  1150.         /// <summary>
  1151.         /// Reads a CAN message from the receive queue of a FD capable PCAN Channel
  1152.         /// </summary>
  1153.         /// <param name="Channel">The handle of a FD capable PCAN Channel</param>
  1154.         /// <param name="MessageBuffer">A TPCANMsgFD structure buffer to store the CAN message</param>
  1155.         /// <returns>A TPCANStatus error code</returns>
  1156.         public static TPCANStatus ReadFD(
  1157.             TPCANHandle Channel,
  1158.             out TPCANMsgFD MessageBuffer)
  1159.         {
  1160.             return ReadFD(Channel, out MessageBuffer, IntPtr.Zero);
  1161.         }
  1162.  
  1163.         /// <summary>
  1164.         ///  Transmits a CAN message
  1165.         /// </summary>
  1166.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1167.         /// <param name="MessageBuffer">A TPCANMsg buffer with the message to be sent</param>
  1168.         /// <returns>A TPCANStatus error code</returns>
  1169.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_Write")]
  1170.         public static extern TPCANStatus Write(
  1171.             [MarshalAs(UnmanagedType.U2)]
  1172.             TPCANHandle Channel,
  1173.             ref TPCANMsg MessageBuffer);
  1174.  
  1175.         /// <summary>
  1176.         /// Transmits a CAN message over a FD capable PCAN Channel
  1177.         /// </summary>
  1178.         /// <param name="Channel">The handle of a FD capable PCAN Channel</param>
  1179.         /// <param name="MessageBuffer">A TPCANMsgFD buffer with the message to be sent</param>
  1180.         /// <returns>A TPCANStatus error code</returns>
  1181.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_WriteFD")]
  1182.         public static extern TPCANStatus WriteFD(
  1183.             [MarshalAs(UnmanagedType.U2)]
  1184.             TPCANHandle Channel,
  1185.             ref TPCANMsgFD MessageBuffer);
  1186.  
  1187.         /// <summary>
  1188.         /// Configures the reception filter
  1189.         /// </summary>
  1190.         /// <remarks>The message filter will be expanded with every call to
  1191.         /// this function. If it is desired to reset the filter, please use
  1192.         /// the 'SetValue' function</remarks>
  1193.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1194.         /// <param name="FromID">The lowest CAN ID to be received</param>
  1195.         /// <param name="ToID">The highest CAN ID to be received</param>
  1196.         /// <param name="Mode">Message type, Standard (11-bit identifier) or
  1197.         /// Extended (29-bit identifier)</param>
  1198.         /// <returns>A TPCANStatus error code</returns>
  1199.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_FilterMessages")]
  1200.         public static extern TPCANStatus FilterMessages(
  1201.             [MarshalAs(UnmanagedType.U2)]
  1202.             TPCANHandle Channel,
  1203.             UInt32 FromID,
  1204.             UInt32 ToID,
  1205.             [MarshalAs(UnmanagedType.U1)]
  1206.             TPCANMode Mode);
  1207.  
  1208.         /// <summary>
  1209.         /// Retrieves a PCAN Channel value
  1210.         /// </summary>
  1211.         /// <remarks>Parameters can be present or not according with the kind
  1212.         /// of Hardware (PCAN Channel) being used. If a parameter is not available,
  1213.         /// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
  1214.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1215.         /// <param name="Parameter">The TPCANParameter parameter to get</param>
  1216.         /// <param name="StringBuffer">Buffer for the parameter value</param>
  1217.         /// <param name="BufferLength">Size in bytes of the buffer</param>
  1218.         /// <returns>A TPCANStatus error code</returns>
  1219.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")]
  1220.         public static extern TPCANStatus GetValue(
  1221.             [MarshalAs(UnmanagedType.U2)]
  1222.             TPCANHandle Channel,
  1223.             [MarshalAs(UnmanagedType.U1)]
  1224.             TPCANParameter Parameter,
  1225.             StringBuilder StringBuffer,            
  1226.             UInt32 BufferLength);
  1227.  
  1228.         /// <summary>
  1229.         /// Retrieves a PCAN Channel value
  1230.         /// </summary>
  1231.         /// <remarks>Parameters can be present or not according with the kind
  1232.         /// of Hardware (PCAN Channel) being used. If a parameter is not available,
  1233.         /// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
  1234.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1235.         /// <param name="Parameter">The TPCANParameter parameter to get</param>
  1236.         /// <param name="NumericBuffer">Buffer for the parameter value</param>
  1237.         /// <param name="BufferLength">Size in bytes of the buffer</param>
  1238.         /// <returns>A TPCANStatus error code</returns>
  1239.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")]
  1240.         public static extern TPCANStatus GetValue(
  1241.             [MarshalAs(UnmanagedType.U2)]
  1242.             TPCANHandle Channel,
  1243.             [MarshalAs(UnmanagedType.U1)]
  1244.             TPCANParameter Parameter,
  1245.             out UInt32 NumericBuffer,
  1246.             UInt32 BufferLength);
  1247.  
  1248.         /// <summary>
  1249.         /// Retrieves a PCAN Channel value
  1250.         /// </summary>
  1251.         /// <remarks>Parameters can be present or not according with the kind
  1252.         /// of Hardware (PCAN Channel) being used. If a parameter is not available,
  1253.         /// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
  1254.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1255.         /// <param name="Parameter">The TPCANParameter parameter to get</param>
  1256.         /// <param name="NumericBuffer">Buffer for the parameter value</param>
  1257.         /// <param name="BufferLength">Size in bytes of the buffer</param>
  1258.         /// <returns>A TPCANStatus error code</returns>
  1259.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")]
  1260.         public static extern TPCANStatus GetValue(
  1261.             [MarshalAs(UnmanagedType.U2)]
  1262.             TPCANHandle Channel,
  1263.             [MarshalAs(UnmanagedType.U1)]
  1264.             TPCANParameter Parameter,
  1265.             out UInt64 NumericBuffer,
  1266.             UInt32 BufferLength);
  1267.  
  1268.         /// <summary>
  1269.         /// Configures or sets a PCAN Channel value
  1270.         /// </summary>
  1271.         /// <remarks>Parameters can be present or not according with the kind
  1272.         /// of Hardware (PCAN Channel) being used. If a parameter is not available,
  1273.         /// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
  1274.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1275.         /// <param name="Parameter">The TPCANParameter parameter to set</param>
  1276.         /// <param name="NumericBuffer">Buffer with the value to be set</param>
  1277.         /// <param name="BufferLength">Size in bytes of the buffer</param>
  1278.         /// <returns>A TPCANStatus error code</returns>
  1279.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_SetValue")]
  1280.         public static extern TPCANStatus SetValue(
  1281.             [MarshalAs(UnmanagedType.U2)]
  1282.             TPCANHandle Channel,
  1283.             [MarshalAs(UnmanagedType.U1)]
  1284.             TPCANParameter Parameter,
  1285.             ref UInt32 NumericBuffer,
  1286.             UInt32 BufferLength);
  1287.  
  1288.         /// <summary>
  1289.         /// Configures or sets a PCAN Channel value
  1290.         /// </summary>
  1291.         /// <remarks>Parameters can be present or not according with the kind
  1292.         /// of Hardware (PCAN Channel) being used. If a parameter is not available,
  1293.         /// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
  1294.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1295.         /// <param name="Parameter">The TPCANParameter parameter to set</param>
  1296.         /// <param name="NumericBuffer">Buffer with the value to be set</param>
  1297.         /// <param name="BufferLength">Size in bytes of the buffer</param>
  1298.         /// <returns>A TPCANStatus error code</returns>
  1299.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_SetValue")]
  1300.         public static extern TPCANStatus SetValue(
  1301.             [MarshalAs(UnmanagedType.U2)]
  1302.             TPCANHandle Channel,
  1303.             [MarshalAs(UnmanagedType.U1)]
  1304.             TPCANParameter Parameter,
  1305.             ref UInt64 NumericBuffer,
  1306.             UInt32 BufferLength);
  1307.  
  1308.         /// <summary>
  1309.         /// Configures or sets a PCAN Channel value
  1310.         /// </summary>
  1311.         /// <remarks>Parameters can be present or not according with the kind
  1312.         /// of Hardware (PCAN Channel) being used. If a parameter is not available,
  1313.         /// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
  1314.         /// <param name="Channel">The handle of a PCAN Channel</param>
  1315.         /// <param name="Parameter"></param>
  1316.         /// <param name="StringBuffer">Buffer with the value to be set</param>
  1317.         /// <param name="BufferLength">Size in bytes of the buffer</param>
  1318.         /// <returns>A TPCANStatus error code</returns>
  1319.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_SetValue")]
  1320.         public static extern TPCANStatus SetValue(
  1321.             [MarshalAs(UnmanagedType.U2)]
  1322.             TPCANHandle Channel,
  1323.             [MarshalAs(UnmanagedType.U1)]
  1324.             TPCANParameter Parameter,
  1325.             [MarshalAs(UnmanagedType.LPStr,SizeParamIndex=3)]
  1326.             string StringBuffer,
  1327.             UInt32 BufferLength);
  1328.  
  1329.         /// <summary>
  1330.         /// Returns a descriptive text of a given TPCANStatus error
  1331.         /// code, in any desired language
  1332.         /// </summary>
  1333.         /// <remarks>The current languages available for translation are:
  1334.         /// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A),
  1335.         /// Italian (0x10) and French (0x0C)</remarks>
  1336.         /// <param name="Error">A TPCANStatus error code</param>
  1337.         /// <param name="Language">Indicates a 'Primary language ID'</param>
  1338.         /// <param name="StringBuffer">Buffer for the text (must be at least 256 in length)</param>
  1339.         /// <returns>A TPCANStatus error code</returns>
  1340.         [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetErrorText")]
  1341.         public static extern TPCANStatus GetErrorText(
  1342.             [MarshalAs(UnmanagedType.U4)]
  1343.             TPCANStatus Error,
  1344.             UInt16 Language,
  1345.             StringBuilder StringBuffer);
  1346.         #endregion
  1347.     }
  1348.     #endregion
  1349. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement