source: pacpussensors/trunk/CanGateway/driver/PCANBasicCLR.h@ 69

Last change on this file since 69 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: 29.5 KB
Line 
1// PCANBasicCLR.h
2//
3// ~~~~~~~~~~~~
4//
5// PCAN-Basic API
6//
7// ~~~~~~~~~~~~
8//
9// ------------------------------------------------------------------
10// Author : Keneth Wagner
11// Last change: 13.03.2013 Wagner
12//
13// Language: C++/CLR
14// ------------------------------------------------------------------
15//
16// Copyright (C) 1999-2013 PEAK-System Technik GmbH, Darmstadt
17// more Info at http://www.peak-system.com
18//
19using namespace System;
20using namespace System::Text;
21using namespace System::Runtime::InteropServices;
22
23////////////////////////////////////////////////////////////
24// Type definitions
25////////////////////////////////////////////////////////////
26#define TPCANHandle System::Byte // Represents a PCAN hardware channel handle
27
28namespace Peak
29{
30 namespace Can
31 {
32 namespace Basic
33 {
34 #pragma region Enumerations
35 /// <summary>
36 /// Represents a PCAN status/error code
37 /// </summary>
38 [Flags]
39 public enum class TPCANStatus : UInt32
40 {
41 /// <summary>
42 /// No error
43 /// </summary>
44 PCAN_ERROR_OK = 0x00000,
45 /// <summary>
46 /// Transmit buffer in CAN controller is full
47 /// </summary>
48 PCAN_ERROR_XMTFULL = 0x00001,
49 /// <summary>
50 /// CAN controller was read too late
51 /// </summary>
52 PCAN_ERROR_OVERRUN = 0x00002,
53 /// <summary>
54 /// Bus error: an error counter reached the 'light' limit
55 /// </summary>
56 PCAN_ERROR_BUSLIGHT = 0x00004,
57 /// <summary>
58 /// Bus error: an error counter reached the 'heavy' limit
59 /// </summary>
60 PCAN_ERROR_BUSHEAVY = 0x00008,
61 /// <summary>
62 /// Bus error: the CAN controller is in bus-off state
63 /// </summary>
64 PCAN_ERROR_BUSOFF = 0x00010,
65 /// <summary>
66 /// Mask for all bus errors
67 /// </summary>
68 PCAN_ERROR_ANYBUSERR = (PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF),
69 /// <summary>
70 /// Receive queue is empty
71 /// </summary>
72 PCAN_ERROR_QRCVEMPTY = 0x00020,
73 /// <summary>
74 /// Receive queue was read too late
75 /// </summary>
76 PCAN_ERROR_QOVERRUN = 0x00040,
77 /// <summary>
78 /// Transmit queue is full
79 /// </summary>
80 PCAN_ERROR_QXMTFULL = 0x00080,
81 /// <summary>
82 /// Test of the CAN controller hardware registers failed (no hardware found)
83 /// </summary>
84 PCAN_ERROR_REGTEST = 0x00100,
85 /// <summary>
86 /// Driver not loaded
87 /// </summary>
88 PCAN_ERROR_NODRIVER = 0x00200,
89 /// <summary>
90 /// Hardware already in use by a Net
91 /// </summary>
92 PCAN_ERROR_HWINUSE = 0x00400,
93 /// <summary>
94 /// A Client is already connected to the Net
95 /// </summary>
96 PCAN_ERROR_NETINUSE = 0x00800,
97 /// <summary>
98 /// Hardware handle is invalid
99 /// </summary>
100 PCAN_ERROR_ILLHW = 0x01400,
101 /// <summary>
102 /// Net handle is invalid
103 /// </summary>
104 PCAN_ERROR_ILLNET = 0x01800,
105 /// <summary>
106 /// Client handle is invalid
107 /// </summary>
108 PCAN_ERROR_ILLCLIENT = 0x01C00,
109 /// <summary>
110 /// Mask for all handle errors
111 /// </summary>
112 PCAN_ERROR_ILLHANDLE = (PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT),
113 /// <summary>
114 /// Resource (FIFO, Client, timeout) cannot be created
115 /// </summary>
116 PCAN_ERROR_RESOURCE = 0x02000,
117 /// <summary>
118 /// Invalid parameter
119 /// </summary>
120 PCAN_ERROR_ILLPARAMTYPE = 0x04000,
121 /// <summary>
122 /// Invalid parameter value
123 /// </summary>
124 PCAN_ERROR_ILLPARAMVAL = 0x08000,
125 /// <summary>
126 /// Unknow error
127 /// </summary>
128 PCAN_ERROR_UNKNOWN = 0x10000,
129 /// <summary>
130 /// Invalid data, function, or action.
131 /// </summary>
132 PCAN_ERROR_ILLDATA = 0x20000,
133 /// <summary>
134 /// Channel is not initialized
135 /// </summary>
136 PCAN_ERROR_INITIALIZE = 0x40000,
137 /// <summary>
138 /// Invalid operation
139 /// </summary>
140 PCAN_ERROR_ILLOPERATION = 0x80000,
141 };
142
143 /// <summary>
144 /// Represents a PCAN device
145 /// </summary>
146 public enum class TPCANDevice : Byte
147 {
148 /// <summary>
149 /// Undefined, unknown or not selected PCAN device value
150 /// </summary>
151 PCAN_NONE = 0,
152 /// <summary>
153 /// PCAN Non-Plug&Play devices. NOT USED WITHIN PCAN-Basic API
154 /// </summary>
155 PCAN_PEAKCAN = 1,
156 /// <summary>
157 /// PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus
158 /// </summary>
159 PCAN_ISA = 2,
160 /// <summary>
161 /// PCAN-Dongle
162 /// </summary>
163 PCAN_DNG = 3,
164 /// <summary>
165 /// PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express
166 /// </summary>
167 PCAN_PCI = 4,
168 /// <summary>
169 /// PCAN-USB and PCAN-USB Pro
170 /// </summary>
171 PCAN_USB = 5,
172 /// <summary>
173 /// PCAN-PC Card
174 /// </summary>
175 PCAN_PCC = 6
176 };
177
178 /// <summary>
179 /// Represents a PCAN parameter to be read or set
180 /// </summary>
181 public enum class TPCANParameter : Byte
182 {
183 /// <summary>
184 /// PCAN-USB device number parameter
185 /// </summary>
186 PCAN_DEVICE_NUMBER = 1,
187 /// <summary>
188 /// PCAN-PC Card 5-Volt power parameter
189 /// </summary>
190 PCAN_5VOLTS_POWER = 2,
191 /// <summary>
192 /// PCAN receive event handler parameter
193 /// </summary>
194 PCAN_RECEIVE_EVENT = 3,
195 /// <summary>
196 /// PCAN message filter parameter
197 /// </summary>
198 PCAN_MESSAGE_FILTER = 4,
199 /// <summary>
200 /// PCAN-Basic API version parameter
201 /// </summary>
202 PCAN_API_VERSION = 5,
203 /// <summary>
204 /// PCAN device channel version parameter
205 /// </summary>
206 PCAN_CHANNEL_VERSION = 6,
207 /// <summary>
208 /// PCAN Reset-On-Busoff parameter
209 /// </summary>
210 PCAN_BUSOFF_AUTORESET = 7,
211 /// <summary>
212 /// PCAN Listen-Only parameter
213 /// </summary>
214 PCAN_LISTEN_ONLY = 8,
215 /// <summary>
216 /// Directory path for log files
217 /// </summary>
218 PCAN_LOG_LOCATION = 9,
219 /// <summary>
220 /// Debug-Log activation status
221 /// </summary>
222 PCAN_LOG_STATUS = 10,
223 /// <summary>
224 /// Configuration of the debugged information (LOG_FUNCTION_***)
225 /// </summary>
226 PCAN_LOG_CONFIGURE = 11,
227 /// <summary>
228 /// Custom insertion of text into the log file
229 /// </summary>
230 PCAN_LOG_TEXT = 12,
231 /// <summary>
232 /// Availability status of a PCAN-Channel
233 /// </summary>
234 PCAN_CHANNEL_CONDITION = 13,
235 /// <summary>
236 /// PCAN hardware name parameter
237 /// </summary>
238 PCAN_HARDWARE_NAME = 14,
239 /// <summary>
240 /// Message reception status of a PCAN-Channel
241 /// </summary>
242 PCAN_RECEIVE_STATUS = 15,
243 /// <summary>
244 /// CAN-Controller number of a PCAN-Channel
245 /// </summary>
246 PCAN_CONTROLLER_NUMBER = 16,
247 /// <summary>
248 /// Directory path for PCAN trace files
249 /// </summary>
250 PCAN_TRACE_LOCATION = 17,
251 /// <summary>
252 /// CAN tracing activation status
253 /// </summary>
254 PCAN_TRACE_STATUS = 18,
255 /// <summary>
256 /// Configuration of the maximum file size of a CAN trace
257 /// </summary>
258 PCAN_TRACE_SIZE = 19,
259 /// <summary>
260 /// Configuration of the trace file storing mode (TRACE_FILE_***)
261 /// </summary>
262 PCAN_TRACE_CONFIGURE = 20,
263 /// <summary>
264 /// Phisical identification of a USB based PCAN-Channel by blinking its associated LED
265 /// </summary>
266 PCAN_CHANNEL_IDENTIFYING = 21,
267 };
268
269 /// <summary>
270 /// Represents the type of a PCAN message
271 /// </summary>
272 [Flags]
273 public enum class TPCANMessageType : Byte
274 {
275 /// <summary>
276 /// The PCAN message is a CAN Standard Frame (11-bit identifier)
277 /// </summary>
278 PCAN_MESSAGE_STANDARD = 0x00,
279 /// <summary>
280 /// The PCAN message is a CAN Remote-Transfer-Request Frame
281 /// </summary>
282 PCAN_MESSAGE_RTR = 0x01,
283 /// <summary>
284 /// The PCAN message is a CAN Extended Frame (29-bit identifier)
285 /// </summary>
286 PCAN_MESSAGE_EXTENDED = 0x02,
287 /// <summary>
288 /// The PCAN message represents a PCAN status message
289 /// </summary>
290 PCAN_MESSAGE_STATUS = 0x80,
291 };
292
293 /// <summary>
294 /// Represents a PCAN filter mode
295 /// </summary>
296 public enum class TPCANMode : Byte
297 {
298 /// <summary>
299 /// Mode is Standard (11-bit identifier)
300 /// </summary>
301 PCAN_MODE_STANDARD = TPCANMessageType::PCAN_MESSAGE_STANDARD,
302 /// <summary>
303 /// Mode is Extended (29-bit identifier)
304 /// </summary>
305 PCAN_MODE_EXTENDED = TPCANMessageType::PCAN_MESSAGE_EXTENDED,
306 };
307
308 /// <summary>
309 /// Represents a PCAN Baud rate register value
310 /// </summary>
311 public enum class TPCANBaudrate : UInt16
312 {
313 /// <summary>
314 /// 1 MBit/s
315 /// </summary>
316 PCAN_BAUD_1M = 0x0014,
317 /// <summary>
318 /// 800 kBit/s
319 /// </summary>
320 PCAN_BAUD_800K = 0x0016,
321 /// <summary>
322 /// 500 kBit/s
323 /// </summary>
324 PCAN_BAUD_500K = 0x001C,
325 /// <summary>
326 /// 250 kBit/s
327 /// </summary>
328 PCAN_BAUD_250K = 0x011C,
329 /// <summary>
330 /// 125 kBit/s
331 /// </summary>
332 PCAN_BAUD_125K = 0x031C,
333 /// <summary>
334 /// 100 kBit/s
335 /// </summary>
336 PCAN_BAUD_100K = 0x432F,
337 /// <summary>
338 /// 95,238 kBit/s
339 /// </summary>
340 PCAN_BAUD_95K = 0xC34E,
341 /// <summary>
342 /// 83,333 kBit/s
343 /// </summary>
344 PCAN_BAUD_83K = 0x852B,
345 /// <summary>
346 /// 50 kBit/s
347 /// </summary>
348 PCAN_BAUD_50K = 0x472F,
349 /// <summary>
350 /// 47,619 kBit/s
351 /// </summary>
352 PCAN_BAUD_47K = 0x1414,
353 /// <summary>
354 /// 33,333 kBit/s
355 /// </summary>
356 PCAN_BAUD_33K = 0x8B2F,
357 /// <summary>
358 /// 20 kBit/s
359 /// </summary>
360 PCAN_BAUD_20K = 0x532F,
361 /// <summary>
362 /// 10 kBit/s
363 /// </summary>
364 PCAN_BAUD_10K = 0x672F,
365 /// <summary>
366 /// 5 kBit/s
367 /// </summary>
368 PCAN_BAUD_5K = 0x7F7F,
369 };
370
371 /// <summary>
372 /// Represents the type of PCAN (non plug&play) hardware to be initialized
373 /// </summary>
374 public enum class TPCANType : Byte
375 {
376 /// <summary>
377 /// PCAN-ISA 82C200
378 /// </summary>
379 PCAN_TYPE_ISA = 0x01,
380 /// <summary>
381 /// PCAN-ISA SJA1000
382 /// </summary>
383 PCAN_TYPE_ISA_SJA = 0x09,
384 /// <summary>
385 /// PHYTEC ISA
386 /// </summary>
387 PCAN_TYPE_ISA_PHYTEC = 0x04,
388 /// <summary>
389 /// PCAN-Dongle 82C200
390 /// </summary>
391 PCAN_TYPE_DNG = 0x02,
392 /// <summary>
393 /// PCAN-Dongle EPP 82C200
394 /// </summary>
395 PCAN_TYPE_DNG_EPP = 0x03,
396 /// <summary>
397 /// PCAN-Dongle SJA1000
398 /// </summary>
399 PCAN_TYPE_DNG_SJA = 0x05,
400 /// <summary>
401 /// PCAN-Dongle EPP SJA1000
402 /// </summary>
403 PCAN_TYPE_DNG_SJA_EPP = 0x06,
404 };
405 #pragma endregion
406
407 #pragma region Strutures
408 /// <summary>
409 /// Represents a PCAN message
410 /// </summary>
411 public value struct TPCANMsg
412 {
413 /// <summary>
414 /// 11/29-bit message identifier
415 /// </summary>
416 UInt32 ID;
417 /// <summary>
418 /// Type of the message
419 /// </summary>
420 [MarshalAs(UnmanagedType::U1)]
421 TPCANMessageType MSGTYPE;
422 /// <summary>
423 /// Data Length Code of the message (0..8)
424 /// </summary>
425 Byte LEN;
426 /// <summary>
427 /// Data of the message (DATA[0]..DATA[7])
428 /// </summary>
429 [MarshalAs(UnmanagedType::ByValArray, SizeConst = 8)]
430 array<Byte>^ DATA;
431 };
432
433 /// <summary>
434 /// Represents a timestamp of a received PCAN message.
435 /// Total Microseconds = micros + 1000 * millis + 0xFFFFFFFF * 1000 * millis_overflow
436 /// </summary>
437 public value struct TPCANTimestamp
438 {
439 /// <summary>
440 /// Base-value: milliseconds: 0.. 2^32-1
441 /// </summary>
442 UInt32 millis;
443 /// <summary>
444 /// Roll-arounds of millis
445 /// </summary>
446 UInt16 millis_overflow;
447 /// <summary>
448 /// Microseconds: 0..999
449 /// </summary>
450 UInt16 micros;
451 };
452 #pragma endregion
453
454 #pragma region PCANBasic class
455 /// <summary>
456 /// PCAN-Basic API class implementation
457 /// </summary>
458 public ref class PCANBasic abstract sealed
459 {
460 public:
461 #pragma region PCAN-BUS Handles Definition
462 /// <summary>
463 /// Undefined/default value for a PCAN bus
464 /// </summary>
465 static const TPCANHandle PCAN_NONEBUS = 0x00;
466
467 /// <summary>
468 /// PCAN-ISA interface, channel 1
469 /// </summary>
470 static const TPCANHandle PCAN_ISABUS1 = 0x21;
471 /// <summary>
472 /// PCAN-ISA interface, channel 2
473 /// </summary>
474 static const TPCANHandle PCAN_ISABUS2 = 0x22;
475 /// <summary>
476 /// PCAN-ISA interface, channel 3
477 /// </summary>
478 static const TPCANHandle PCAN_ISABUS3 = 0x23;
479 /// <summary>
480 /// PCAN-ISA interface, channel 4
481 /// </summary>
482 static const TPCANHandle PCAN_ISABUS4 = 0x24;
483 /// <summary>
484 /// PCAN-ISA interface, channel 5
485 /// </summary>
486 static const TPCANHandle PCAN_ISABUS5 = 0x25;
487 /// <summary>
488 /// PCAN-ISA interface, channel 6
489 /// </summary>
490 static const TPCANHandle PCAN_ISABUS6 = 0x26;
491 /// <summary>
492 /// PCAN-ISA interface, channel 7
493 /// </summary>
494 static const TPCANHandle PCAN_ISABUS7 = 0x27;
495 /// <summary>
496 /// PCAN-ISA interface, channel 8
497 /// </summary>
498 static const TPCANHandle PCAN_ISABUS8 = 0x28;
499
500 /// <summary>
501 /// PPCAN-Dongle/LPT interface, channel 1
502 /// </summary>
503 static const TPCANHandle PCAN_DNGBUS1 = 0x31;
504
505 /// <summary>
506 /// PCAN-PCI interface, channel 1
507 /// </summary>
508 static const TPCANHandle PCAN_PCIBUS1 = 0x41;
509 /// <summary>
510 /// PCAN-PCI interface, channel 2
511 /// </summary>
512 static const TPCANHandle PCAN_PCIBUS2 = 0x42;
513 /// <summary>
514 /// PCAN-PCI interface, channel 3
515 /// </summary>
516 static const TPCANHandle PCAN_PCIBUS3 = 0x43;
517 /// <summary>
518 /// PCAN-PCI interface, channel 4
519 /// </summary>
520 static const TPCANHandle PCAN_PCIBUS4 = 0x44;
521 /// <summary>
522 /// PCAN-PCI interface, channel 5
523 /// </summary>
524 static const TPCANHandle PCAN_PCIBUS5 = 0x45;
525 /// <summary>
526 /// PCAN-PCI interface, channel 6
527 /// </summary>
528 static const TPCANHandle PCAN_PCIBUS6 = 0x46;
529 /// <summary>
530 /// PCAN-PCI interface, channel 7
531 /// </summary>
532 static const TPCANHandle PCAN_PCIBUS7 = 0x47;
533 /// <summary>
534 /// PCAN-PCI interface, channel 8
535 /// </summary>
536 static const TPCANHandle PCAN_PCIBUS8 = 0x48;
537
538 /// <summary>
539 /// PCAN-USB interface, channel 1
540 /// </summary>
541 static const TPCANHandle PCAN_USBBUS1 = 0x51;
542 /// <summary>
543 /// PCAN-USB interface, channel 2
544 /// </summary>
545 static const TPCANHandle PCAN_USBBUS2 = 0x52;
546 /// <summary>
547 /// PCAN-USB interface, channel 3
548 /// </summary>
549 static const TPCANHandle PCAN_USBBUS3 = 0x53;
550 /// <summary>
551 /// PCAN-USB interface, channel 4
552 /// </summary>
553 static const TPCANHandle PCAN_USBBUS4 = 0x54;
554 /// <summary>
555 /// PCAN-USB interface, channel 5
556 /// </summary>
557 static const TPCANHandle PCAN_USBBUS5 = 0x55;
558 /// <summary>
559 /// PCAN-USB interface, channel 6
560 /// </summary>
561 static const TPCANHandle PCAN_USBBUS6 = 0x56;
562 /// <summary>
563 /// PCAN-USB interface, channel 7
564 /// </summary>
565 static const TPCANHandle PCAN_USBBUS7 = 0x57;
566 /// <summary>
567 /// PCAN-USB interface, channel 8
568 /// </summary>
569 static const TPCANHandle PCAN_USBBUS8 = 0x58;
570
571 /// <summary>
572 /// PCAN-PC Card interface, channel 1
573 /// </summary>
574 static const TPCANHandle PCAN_PCCBUS1 = 0x61;
575 /// <summary>
576 /// PCAN-PC Card interface, channel 2
577 /// </summary>
578 static const TPCANHandle PCAN_PCCBUS2 = 0x62;
579 #pragma endregion
580
581 #pragma region Parameter values definition
582 /// <summary>
583 /// The PCAN parameter is not set (inactive)
584 /// </summary>
585 static const int PCAN_PARAMETER_OFF = 0;
586 /// <summary>
587 /// The PCAN parameter is set (active)
588 /// </summary>
589 static const int PCAN_PARAMETER_ON = 1;
590 /// <summary>
591 /// The PCAN filter is closed. No messages will be received
592 /// </summary>
593 static const int PCAN_FILTER_CLOSE = 0;
594 /// <summary>
595 /// The PCAN filter is fully opened. All messages will be received
596 /// </summary>
597 static const int PCAN_FILTER_OPEN = 1;
598 /// <summary>
599 /// The PCAN filter is custom configured. Only registered
600 /// messages will be received
601 /// </summary>
602 static const int PCAN_FILTER_CUSTOM = 2;
603 /// <summary>
604 /// The PCAN-Channel handle is illegal, or its associated hadware is not available
605 /// </summary>
606 static const int PCAN_CHANNEL_UNAVAILABLE = 0;
607 /// <summary>
608 /// The PCAN-Channel handle is available to be connected (Plug&Play Hardware: it means futhermore that the hardware is plugged-in)
609 /// </summary>
610 static const int PCAN_CHANNEL_AVAILABLE = 1;
611 /// <summary>
612 /// The PCAN-Channel handle is valid, and is already being used
613 /// </summary>
614 static const int PCAN_CHANNEL_OCCUPIED = 2;
615
616 /// <summary>
617 /// Logs system exceptions / errors
618 /// </summary>
619 static const int LOG_FUNCTION_DEFAULT = 0x00;
620 /// <summary>
621 /// Logs the entries to the PCAN-Basic API functions
622 /// </summary>
623 static const int LOG_FUNCTION_ENTRY = 0x01;
624 /// <summary>
625 /// Logs the parameters passed to the PCAN-Basic API functions
626 /// </summary>
627 static const int LOG_FUNCTION_PARAMETERS = 0x02;
628 /// <summary>
629 /// Logs the exits from the PCAN-Basic API functions
630 /// </summary>
631 static const int LOG_FUNCTION_LEAVE = 0x04;
632 /// <summary>
633 /// Logs the CAN messages passed to the CAN_Write function
634 /// </summary>
635 static const int LOG_FUNCTION_WRITE = 0x08;
636 /// <summary>
637 /// Logs the CAN messages received within the CAN_Read function
638 /// </summary>
639 static const int LOG_FUNCTION_READ = 0x10;
640 /// <summary>
641 /// Logs all possible information within the PCAN-Basic API functions
642 /// </summary>
643 static const int LOG_FUNCTION_ALL = 0xFFFF;
644
645 /// <summary>
646 /// A single file is written until it size reaches PAN_TRACE_SIZE
647 /// </summary>
648 static const int TRACE_FILE_SINGLE = 0x00;
649 /// <summary>
650 /// Traced data is distributed in several files with size PAN_TRACE_SIZE
651 /// </summary>
652 static const int TRACE_FILE_SEGMENTED = 0x01;
653 /// <summary>
654 /// Includes the date into the name of the trace file
655 /// </summary>
656 static const int TRACE_FILE_DATE = 0x02;
657 /// <summary>
658 /// Includes the start time into the name of the trace file
659 /// </summary>
660 static const int TRACE_FILE_TIME = 0x04;
661 /// <summary>
662 /// Causes the overwriting of available traces (same name)
663 /// </summary>
664 static const int TRACE_FILE_OVERWRITE = 0x80;
665 #pragma endregion
666
667 #pragma region PCANBasic API Implementation
668 /// <summary>
669 /// Initializes a PCAN Channel
670 /// </summary>
671 /// <param name="Channel">The handle of a PCAN Channel</param>
672 /// <param name="Btr0Btr1">The speed for the communication (BTR0BTR1 code)</param>
673 /// <param name="HwType">NON PLUG&PLAY: The type of hardware and operation mode</param>
674 /// <param name="IOPort">NON PLUG&PLAY: The I/O address for the parallel port</param>
675 /// <param name="Interrupt">NON PLUG&PLAY: Interrupt number of the parallel por</param>
676 /// <returns>A TPCANStatus error code</returns>
677 [DllImport("PCANBasic.dll", EntryPoint = "CAN_Initialize")]
678 static TPCANStatus Initialize(
679 [MarshalAs(UnmanagedType::U1)]
680 TPCANHandle Channel,
681 [MarshalAs(UnmanagedType::U2)]
682 TPCANBaudrate Btr0Btr1,
683 [MarshalAs(UnmanagedType::U1)]
684 TPCANType HwType,
685 UInt32 IOPort,
686 UInt16 Interrupt);
687
688 /// <summary>
689 /// Initializes a PCAN Channel
690 /// </summary>
691 /// <param name="Channel">The handle of a PCAN Channel</param>
692 /// <param name="Btr0Btr1">The speed for the communication (BTR0BTR1 code)</param>
693 /// <returns>A TPCANStatus error code</returns>
694 static TPCANStatus Initialize(
695 TPCANHandle Channel,
696 TPCANBaudrate Btr0Btr1)
697 {
698 return Initialize(Channel, Btr0Btr1, (TPCANType)0, 0, 0);
699 }
700
701 /// <summary>
702 /// Uninitializes one or all PCAN Channels initialized by CAN_Initialize
703 /// </summary>
704 /// <remarks>Giving the TPCANHandle value "PCAN_NONEBUS",
705 /// uninitialize all initialized channels</remarks>
706 /// <param name="Channel">The handle of a PCAN Channel</param>
707 /// <returns>A TPCANStatus error code</returns>
708 [DllImport("PCANBasic.dll", EntryPoint = "CAN_Uninitialize")]
709 static TPCANStatus Uninitialize(
710 [MarshalAs(UnmanagedType::U1)]
711 TPCANHandle Channel);
712
713 /// <summary>
714 /// Resets the receive and transmit queues of the PCAN Channel
715 /// </summary>
716 /// <remarks>A reset of the CAN controller is not performed</remarks>
717 /// <param name="Channel">The handle of a PCAN Channel</param>
718 /// <returns>A TPCANStatus error code</returns>
719 [DllImport("PCANBasic.dll", EntryPoint = "CAN_Reset")]
720 static TPCANStatus Reset(
721 [MarshalAs(UnmanagedType::U1)]
722 TPCANHandle Channel);
723
724 /// <summary>
725 /// Gets the current status of a PCAN Channel
726 /// </summary>
727 /// <param name="Channel">The handle of a PCAN Channel</param>
728 /// <returns>A TPCANStatus error code</returns>
729 [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetStatus")]
730 static TPCANStatus GetStatus(
731 [MarshalAs(UnmanagedType::U1)]
732 TPCANHandle Channel);
733
734 /// <summary>
735 /// Reads a CAN message from the receive queue of a PCAN Channel
736 /// </summary>
737 /// <param name="Channel">The handle of a PCAN Channel</param>
738 /// <param name="MessageBuffer">A TPCANMsg structure buffer to store the CAN message</param>
739 /// <param name="TimestampBuffer">A TPCANTimestamp structure buffer to get
740 /// the reception time of the message</param>
741 /// <returns>A TPCANStatus error code</returns>
742 [DllImport("PCANBasic.dll", EntryPoint = "CAN_Read")]
743 static TPCANStatus Read(
744 [MarshalAs(UnmanagedType::U1)]
745 TPCANHandle Channel,
746 TPCANMsg %MessageBuffer,
747 TPCANTimestamp %TimestampBuffer);
748
749 /// <summary>
750 /// Reads a CAN message from the receive queue of a PCAN Channel
751 /// </summary>
752 /// <param name="Channel">The handle of a PCAN Channel</param>
753 /// <param name="MessageBuffer">A TPCANMsg structure buffer to store the CAN message</param>
754 /// <returns>A TPCANStatus error code</returns>
755 [DllImport("PCANBasic.dll", EntryPoint = "CAN_Read")]
756 static TPCANStatus Read(
757 [MarshalAs(UnmanagedType::U1)]
758 TPCANHandle Channel,
759 TPCANMsg %MessageBuffer);
760
761 /// <summary>
762 /// Transmits a CAN message
763 /// </summary>
764 /// <param name="Channel">The handle of a PCAN Channel</param>
765 /// <param name="MessageBuffer">A TPCANMsg buffer with the message to be sent</param>
766 /// <returns>A TPCANStatus error code</returns>
767 [DllImport("PCANBasic.dll", EntryPoint = "CAN_Write")]
768 static TPCANStatus Write(
769 [MarshalAs(UnmanagedType::U1)]
770 TPCANHandle Channel,
771 TPCANMsg %MessageBuffer);
772
773 /// <summary>
774 /// Configures the reception filter
775 /// </summary>
776 /// <remarks>The message filter will be expanded with every call to
777 /// this function. If it is desired to reset the filter, please use
778 /// the 'SetValue' function</remarks>
779 /// <param name="Channel">The handle of a PCAN Channel</param>
780 /// <param name="FromID">The lowest CAN ID to be received</param>
781 /// <param name="ToID">The highest CAN ID to be received</param>
782 /// <param name="Mode">Message type, Standard (11-bit identifier) or
783 /// Extended (29-bit identifier)</param>
784 /// <returns>A TPCANStatus error code</returns>
785 [DllImport("PCANBasic.dll", EntryPoint = "CAN_FilterMessages")]
786 static TPCANStatus FilterMessages(
787 [MarshalAs(UnmanagedType::U1)]
788 TPCANHandle Channel,
789 UInt32 FromID,
790 UInt32 ToID,
791 [MarshalAs(UnmanagedType::U1)]
792 TPCANMode Mode);
793
794 /// <summary>
795 /// Retrieves a PCAN Channel value
796 /// </summary>
797 /// <remarks>Parameters can be present or not according with the kind
798 /// of Hardware (PCAN Channel) being used. If a parameter is not available,
799 /// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
800 /// <param name="Channel">The handle of a PCAN Channel</param>
801 /// <param name="Parameter">The TPCANParameter parameter to get</param>
802 /// <param name="StringBuffer">Buffer for the parameter value</param>
803 /// <param name="BufferLength">Size in bytes of the buffer</param>
804 /// <returns>A TPCANStatus error code</returns>
805 [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")]
806 static TPCANStatus GetValue(
807 [MarshalAs(UnmanagedType::U1)]
808 TPCANHandle Channel,
809 [MarshalAs(UnmanagedType::U1)]
810 TPCANParameter Parameter,
811 StringBuilder^ StringBuffer,
812 UInt32 BufferLength);
813
814 /// <summary>
815 /// Retrieves a PCAN Channel value
816 /// </summary>
817 /// <remarks>Parameters can be present or not according with the kind
818 /// of Hardware (PCAN Channel) being used. If a parameter is not available,
819 /// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
820 /// <param name="Channel">The handle of a PCAN Channel</param>
821 /// <param name="Parameter">The TPCANParameter parameter to get</param>
822 /// <param name="NumericBuffer">Buffer for the parameter value</param>
823 /// <param name="BufferLength">Size in bytes of the buffer</param>
824 /// <returns>A TPCANStatus error code</returns>
825 [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetValue")]
826 static TPCANStatus GetValue(
827 [MarshalAs(UnmanagedType::U1)]
828 TPCANHandle Channel,
829 [MarshalAs(UnmanagedType::U1)]
830 TPCANParameter Parameter,
831 UInt32 %NumericBuffer,
832 UInt32 BufferLength);
833
834 /// <summary>
835 /// Configures a PCAN Channel value
836 /// </summary>
837 /// <remarks>Parameters can be present or not according with the kind
838 /// of Hardware (PCAN Channel) being used. If a parameter is not available,
839 /// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
840 /// <param name="Channel">The handle of a PCAN Channel</param>
841 /// <param name="Parameter">The TPCANParameter parameter to set</param>
842 /// <param name="NumericBuffer">Buffer with the value to be set</param>
843 /// <param name="BufferLength">Size in bytes of the buffer</param>
844 /// <returns>A TPCANStatus error code</returns>
845 [DllImport("PCANBasic.dll", EntryPoint = "CAN_SetValue")]
846 static TPCANStatus SetValue(
847 [MarshalAs(UnmanagedType::U1)]
848 TPCANHandle Channel,
849 [MarshalAs(UnmanagedType::U1)]
850 TPCANParameter Parameter,
851 UInt32% NumericBuffer,
852 UInt32 BufferLength);
853
854 /// <summary>
855 /// Configures a PCAN Channel value
856 /// </summary>
857 /// <remarks>Parameters can be present or not according with the kind
858 /// of Hardware (PCAN Channel) being used. If a parameter is not available,
859 /// a PCAN_ERROR_ILLPARAMTYPE error will be returned</remarks>
860 /// <param name="Channel">The handle of a PCAN Channel</param>
861 /// <param name="Parameter"></param>
862 /// <param name="StringBuffer">Buffer with the value to be set</param>
863 /// <param name="BufferLength">Size in bytes of the buffer</param>
864 /// <returns>A TPCANStatus error code</returns>
865 [DllImport("PCANBasic.dll", EntryPoint = "CAN_SetValue")]
866 static TPCANStatus SetValue(
867 [MarshalAs(UnmanagedType::U1)]
868 TPCANHandle Channel,
869 [MarshalAs(UnmanagedType::U1)]
870 TPCANParameter Parameter,
871 [MarshalAs(UnmanagedType::LPStr,SizeParamIndex=3)]
872 String^ StringBuffer,
873 UInt32 BufferLength);
874
875 /// <summary>
876 /// Returns a descriptive text of a given TPCANStatus error
877 /// code, in any desired language
878 /// </summary>
879 /// <remarks>The current languages available for translation are:
880 /// Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A),
881 /// Italian (0x10) and French (0x0C)</remarks>
882 /// <param name="Error">A TPCANStatus error code</param>
883 /// <param name="Language">Indicates a 'Primary language ID'</param>
884 /// <param name="StringBuffer">Buffer for the text (must be at least 256 in length)</param>
885 /// <returns>A TPCANStatus error code</returns>
886 [DllImport("PCANBasic.dll", EntryPoint = "CAN_GetErrorText")]
887 static TPCANStatus GetErrorText(
888 [MarshalAs(UnmanagedType::U4)]
889 TPCANStatus Error,
890 UInt16 Language,
891 StringBuilder^ StringBuffer);
892 #pragma endregion
893 };
894 #pragma endregion
895 }
896 }
897}
Note: See TracBrowser for help on using the repository browser.