PCANBasic.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. // PCANBasic.h
  2. //
  3. // ~~~~~~~~~~~~
  4. //
  5. // PCAN-Basic API
  6. //
  7. // ~~~~~~~~~~~~
  8. //
  9. // ------------------------------------------------------------------
  10. // Author : Keneth Wagner
  11. // Last change: 24.04.2015 Wagner
  12. //
  13. // Language: ANSI-C
  14. // ------------------------------------------------------------------
  15. //
  16. // Copyright (C) 1999-2015 PEAK-System Technik GmbH, Darmstadt
  17. // more Info at http://www.peak-system.com
  18. //
  19. #ifndef __PCANBASICH__
  20. #define __PCANBASICH__
  21. ////////////////////////////////////////////////////////////
  22. // Value definitions
  23. ////////////////////////////////////////////////////////////
  24. // Currently defined and supported PCAN channels
  25. //
  26. #define PCAN_NONEBUS 0x00U // Undefined/default value for a PCAN bus
  27. #define PCAN_ISABUS1 0x21U // PCAN-ISA interface, channel 1
  28. #define PCAN_ISABUS2 0x22U // PCAN-ISA interface, channel 2
  29. #define PCAN_ISABUS3 0x23U // PCAN-ISA interface, channel 3
  30. #define PCAN_ISABUS4 0x24U // PCAN-ISA interface, channel 4
  31. #define PCAN_ISABUS5 0x25U // PCAN-ISA interface, channel 5
  32. #define PCAN_ISABUS6 0x26U // PCAN-ISA interface, channel 6
  33. #define PCAN_ISABUS7 0x27U // PCAN-ISA interface, channel 7
  34. #define PCAN_ISABUS8 0x28U // PCAN-ISA interface, channel 8
  35. #define PCAN_DNGBUS1 0x31U // PCAN-Dongle/LPT interface, channel 1
  36. #define PCAN_PCIBUS1 0x41U // PCAN-PCI interface, channel 1
  37. #define PCAN_PCIBUS2 0x42U // PCAN-PCI interface, channel 2
  38. #define PCAN_PCIBUS3 0x43U // PCAN-PCI interface, channel 3
  39. #define PCAN_PCIBUS4 0x44U // PCAN-PCI interface, channel 4
  40. #define PCAN_PCIBUS5 0x45U // PCAN-PCI interface, channel 5
  41. #define PCAN_PCIBUS6 0x46U // PCAN-PCI interface, channel 6
  42. #define PCAN_PCIBUS7 0x47U // PCAN-PCI interface, channel 7
  43. #define PCAN_PCIBUS8 0x48U // PCAN-PCI interface, channel 8
  44. #define PCAN_PCIBUS9 0x409U // PCAN-PCI interface, channel 9
  45. #define PCAN_PCIBUS10 0x40AU // PCAN-PCI interface, channel 10
  46. #define PCAN_PCIBUS11 0x40BU // PCAN-PCI interface, channel 11
  47. #define PCAN_PCIBUS12 0x40CU // PCAN-PCI interface, channel 12
  48. #define PCAN_PCIBUS13 0x40DU // PCAN-PCI interface, channel 13
  49. #define PCAN_PCIBUS14 0x40EU // PCAN-PCI interface, channel 14
  50. #define PCAN_PCIBUS15 0x40FU // PCAN-PCI interface, channel 15
  51. #define PCAN_PCIBUS16 0x410U // PCAN-PCI interface, channel 16
  52. #define PCAN_USBBUS1 0x51U // PCAN-USB interface, channel 1
  53. #define PCAN_USBBUS2 0x52U // PCAN-USB interface, channel 2
  54. #define PCAN_USBBUS3 0x53U // PCAN-USB interface, channel 3
  55. #define PCAN_USBBUS4 0x54U // PCAN-USB interface, channel 4
  56. #define PCAN_USBBUS5 0x55U // PCAN-USB interface, channel 5
  57. #define PCAN_USBBUS6 0x56U // PCAN-USB interface, channel 6
  58. #define PCAN_USBBUS7 0x57U // PCAN-USB interface, channel 7
  59. #define PCAN_USBBUS8 0x58U // PCAN-USB interface, channel 8
  60. #define PCAN_USBBUS9 0x509U // PCAN-USB interface, channel 9
  61. #define PCAN_USBBUS10 0x50AU // PCAN-USB interface, channel 10
  62. #define PCAN_USBBUS11 0x50BU // PCAN-USB interface, channel 11
  63. #define PCAN_USBBUS12 0x50CU // PCAN-USB interface, channel 12
  64. #define PCAN_USBBUS13 0x50DU // PCAN-USB interface, channel 13
  65. #define PCAN_USBBUS14 0x50EU // PCAN-USB interface, channel 14
  66. #define PCAN_USBBUS15 0x50FU // PCAN-USB interface, channel 15
  67. #define PCAN_USBBUS16 0x510U // PCAN-USB interface, channel 16
  68. #define PCAN_PCCBUS1 0x61U // PCAN-PC Card interface, channel 1
  69. #define PCAN_PCCBUS2 0x62U // PCAN-PC Card interface, channel 2
  70. #define PCAN_LANBUS1 0x801U // PCAN-LAN interface, channel 1
  71. #define PCAN_LANBUS2 0x802U // PCAN-LAN interface, channel 2
  72. #define PCAN_LANBUS3 0x803U // PCAN-LAN interface, channel 3
  73. #define PCAN_LANBUS4 0x804U // PCAN-LAN interface, channel 4
  74. #define PCAN_LANBUS5 0x805U // PCAN-LAN interface, channel 5
  75. #define PCAN_LANBUS6 0x806U // PCAN-LAN interface, channel 6
  76. #define PCAN_LANBUS7 0x807U // PCAN-LAN interface, channel 7
  77. #define PCAN_LANBUS8 0x808U // PCAN-LAN interface, channel 8
  78. #define PCAN_LANBUS9 0x809U // PCAN-LAN interface, channel 9
  79. #define PCAN_LANBUS10 0x80AU // PCAN-LAN interface, channel 10
  80. #define PCAN_LANBUS11 0x80BU // PCAN-LAN interface, channel 11
  81. #define PCAN_LANBUS12 0x80CU // PCAN-LAN interface, channel 12
  82. #define PCAN_LANBUS13 0x80DU // PCAN-LAN interface, channel 13
  83. #define PCAN_LANBUS14 0x80EU // PCAN-LAN interface, channel 14
  84. #define PCAN_LANBUS15 0x80FU // PCAN-LAN interface, channel 15
  85. #define PCAN_LANBUS16 0x810U // PCAN-LAN interface, channel 16
  86. // Represent the PCAN error and status codes
  87. //
  88. #define PCAN_ERROR_OK 0x00000U // No error
  89. #define PCAN_ERROR_XMTFULL 0x00001U // Transmit buffer in CAN controller is full
  90. #define PCAN_ERROR_OVERRUN 0x00002U // CAN controller was read too late
  91. #define PCAN_ERROR_BUSLIGHT 0x00004U // Bus error: an error counter reached the 'light' limit
  92. #define PCAN_ERROR_BUSHEAVY 0x00008U // Bus error: an error counter reached the 'heavy' limit
  93. #define PCAN_ERROR_BUSWARNING PCAN_ERROR_BUSHEAVY // Bus error: an error counter reached the 'warning' limit
  94. #define PCAN_ERROR_BUSPASSIVE 0x40000U // Bus error: the CAN controller is error passive
  95. #define PCAN_ERROR_BUSOFF 0x00010U // Bus error: the CAN controller is in bus-off state
  96. #define PCAN_ERROR_ANYBUSERR (PCAN_ERROR_BUSWARNING | PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF | PCAN_ERROR_BUSPASSIVE) // Mask for all bus errors
  97. #define PCAN_ERROR_QRCVEMPTY 0x00020U // Receive queue is empty
  98. #define PCAN_ERROR_QOVERRUN 0x00040U // Receive queue was read too late
  99. #define PCAN_ERROR_QXMTFULL 0x00080U // Transmit queue is full
  100. #define PCAN_ERROR_REGTEST 0x00100U // Test of the CAN controller hardware registers failed (no hardware found)
  101. #define PCAN_ERROR_NODRIVER 0x00200U // Driver not loaded
  102. #define PCAN_ERROR_HWINUSE 0x00400U // Hardware already in use by a Net
  103. #define PCAN_ERROR_NETINUSE 0x00800U // A Client is already connected to the Net
  104. #define PCAN_ERROR_ILLHW 0x01400U // Hardware handle is invalid
  105. #define PCAN_ERROR_ILLNET 0x01800U // Net handle is invalid
  106. #define PCAN_ERROR_ILLCLIENT 0x01C00U // Client handle is invalid
  107. #define PCAN_ERROR_ILLHANDLE (PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT) // Mask for all handle errors
  108. #define PCAN_ERROR_RESOURCE 0x02000U // Resource (FIFO, Client, timeout) cannot be created
  109. #define PCAN_ERROR_ILLPARAMTYPE 0x04000U // Invalid parameter
  110. #define PCAN_ERROR_ILLPARAMVAL 0x08000U // Invalid parameter value
  111. #define PCAN_ERROR_UNKNOWN 0x10000U // Unknown error
  112. #define PCAN_ERROR_ILLDATA 0x20000U // Invalid data, function, or action
  113. #define PCAN_ERROR_CAUTION 0x2000000U // An operation was successfully carried out, however, irregularities were registered
  114. #define PCAN_ERROR_INITIALIZE 0x4000000U // Channel is not initialized [Value was changed from 0x40000 to 0x4000000]
  115. #define PCAN_ERROR_ILLOPERATION 0x8000000U // Invalid operation [Value was changed from 0x80000 to 0x8000000]
  116. // PCAN devices
  117. //
  118. #define PCAN_NONE 0x00U // Undefined, unknown or not selected PCAN device value
  119. #define PCAN_PEAKCAN 0x01U // PCAN Non-Plug&Play devices. NOT USED WITHIN PCAN-Basic API
  120. #define PCAN_ISA 0x02U // PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus
  121. #define PCAN_DNG 0x03U // PCAN-Dongle
  122. #define PCAN_PCI 0x04U // PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express
  123. #define PCAN_USB 0x05U // PCAN-USB and PCAN-USB Pro
  124. #define PCAN_PCC 0x06U // PCAN-PC Card
  125. #define PCAN_VIRTUAL 0x07U // PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API
  126. #define PCAN_LAN 0x08U // PCAN Gateway devices
  127. // PCAN parameters
  128. //
  129. #define PCAN_DEVICE_NUMBER 0x01U // PCAN-USB device number parameter
  130. #define PCAN_5VOLTS_POWER 0x02U // PCAN-PC Card 5-Volt power parameter
  131. #define PCAN_RECEIVE_EVENT 0x03U // PCAN receive event handler parameter
  132. #define PCAN_MESSAGE_FILTER 0x04U // PCAN message filter parameter
  133. #define PCAN_API_VERSION 0x05U // PCAN-Basic API version parameter
  134. #define PCAN_CHANNEL_VERSION 0x06U // PCAN device channel version parameter
  135. #define PCAN_BUSOFF_AUTORESET 0x07U // PCAN Reset-On-Busoff parameter
  136. #define PCAN_LISTEN_ONLY 0x08U // PCAN Listen-Only parameter
  137. #define PCAN_LOG_LOCATION 0x09U // Directory path for log files
  138. #define PCAN_LOG_STATUS 0x0AU // Debug-Log activation status
  139. #define PCAN_LOG_CONFIGURE 0x0BU // Configuration of the debugged information (LOG_FUNCTION_***)
  140. #define PCAN_LOG_TEXT 0x0CU // Custom insertion of text into the log file
  141. #define PCAN_CHANNEL_CONDITION 0x0DU // Availability status of a PCAN-Channel
  142. #define PCAN_HARDWARE_NAME 0x0EU // PCAN hardware name parameter
  143. #define PCAN_RECEIVE_STATUS 0x0FU // Message reception status of a PCAN-Channel
  144. #define PCAN_CONTROLLER_NUMBER 0x10U // CAN-Controller number of a PCAN-Channel
  145. #define PCAN_TRACE_LOCATION 0x11U // Directory path for PCAN trace files
  146. #define PCAN_TRACE_STATUS 0x12U // CAN tracing activation status
  147. #define PCAN_TRACE_SIZE 0x13U // Configuration of the maximum file size of a CAN trace
  148. #define PCAN_TRACE_CONFIGURE 0x14U // Configuration of the trace file storing mode (TRACE_FILE_***)
  149. #define PCAN_CHANNEL_IDENTIFYING 0x15U // Physical identification of a USB based PCAN-Channel by blinking its associated LED
  150. #define PCAN_CHANNEL_FEATURES 0x16U // Capabilities of a PCAN device (FEATURE_***)
  151. #define PCAN_BITRATE_ADAPTING 0x17U // Using of an existing bit rate (PCAN-View connected to a channel)
  152. #define PCAN_BITRATE_INFO 0x18U // Configured bit rate as Btr0Btr1 value
  153. #define PCAN_BITRATE_INFO_FD 0x19U // Configured bit rate as TPCANBitrateFD string
  154. #define PCAN_BUSSPEED_NOMINAL 0x1AU // Configured nominal CAN Bus speed as Bits per seconds
  155. #define PCAN_BUSSPEED_DATA 0x1BU // Configured CAN data speed as Bits per seconds
  156. #define PCAN_IP_ADDRESS 0x1CU // Remote address of a LAN channel as string in IPv4 format
  157. // PCAN parameter values
  158. //
  159. #define PCAN_PARAMETER_OFF 0x00U // The PCAN parameter is not set (inactive)
  160. #define PCAN_PARAMETER_ON 0x01U // The PCAN parameter is set (active)
  161. #define PCAN_FILTER_CLOSE 0x00U // The PCAN filter is closed. No messages will be received
  162. #define PCAN_FILTER_OPEN 0x01U // The PCAN filter is fully opened. All messages will be received
  163. #define PCAN_FILTER_CUSTOM 0x02U // The PCAN filter is custom configured. Only registered messages will be received
  164. #define PCAN_CHANNEL_UNAVAILABLE 0x00U // The PCAN-Channel handle is illegal, or its associated hardware is not available
  165. #define PCAN_CHANNEL_AVAILABLE 0x01U // The PCAN-Channel handle is available to be connected (Plug&Play Hardware: it means furthermore that the hardware is plugged-in)
  166. #define PCAN_CHANNEL_OCCUPIED 0x02U // The PCAN-Channel handle is valid, and is already being used
  167. #define PCAN_CHANNEL_PCANVIEW (PCAN_CHANNEL_AVAILABLE | PCAN_CHANNEL_OCCUPIED) // The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect
  168. #define LOG_FUNCTION_DEFAULT 0x00U // Logs system exceptions / errors
  169. #define LOG_FUNCTION_ENTRY 0x01U // Logs the entries to the PCAN-Basic API functions
  170. #define LOG_FUNCTION_PARAMETERS 0x02U // Logs the parameters passed to the PCAN-Basic API functions
  171. #define LOG_FUNCTION_LEAVE 0x04U // Logs the exits from the PCAN-Basic API functions
  172. #define LOG_FUNCTION_WRITE 0x08U // Logs the CAN messages passed to the CAN_Write function
  173. #define LOG_FUNCTION_READ 0x10U // Logs the CAN messages received within the CAN_Read function
  174. #define LOG_FUNCTION_ALL 0xFFFFU // Logs all possible information within the PCAN-Basic API functions
  175. #define TRACE_FILE_SINGLE 0x00U // A single file is written until it size reaches PAN_TRACE_SIZE
  176. #define TRACE_FILE_SEGMENTED 0x01U // Traced data is distributed in several files with size PAN_TRACE_SIZE
  177. #define TRACE_FILE_DATE 0x02U // Includes the date into the name of the trace file
  178. #define TRACE_FILE_TIME 0x04U // Includes the start time into the name of the trace file
  179. #define TRACE_FILE_OVERWRITE 0x80U // Causes the overwriting of available traces (same name)
  180. #define FEATURE_FD_CAPABLE 0x01U // Device supports flexible data-rate (CAN-FD)
  181. // PCAN message types
  182. //
  183. #define PCAN_MESSAGE_STANDARD 0x00U // The PCAN message is a CAN Standard Frame (11-bit identifier)
  184. #define PCAN_MESSAGE_RTR 0x01U // The PCAN message is a CAN Remote-Transfer-Request Frame
  185. #define PCAN_MESSAGE_EXTENDED 0x02U // The PCAN message is a CAN Extended Frame (29-bit identifier)
  186. #define PCAN_MESSAGE_FD 0x04U // The PCAN message represents a FD frame in terms of CiA Specs
  187. #define PCAN_MESSAGE_BRS 0x08U // The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate)
  188. #define PCAN_MESSAGE_ESI 0x10U // The PCAN message represents a FD error state indicator(CAN FD transmitter was error active)
  189. #define PCAN_MESSAGE_STATUS 0x80U // The PCAN message represents a PCAN status message
  190. // Frame Type / Initialization Mode
  191. //
  192. #define PCAN_MODE_STANDARD PCAN_MESSAGE_STANDARD
  193. #define PCAN_MODE_EXTENDED PCAN_MESSAGE_EXTENDED
  194. // Baud rate codes = BTR0/BTR1 register values for the CAN controller.
  195. // You can define your own Baud rate with the BTROBTR1 register.
  196. // Take a look at www.peak-system.com for our free software "BAUDTOOL"
  197. // to calculate the BTROBTR1 register for every bit rate and sample point.
  198. //
  199. #define PCAN_BAUD_1M 0x0014U // 1 MBit/s
  200. #define PCAN_BAUD_800K 0x0016U // 800 kBit/s
  201. #define PCAN_BAUD_500K 0x001CU // 500 kBit/s
  202. #define PCAN_BAUD_250K 0x011CU // 250 kBit/s
  203. #define PCAN_BAUD_125K 0x031CU // 125 kBit/s
  204. #define PCAN_BAUD_100K 0x432FU // 100 kBit/s
  205. #define PCAN_BAUD_95K 0xC34EU // 95,238 kBit/s
  206. #define PCAN_BAUD_83K 0x852BU // 83,333 kBit/s
  207. #define PCAN_BAUD_50K 0x472FU // 50 kBit/s
  208. #define PCAN_BAUD_47K 0x1414U // 47,619 kBit/s
  209. #define PCAN_BAUD_33K 0x8B2FU // 33,333 kBit/s
  210. #define PCAN_BAUD_20K 0x532FU // 20 kBit/s
  211. #define PCAN_BAUD_10K 0x672FU // 10 kBit/s
  212. #define PCAN_BAUD_5K 0x7F7FU // 5 kBit/s
  213. // Represents the configuration for a CAN bit rate
  214. // Note:
  215. // * Each parameter and its value must be separated with a '='.
  216. // * Each pair of parameter/value must be separated using ','.
  217. //
  218. // Example:
  219. // f_clock=80000000,nom_brp=0,nom_tseg1=13,nom_tseg2=0,nom_sjw=0,data_brp=0,data_tseg1=13,data_tseg2=0,data_sjw=0
  220. //
  221. #define PCAN_BR_CLOCK __T("f_clock")
  222. #define PCAN_BR_CLOCK_MHZ __T("f_clock_mhz")
  223. #define PCAN_BR_NOM_BRP __T("nom_brp")
  224. #define PCAN_BR_NOM_TSEG1 __T("nom_tseg1")
  225. #define PCAN_BR_NOM_TSEG2 __T("nom_tseg2")
  226. #define PCAN_BR_NOM_SJW __T("nom_sjw")
  227. #define PCAN_BR_NOM_SAMPLE __T("nom_sam")
  228. #define PCAN_BR_DATA_BRP __T("data_brp")
  229. #define PCAN_BR_DATA_TSEG1 __T("data_tseg1")
  230. #define PCAN_BR_DATA_TSEG2 __T("data_tseg2")
  231. #define PCAN_BR_DATA_SJW __T("data_sjw")
  232. #define PCAN_BR_DATA_SAMPLE __T("data_ssp_offset")
  233. // Type of PCAN (non plug&play) hardware
  234. //
  235. #define PCAN_TYPE_ISA 0x01U // PCAN-ISA 82C200
  236. #define PCAN_TYPE_ISA_SJA 0x09U // PCAN-ISA SJA1000
  237. #define PCAN_TYPE_ISA_PHYTEC 0x04U // PHYTEC ISA
  238. #define PCAN_TYPE_DNG 0x02U // PCAN-Dongle 82C200
  239. #define PCAN_TYPE_DNG_EPP 0x03U // PCAN-Dongle EPP 82C200
  240. #define PCAN_TYPE_DNG_SJA 0x05U // PCAN-Dongle SJA1000
  241. #define PCAN_TYPE_DNG_SJA_EPP 0x06U // PCAN-Dongle EPP SJA1000
  242. ////////////////////////////////////////////////////////////
  243. // Type definitions
  244. ////////////////////////////////////////////////////////////
  245. #define TPCANHandle WORD // Represents a PCAN hardware channel handle
  246. #define TPCANStatus DWORD // Represents a PCAN status/error code
  247. #define TPCANParameter BYTE // Represents a PCAN parameter to be read or set
  248. #define TPCANDevice BYTE // Represents a PCAN device
  249. #define TPCANMessageType BYTE // Represents the type of a PCAN message
  250. #define TPCANType BYTE // Represents the type of PCAN hardware to be initialized
  251. #define TPCANMode BYTE // Represents a PCAN filter mode
  252. #define TPCANBaudrate WORD // Represents a PCAN Baud rate register value
  253. #define TPCANBitrateFD LPSTR // Represents a PCAN-FD bit rate string
  254. #define TPCANTimestampFD UINT64 // Represents a timestamp of a received PCAN FD message
  255. ////////////////////////////////////////////////////////////
  256. // Structure definitions
  257. ////////////////////////////////////////////////////////////
  258. // Represents a PCAN message
  259. //
  260. typedef struct tagTPCANMsg
  261. {
  262. DWORD ID; // 11/29-bit message identifier
  263. TPCANMessageType MSGTYPE; // Type of the message
  264. BYTE LEN; // Data Length Code of the message (0..8)
  265. BYTE DATA[8]; // Data of the message (DATA[0]..DATA[7])
  266. } TPCANMsg;
  267. // Represents a timestamp of a received PCAN message
  268. // Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow
  269. //
  270. typedef struct tagTPCANTimestamp
  271. {
  272. DWORD millis; // Base-value: milliseconds: 0.. 2^32-1
  273. WORD millis_overflow; // Roll-arounds of millis
  274. WORD micros; // Microseconds: 0..999
  275. } TPCANTimestamp;
  276. // Represents a PCAN message from a FD capable hardware
  277. //
  278. typedef struct tagTPCANMsgFD
  279. {
  280. DWORD ID; // 11/29-bit message identifier
  281. TPCANMessageType MSGTYPE; // Type of the message
  282. BYTE DLC; // Data Length Code of the message (0..15)
  283. BYTE DATA[64]; // Data of the message (DATA[0]..DATA[63])
  284. } TPCANMsgFD;
  285. #ifdef __cplusplus
  286. extern "C" {
  287. #define _DEF_ARG =0
  288. #else
  289. #define _DEF_ARG
  290. #endif
  291. ////////////////////////////////////////////////////////////
  292. // PCAN-Basic API function declarations
  293. ////////////////////////////////////////////////////////////
  294. /// <summary>
  295. /// Initializes a PCAN Channel
  296. /// </summary>
  297. /// <param name="Channel">"The handle of a PCAN Channel"</param>
  298. /// <param name="Btr0Btr1">"The speed for the communication (BTR0BTR1 code)"</param>
  299. /// <param name="HwType">"NON PLUG&PLAY: The type of hardware and operation mode"</param>
  300. /// <param name="IOPort">"NON PLUG&PLAY: The I/O address for the parallel port"</param>
  301. /// <param name="Interrupt">"NON PLUG&PLAY: Interrupt number of the parallel port"</param>
  302. /// <returns>"A TPCANStatus error code"</returns>
  303. TPCANStatus __stdcall CAN_Initialize(
  304. TPCANHandle Channel,
  305. TPCANBaudrate Btr0Btr1,
  306. TPCANType HwType _DEF_ARG,
  307. DWORD IOPort _DEF_ARG,
  308. WORD Interrupt _DEF_ARG);
  309. /// <summary>
  310. /// Initializes a FD capable PCAN Channel
  311. /// </summary>
  312. /// <param name="Channel">"The handle of a FD capable PCAN Channel"</param>
  313. /// <param name="BitrateFD">"The speed for the communication (FD bit rate string)"</param>
  314. /// <remarks>See PCAN_BR_* values
  315. /// * Parameter and values must be separated by '='
  316. /// * Couples of Parameter/value must be separated by ','
  317. /// * Following Parameter must be filled out: f_clock, data_brp, data_sjw, data_tseg1, data_tseg2,
  318. /// nom_brp, nom_sjw, nom_tseg1, nom_tseg2.
  319. /// * Following Parameters are optional (not used yet): data_ssp_offset, nom_samp
  320. ///</remarks>
  321. /// <example>f_clock_mhz=80,nom_brp=0,nom_tseg1=13,nom_tseg2=0,nom_sjw=0,data_brp=0,
  322. /// data_tseg1=13,data_tseg2=0,data_sjw=0</example>
  323. /// <returns>"A TPCANStatus error code"</returns>
  324. TPCANStatus __stdcall CAN_InitializeFD(
  325. TPCANHandle Channel,
  326. TPCANBitrateFD BitrateFD);
  327. /// <summary>
  328. /// Uninitializes one or all PCAN Channels initialized by CAN_Initialize
  329. /// </summary>
  330. /// <remarks>Giving the TPCANHandle value "PCAN_NONEBUS",
  331. /// uninitialize all initialized channels</remarks>
  332. /// <param name="Channel">"The handle of a PCAN Channel"</param>
  333. /// <returns>"A TPCANStatus error code"</returns>
  334. TPCANStatus __stdcall CAN_Uninitialize(
  335. TPCANHandle Channel);
  336. /// <summary>
  337. /// Resets the receive and transmit queues of the PCAN Channel
  338. /// </summary>
  339. /// <remarks>
  340. /// A reset of the CAN controller is not performed.
  341. /// </remarks>
  342. /// <param name="Channel">"The handle of a PCAN Channel"</param>
  343. /// <returns>"A TPCANStatus error code"</returns>
  344. TPCANStatus __stdcall CAN_Reset(
  345. TPCANHandle Channel);
  346. /// <summary>
  347. /// Gets the current status of a PCAN Channel
  348. /// </summary>
  349. /// <param name="Channel">"The handle of a PCAN Channel"</param>
  350. /// <returns>"A TPCANStatus error code"</returns>
  351. TPCANStatus __stdcall CAN_GetStatus(
  352. TPCANHandle Channel);
  353. /// <summary>
  354. /// Reads a CAN message from the receive queue of a PCAN Channel
  355. /// </summary>
  356. /// <param name="Channel">"The handle of a PCAN Channel"</param>
  357. /// <param name="MessageBuffer">"A TPCANMsg structure buffer to store the CAN message"</param>
  358. /// <param name="TimestampBuffer">"A TPCANTimestamp structure buffer to get
  359. /// the reception time of the message. If this value is not desired, this parameter
  360. /// should be passed as NULL"</param>
  361. /// <returns>"A TPCANStatus error code"</returns>
  362. TPCANStatus __stdcall CAN_Read(
  363. TPCANHandle Channel,
  364. TPCANMsg* MessageBuffer,
  365. TPCANTimestamp* TimestampBuffer);
  366. /// <summary>
  367. /// Reads a CAN message from the receive queue of a FD capable PCAN Channel
  368. /// </summary>
  369. /// <param name="Channel">"The handle of a FD capable PCAN Channel"</param>
  370. /// <param name="MessageBuffer">"A TPCANMsgFD structure buffer to store the CAN message"</param>
  371. /// <param name="TimestampBuffer">"A TPCANTimestampFD buffer to get
  372. /// the reception time of the message. If this value is not desired, this parameter
  373. /// should be passed as NULL"</param>
  374. /// <returns>"A TPCANStatus error code"</returns>
  375. TPCANStatus __stdcall CAN_ReadFD(
  376. TPCANHandle Channel,
  377. TPCANMsgFD* MessageBuffer,
  378. TPCANTimestampFD *TimestampBuffer);
  379. /// <summary>
  380. /// Transmits a CAN message
  381. /// </summary>
  382. /// <param name="Channel">"The handle of a PCAN Channel"</param>
  383. /// <param name="MessageBuffer">"A TPCANMsg buffer with the message to be sent"</param>
  384. /// <returns>"A TPCANStatus error code"</returns>
  385. TPCANStatus __stdcall CAN_Write(
  386. TPCANHandle Channel,
  387. TPCANMsg* MessageBuffer);
  388. /// <summary>
  389. /// Transmits a CAN message over a FD capable PCAN Channel
  390. /// </summary>
  391. /// <param name="Channel">"The handle of a FD capable PCAN Channel"</param>
  392. /// <param name="MessageBuffer">"A TPCANMsgFD buffer with the message to be sent"</param>
  393. /// <returns>"A TPCANStatus error code"</returns>
  394. TPCANStatus __stdcall CAN_WriteFD(
  395. TPCANHandle Channel,
  396. TPCANMsgFD* MessageBuffer);
  397. /// <summary>
  398. /// Configures the reception filter.
  399. /// </summary>
  400. /// <remarks>The message filter will be expanded with every call to
  401. /// this function. If it is desired to reset the filter, please use
  402. /// the CAN_SetValue function</remarks>
  403. /// <param name="Channel">"The handle of a PCAN Channel"</param>
  404. /// <param name="FromID">"The lowest CAN ID to be received"</param>
  405. /// <param name="ToID">"The highest CAN ID to be received"</param>
  406. /// <param name="Mode">"Message type, Standard (11-bit identifier) or
  407. /// Extended (29-bit identifier)"</param>
  408. /// <returns>"A TPCANStatus error code"</returns>
  409. TPCANStatus __stdcall CAN_FilterMessages(
  410. TPCANHandle Channel,
  411. DWORD FromID,
  412. DWORD ToID,
  413. TPCANMode Mode);
  414. /// <summary>
  415. /// Retrieves a PCAN Channel value
  416. /// </summary>
  417. /// <remarks>Parameters can be present or not according with the kind
  418. /// of Hardware (PCAN Channel) being used. If a parameter is not available,
  419. /// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
  420. /// <param name="Channel">"The handle of a PCAN Channel"</param>
  421. /// <param name="Parameter">"The TPCANParameter parameter to get"</param>
  422. /// <param name="Buffer">"Buffer for the parameter value"</param>
  423. /// <param name="BufferLength">"Size in bytes of the buffer"</param>
  424. /// <returns>"A TPCANStatus error code"</returns>
  425. TPCANStatus __stdcall CAN_GetValue(
  426. TPCANHandle Channel,
  427. TPCANParameter Parameter,
  428. void* Buffer,
  429. DWORD BufferLength);
  430. /// <summary>
  431. /// Configures or sets a PCAN Channel value
  432. /// </summary>
  433. /// <remarks>Parameters can be present or not according with the kind
  434. /// of Hardware (PCAN Channel) being used. If a parameter is not available,
  435. /// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
  436. /// <param name="Channel">"The handle of a PCAN Channel"</param>
  437. /// <param name="Parameter">"The TPCANParameter parameter to set"</param>
  438. /// <param name="Buffer">"Buffer with the value to be set"</param>
  439. /// <param name="BufferLength">"Size in bytes of the buffer"</param>
  440. /// <returns>"A TPCANStatus error code"</returns>
  441. TPCANStatus __stdcall CAN_SetValue(
  442. TPCANHandle Channel,
  443. TPCANParameter Parameter,
  444. void* Buffer,
  445. DWORD BufferLength);
  446. /// <summary>
  447. /// Returns a descriptive text of a given TPCANStatus error
  448. /// code, in any desired language
  449. /// </summary>
  450. /// <remarks>The current languages available for translation are:
  451. /// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A),
  452. /// Italian (0x10) and French (0x0C)</remarks>
  453. /// <param name="Error">"A TPCANStatus error code"</param>
  454. /// <param name="Language">"Indicates a 'Primary language ID'"</param>
  455. /// <param name="Buffer">"Buffer for a null terminated char array"</param>
  456. /// <returns>"A TPCANStatus error code"</returns>
  457. TPCANStatus __stdcall CAN_GetErrorText(
  458. TPCANStatus Error,
  459. WORD Language,
  460. LPSTR Buffer);
  461. #ifdef __cplusplus
  462. }
  463. #endif
  464. #endif