source: pacpussensors/trunk/CanGateway/driver/PCANBasic.h@ 85

Last change on this file since 85 was 59, checked in by DHERBOMEZ Gérald, 10 years ago

Integration of new modules:

  • GPS NMEA0183 decoder
  • Span CPT Decoder

Update of:

File size: 18.8 KB
RevLine 
[59]1// PCANBasic.h
2//
3// ~~~~~~~~~~~~
4//
5// PCAN-Basic API
6//
7// ~~~~~~~~~~~~
8//
9// ------------------------------------------------------------------
10// Author : Keneth Wagner
11// Last change: 26.02.2013 Wagner
12//
13// Language: ANSI-C
14// ------------------------------------------------------------------
15//
16// Copyright (C) 1999-2013 PEAK-System Technik GmbH, Darmstadt
17// more Info at http://www.peak-system.com
18//
19#ifndef __PCANBASICH__
20#define __PCANBASICH__
21
22////////////////////////////////////////////////////////////
23// Value definitions
24////////////////////////////////////////////////////////////
25
26// Currently defined and supported PCAN channels
27//
28#define PCAN_NONEBUS 0x00 // Undefined/default value for a PCAN bus
29
30#define PCAN_ISABUS1 0x21 // PCAN-ISA interface, channel 1
31#define PCAN_ISABUS2 0x22 // PCAN-ISA interface, channel 2
32#define PCAN_ISABUS3 0x23 // PCAN-ISA interface, channel 3
33#define PCAN_ISABUS4 0x24 // PCAN-ISA interface, channel 4
34#define PCAN_ISABUS5 0x25 // PCAN-ISA interface, channel 5
35#define PCAN_ISABUS6 0x26 // PCAN-ISA interface, channel 6
36#define PCAN_ISABUS7 0x27 // PCAN-ISA interface, channel 7
37#define PCAN_ISABUS8 0x28 // PCAN-ISA interface, channel 8
38
39#define PCAN_DNGBUS1 0x31 // PCAN-Dongle/LPT interface, channel 1
40
41#define PCAN_PCIBUS1 0x41 // PCAN-PCI interface, channel 1
42#define PCAN_PCIBUS2 0x42 // PCAN-PCI interface, channel 2
43#define PCAN_PCIBUS3 0x43 // PCAN-PCI interface, channel 3
44#define PCAN_PCIBUS4 0x44 // PCAN-PCI interface, channel 4
45#define PCAN_PCIBUS5 0x45 // PCAN-PCI interface, channel 5
46#define PCAN_PCIBUS6 0x46 // PCAN-PCI interface, channel 6
47#define PCAN_PCIBUS7 0x47 // PCAN-PCI interface, channel 7
48#define PCAN_PCIBUS8 0x48 // PCAN-PCI interface, channel 8
49
50#define PCAN_USBBUS1 0x51 // PCAN-USB interface, channel 1
51#define PCAN_USBBUS2 0x52 // PCAN-USB interface, channel 2
52#define PCAN_USBBUS3 0x53 // PCAN-USB interface, channel 3
53#define PCAN_USBBUS4 0x54 // PCAN-USB interface, channel 4
54#define PCAN_USBBUS5 0x55 // PCAN-USB interface, channel 5
55#define PCAN_USBBUS6 0x56 // PCAN-USB interface, channel 6
56#define PCAN_USBBUS7 0x57 // PCAN-USB interface, channel 7
57#define PCAN_USBBUS8 0x58 // PCAN-USB interface, channel 8
58
59#define PCAN_PCCBUS1 0x61 // PCAN-PC Card interface, channel 1
60#define PCAN_PCCBUS2 0x62 // PCAN-PC Card interface, channel 2
61
62// Represent the PCAN error and status codes
63//
64#define PCAN_ERROR_OK 0x00000 // No error
65#define PCAN_ERROR_XMTFULL 0x00001 // Transmit buffer in CAN controller is full
66#define PCAN_ERROR_OVERRUN 0x00002 // CAN controller was read too late
67#define PCAN_ERROR_BUSLIGHT 0x00004 // Bus error: an error counter reached the 'light' limit
68#define PCAN_ERROR_BUSHEAVY 0x00008 // Bus error: an error counter reached the 'heavy' limit
69#define PCAN_ERROR_BUSOFF 0x00010 // Bus error: the CAN controller is in bus-off state
70#define PCAN_ERROR_ANYBUSERR (PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF) // Mask for all bus errors
71#define PCAN_ERROR_QRCVEMPTY 0x00020 // Receive queue is empty
72#define PCAN_ERROR_QOVERRUN 0x00040 // Receive queue was read too late
73#define PCAN_ERROR_QXMTFULL 0x00080 // Transmit queue is full
74#define PCAN_ERROR_REGTEST 0x00100 // Test of the CAN controller hardware registers failed (no hardware found)
75#define PCAN_ERROR_NODRIVER 0x00200 // Driver not loaded
76#define PCAN_ERROR_HWINUSE 0x00400 // Hardware already in use by a Net
77#define PCAN_ERROR_NETINUSE 0x00800 // A Client is already connected to the Net
78#define PCAN_ERROR_ILLHW 0x01400 // Hardware handle is invalid
79#define PCAN_ERROR_ILLNET 0x01800 // Net handle is invalid
80#define PCAN_ERROR_ILLCLIENT 0x01C00 // Client handle is invalid
81#define PCAN_ERROR_ILLHANDLE (PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT) // Mask for all handle errors
82#define PCAN_ERROR_RESOURCE 0x02000 // Resource (FIFO, Client, timeout) cannot be created
83#define PCAN_ERROR_ILLPARAMTYPE 0x04000 // Invalid parameter
84#define PCAN_ERROR_ILLPARAMVAL 0x08000 // Invalid parameter value
85#define PCAN_ERROR_UNKNOWN 0x10000 // Unknow error
86#define PCAN_ERROR_ILLDATA 0x20000 // Invalid data, function, or action
87#define PCAN_ERROR_INITIALIZE 0x40000 // Channel is not initialized
88#define PCAN_ERROR_ILLOPERATION 0x80000 // Invalid operation
89
90// PCAN devices
91//
92#define PCAN_NONE 0x00 // Undefined, unknown or not selected PCAN device value
93#define PCAN_PEAKCAN 0x01 // PCAN Non-Plug&Play devices. NOT USED WITHIN PCAN-Basic API
94#define PCAN_ISA 0x02 // PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus
95#define PCAN_DNG 0x03 // PCAN-Dongle
96#define PCAN_PCI 0x04 // PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express
97#define PCAN_USB 0x05 // PCAN-USB and PCAN-USB Pro
98#define PCAN_PCC 0x06 // PCAN-PC Card
99
100// PCAN parameters
101//
102#define PCAN_DEVICE_NUMBER 0x01 // PCAN-USB device number parameter
103#define PCAN_5VOLTS_POWER 0x02 // PCAN-PC Card 5-Volt power parameter
104#define PCAN_RECEIVE_EVENT 0x03 // PCAN receive event handler parameter
105#define PCAN_MESSAGE_FILTER 0x04 // PCAN message filter parameter
106#define PCAN_API_VERSION 0x05 // PCAN-Basic API version parameter
107#define PCAN_CHANNEL_VERSION 0x06 // PCAN device channel version parameter
108#define PCAN_BUSOFF_AUTORESET 0x07 // PCAN Reset-On-Busoff parameter
109#define PCAN_LISTEN_ONLY 0x08 // PCAN Listen-Only parameter
110#define PCAN_LOG_LOCATION 0x09 // Directory path for log files
111#define PCAN_LOG_STATUS 0x0A // Debug-Log activation status
112#define PCAN_LOG_CONFIGURE 0x0B // Configuration of the debugged information (LOG_FUNCTION_***)
113#define PCAN_LOG_TEXT 0x0C // Custom insertion of text into the log file
114#define PCAN_CHANNEL_CONDITION 0x0D // Availability status of a PCAN-Channel
115#define PCAN_HARDWARE_NAME 0x0E // PCAN hardware name parameter
116#define PCAN_RECEIVE_STATUS 0x0F // Message reception status of a PCAN-Channel
117#define PCAN_CONTROLLER_NUMBER 0x10 // CAN-Controller number of a PCAN-Channel
118#define PCAN_TRACE_LOCATION 0x11 // Directory path for PCAN trace files
119#define PCAN_TRACE_STATUS 0x12 // CAN tracing activation status
120#define PCAN_TRACE_SIZE 0x13 // Configuration of the maximum file size of a CAN trace
121#define PCAN_TRACE_CONFIGURE 0x14 // Configuration of the trace file storing mode (TRACE_FILE_***)
122#define PCAN_CHANNEL_IDENTIFYING 0x15 // Phisical identification of a USB based PCAN-Channel by blinking its associated LED
123
124// PCAN parameter values
125//
126#define PCAN_PARAMETER_OFF 0x00 // The PCAN parameter is not set (inactive)
127#define PCAN_PARAMETER_ON 0x01 // The PCAN parameter is set (active)
128#define PCAN_FILTER_CLOSE 0x00 // The PCAN filter is closed. No messages will be received
129#define PCAN_FILTER_OPEN 0x01 // The PCAN filter is fully opened. All messages will be received
130#define PCAN_FILTER_CUSTOM 0x02 // The PCAN filter is custom configured. Only registered messages will be received
131#define PCAN_CHANNEL_UNAVAILABLE 0x00 // The PCAN-Channel handle is illegal, or its associated hadware is not available
132#define PCAN_CHANNEL_AVAILABLE 0x01 // The PCAN-Channel handle is available to be connected (Plug&Play Hardware: it means futhermore that the hardware is plugged-in)
133#define PCAN_CHANNEL_OCCUPIED 0x02 // The PCAN-Channel handle is valid, and is already being used
134
135#define LOG_FUNCTION_DEFAULT 0x00 // Logs system exceptions / errors
136#define LOG_FUNCTION_ENTRY 0x01 // Logs the entries to the PCAN-Basic API functions
137#define LOG_FUNCTION_PARAMETERS 0x02 // Logs the parameters passed to the PCAN-Basic API functions
138#define LOG_FUNCTION_LEAVE 0x04 // Logs the exits from the PCAN-Basic API functions
139#define LOG_FUNCTION_WRITE 0x08 // Logs the CAN messages passed to the CAN_Write function
140#define LOG_FUNCTION_READ 0x10 // Logs the CAN messages received within the CAN_Read function
141#define LOG_FUNCTION_ALL 0xFFFF // Logs all possible information within the PCAN-Basic API functions
142
143#define TRACE_FILE_SINGLE 0x00 // A single file is written until it size reaches PAN_TRACE_SIZE
144#define TRACE_FILE_SEGMENTED 0x01 // Traced data is distributed in several files with size PAN_TRACE_SIZE
145#define TRACE_FILE_DATE 0x02 // Includes the date into the name of the trace file
146#define TRACE_FILE_TIME 0x04 // Includes the start time into the name of the trace file
147#define TRACE_FILE_OVERWRITE 0x80 // Causes the overwriting of available traces (same name)
148
149// PCAN message types
150//
151#define PCAN_MESSAGE_STANDARD 0x00 // The PCAN message is a CAN Standard Frame (11-bit identifier)
152#define PCAN_MESSAGE_RTR 0x01 // The PCAN message is a CAN Remote-Transfer-Request Frame
153#define PCAN_MESSAGE_EXTENDED 0x02 // The PCAN message is a CAN Extended Frame (29-bit identifier)
154#define PCAN_MESSAGE_STATUS 0x80 // The PCAN message represents a PCAN status message
155
156// Frame Type / Initialization Mode
157//
158#define PCAN_MODE_STANDARD PCAN_MESSAGE_STANDARD
159#define PCAN_MODE_EXTENDED PCAN_MESSAGE_EXTENDED
160
161// Baud rate codes = BTR0/BTR1 register values for the CAN controller.
162// You can define your own Baud rate with the BTROBTR1 register.
163// Take a look at www.peak-system.com for our free software "BAUDTOOL"
164// to calculate the BTROBTR1 register for every baudrate and sample point.
165//
166#define PCAN_BAUD_1M 0x0014 // 1 MBit/s
167#define PCAN_BAUD_800K 0x0016 // 800 kBit/s
168#define PCAN_BAUD_500K 0x001C // 500 kBit/s
169#define PCAN_BAUD_250K 0x011C // 250 kBit/s
170#define PCAN_BAUD_125K 0x031C // 125 kBit/s
171#define PCAN_BAUD_100K 0x432F // 100 kBit/s
172#define PCAN_BAUD_95K 0xC34E // 95,238 kBit/s
173#define PCAN_BAUD_83K 0x852B // 83,333 kBit/s
174#define PCAN_BAUD_50K 0x472F // 50 kBit/s
175#define PCAN_BAUD_47K 0x1414 // 47,619 kBit/s
176#define PCAN_BAUD_33K 0x8B2F // 33,333 kBit/s
177#define PCAN_BAUD_20K 0x532F // 20 kBit/s
178#define PCAN_BAUD_10K 0x672F // 10 kBit/s
179#define PCAN_BAUD_5K 0x7F7F // 5 kBit/s
180
181#define PCAN_TYPE_ISA 0x01 // PCAN-ISA 82C200
182#define PCAN_TYPE_ISA_SJA 0x09 // PCAN-ISA SJA1000
183#define PCAN_TYPE_ISA_PHYTEC 0x04 // PHYTEC ISA
184#define PCAN_TYPE_DNG 0x02 // PCAN-Dongle 82C200
185#define PCAN_TYPE_DNG_EPP 0x03 // PCAN-Dongle EPP 82C200
186#define PCAN_TYPE_DNG_SJA 0x05 // PCAN-Dongle SJA1000
187#define PCAN_TYPE_DNG_SJA_EPP 0x06 // PCAN-Dongle EPP SJA1000
188
189////////////////////////////////////////////////////////////
190// Type definitions
191////////////////////////////////////////////////////////////
192
193#define TPCANHandle BYTE // Represents a PCAN hardware channel handle
194#define TPCANStatus DWORD // Represents a PCAN status/error code
195#define TPCANParameter BYTE // Represents a PCAN parameter to be read or set
196#define TPCANDevice BYTE // Represents a PCAN device
197#define TPCANMessageType BYTE // Represents the type of a PCAN message
198#define TPCANType BYTE // Represents the type of PCAN hardware to be initialized
199#define TPCANMode BYTE // Represents a PCAN filter mode
200#define TPCANBaudrate WORD // Represents a PCAN Baud rate register value
201
202////////////////////////////////////////////////////////////
203// Structure definitions
204////////////////////////////////////////////////////////////
205
206// Represents a PCAN message
207//
208typedef struct tagTPCANMsg
209{
210 DWORD ID; // 11/29-bit message identifier
211 TPCANMessageType MSGTYPE; // Type of the message
212 BYTE LEN; // Data Length Code of the message (0..8)
213 BYTE DATA[8]; // Data of the message (DATA[0]..DATA[7])
214} TPCANMsg;
215
216// Represents a timestamp of a received PCAN message
217// Total Microseconds = micros + 1000 * millis + 0xFFFFFFFF * 1000 * millis_overflow
218//
219typedef struct tagTPCANTimestamp
220{
221 DWORD millis; // Base-value: milliseconds: 0.. 2^32-1
222 WORD millis_overflow; // Roll-arounds of millis
223 WORD micros; // Microseconds: 0..999
224} TPCANTimestamp;
225
226#ifdef __cplusplus
227extern "C" {
228#define _DEF_ARG =0
229#else
230#define _DEF_ARG
231#endif
232
233////////////////////////////////////////////////////////////
234// PCAN-Basic API function declarations
235////////////////////////////////////////////////////////////
236
237
238/// <summary>
239/// Initializes a PCAN Channel
240/// </summary>
241/// <param name="Channel">"The handle of a PCAN Channel"</param>
242/// <param name="Btr0Btr1">"The speed for the communication (BTR0BTR1 code)"</param>
243/// <param name="HwType">"NON PLUG&PLAY: The type of hardware and operation mode"</param>
244/// <param name="IOPort">"NON PLUG&PLAY: The I/O address for the parallel port"</param>
245/// <param name="Interupt">"NON PLUG&PLAY: Interrupt number of the parallel port"</param>
246/// <returns>"A TPCANStatus error code"</returns>
247TPCANStatus __stdcall CAN_Initialize(
248 TPCANHandle Channel,
249 TPCANBaudrate Btr0Btr1,
250 TPCANType HwType _DEF_ARG,
251 DWORD IOPort _DEF_ARG,
252 WORD Interrupt _DEF_ARG);
253
254
255/// <summary>
256/// Uninitializes one or all PCAN Channels initialized by CAN_Initialize
257/// </summary>
258/// <remarks>Giving the TPCANHandle value "PCAN_NONEBUS",
259/// uninitialize all initialized channels</remarks>
260/// <param name="Channel">"The handle of a PCAN Channel"</param>
261/// <returns>"A TPCANStatus error code"</returns>
262TPCANStatus __stdcall CAN_Uninitialize(
263 TPCANHandle Channel);
264
265
266/// <summary>
267/// Resets the receive and transmit queues of the PCAN Channel
268/// </summary>
269/// <remarks>
270/// A reset of the CAN controller is not performed.
271/// </remarks>
272/// <param name="Channel">"The handle of a PCAN Channel"</param>
273/// <returns>"A TPCANStatus error code"</returns>
274TPCANStatus __stdcall CAN_Reset(
275 TPCANHandle Channel);
276
277
278/// <summary>
279/// Gets the current status of a PCAN Channel
280/// </summary>
281/// <param name="Channel">"The handle of a PCAN Channel"</param>
282/// <returns>"A TPCANStatus error code"</returns>
283TPCANStatus __stdcall CAN_GetStatus(
284 TPCANHandle Channel);
285
286
287/// <summary>
288/// Reads a CAN message from the receive queue of a PCAN Channel
289/// </summary>
290/// <param name="Channel">"The handle of a PCAN Channel"</param>
291/// <param name="MessageBuffer">"A TPCANMsg structure buffer to store the CAN message"</param>
292/// <param name="TimestampBuffer">"A TPCANTimestamp structure buffer to get
293/// the reception time of the message. If this value is not desired, this parameter
294/// should be passed as NULL"</param>
295/// <returns>"A TPCANStatus error code"</returns>
296TPCANStatus __stdcall CAN_Read(
297 TPCANHandle Channel,
298 TPCANMsg* MessageBuffer,
299 TPCANTimestamp* TimestampBuffer);
300
301
302/// <summary>
303/// Transmits a CAN message
304/// </summary>
305/// <param name="Channel">"The handle of a PCAN Channel"</param>
306/// <param name="MessageBuffer">"A TPCANMsg buffer with the message to be sent"</param>
307/// <returns>"A TPCANStatus error code"</returns>
308TPCANStatus __stdcall CAN_Write(
309 TPCANHandle Channel,
310 TPCANMsg* MessageBuffer);
311
312
313/// <summary>
314/// Configures the reception filter.
315/// </summary>
316/// <remarks>The message filter will be expanded with every call to
317/// this function. If it is desired to reset the filter, please use
318/// the CAN_SetValue function</remarks>
319/// <param name="Channel">"The handle of a PCAN Channel"</param>
320/// <param name="FromID">"The lowest CAN ID to be received"</param>
321/// <param name="ToID">"The highest CAN ID to be received"</param>
322/// <param name="Mode">"Message type, Standard (11-bit identifier) or
323/// Extended (29-bit identifier)"</param>
324/// <returns>"A TPCANStatus error code"</returns>
325TPCANStatus __stdcall CAN_FilterMessages(
326 TPCANHandle Channel,
327 DWORD FromID,
328 DWORD ToID,
329 TPCANMode Mode);
330
331
332/// <summary>
333/// Retrieves a PCAN Channel value
334/// </summary>
335/// <remarks>Parameters can be present or not according with the kind
336/// of Hardware (PCAN Channel) being used. If a parameter is not available,
337/// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
338/// <param name="Channel">"The handle of a PCAN Channel"</param>
339/// <param name="Parameter">"The TPCANParameter parameter to get"</param>
340/// <param name="Buffer">"Buffer for the parameter value"</param>
341/// <param name="BufferLength">"Size in bytes of the buffer"</param>
342/// <returns>"A TPCANStatus error code"</returns>
343TPCANStatus __stdcall CAN_GetValue(
344 TPCANHandle Channel,
345 TPCANParameter Parameter,
346 void* Buffer,
347 DWORD BufferLength);
348
349
350/// <summary>
351/// Configures or sets a PCAN Channel value
352/// </summary>
353/// <remarks>Parameters can be present or not according with the kind
354/// of Hardware (PCAN Channel) being used. If a parameter is not available,
355/// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
356/// <param name="Channel">"The handle of a PCAN Channel"</param>
357/// <param name="Parameter">"The TPCANParameter parameter to set"</param>
358/// <param name="Buffer">"Buffer with the value to be set"</param>
359/// <param name="BufferLength">"Size in bytes of the buffer"</param>
360/// <returns>"A TPCANStatus error code"</returns>
361TPCANStatus __stdcall CAN_SetValue(
362 TPCANHandle Channel,
363 TPCANParameter Parameter,
364 void* Buffer,
365 DWORD BufferLength);
366
367
368/// <summary>
369/// Returns a descriptive text of a given TPCANStatus error
370/// code, in any desired language
371/// </summary>
372/// <remarks>The current languages available for translation are:
373/// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A),
374/// Italian (0x10) and French (0x0C)</remarks>
375/// <param name="Error">"A TPCANStatus error code"</param>
376/// <param name="Language">"Indicates a 'Primary language ID'"</param>
377/// <param name="Buffer">"Buffer for a null terminated char array"</param>
378/// <returns>"A TPCANStatus error code"</returns>
379TPCANStatus __stdcall CAN_GetErrorText(
380 TPCANStatus Error,
381 WORD Language,
382 LPSTR Buffer);
383
384#ifdef __cplusplus
385}
386#endif
387
388#endif
Note: See TracBrowser for help on using the repository browser.