Rev 270 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 270 | Rev 800 | ||
|---|---|---|---|
| 1 | #ifndef __SERIALCONNECTION_H |
1 | #ifndef __SERIALCONNECTION_H |
| 2 | #define __SERIALCONNECTION_H |
2 | #define __SERIALCONNECTION_H |
| 3 | 3 | ||
| 4 | #include <crtdbg.h> |
4 | #include <crtdbg.h> |
| 5 | #include <tchar.h> |
5 | #include <tchar.h> |
| 6 | #include <windows.h> |
6 | #include <windows.h> |
| 7 | #include <stdio.h> |
7 | #include <stdio.h> |
| 8 | #include <process.h> |
8 | #include <process.h> |
| 9 | #include "CanProtoMessage.h" |
9 | #include "CanProtoMessage.h" |
| 10 | #include "compiler.h" |
10 | #include "compiler.h" |
| 11 | 11 | ||
| 12 | #define SERIAL_INPUT_BUFFER_SIZE 1024 |
12 | #define SERIAL_INPUT_BUFFER_SIZE 1024 |
| 13 | #define SERIAL_READ_BUFFER_SIZE 8192 |
13 | #define SERIAL_READ_BUFFER_SIZE 8192 |
| 14 | #define QUEUE_PLACES 32 |
14 | #define QUEUE_PLACES 32 |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | class SerialConnection |
17 | class SerialConnection |
| 18 | { |
18 | { |
| 19 | public: |
19 | public: |
| 20 | // Baudrate |
20 | // Baudrate |
| 21 | typedef enum |
21 | typedef enum |
| 22 | { |
22 | { |
| 23 | EBaudUnknown = -1, // Unknown |
23 | EBaudUnknown = -1, // Unknown |
| 24 | EBaud110 = CBR_110, // 110 bits/sec |
24 | EBaud110 = CBR_110, // 110 bits/sec |
| 25 | EBaud300 = CBR_300, // 300 bits/sec |
25 | EBaud300 = CBR_300, // 300 bits/sec |
| 26 | EBaud600 = CBR_600, // 600 bits/sec |
26 | EBaud600 = CBR_600, // 600 bits/sec |
| 27 | EBaud1200 = CBR_1200, // 1200 bits/sec |
27 | EBaud1200 = CBR_1200, // 1200 bits/sec |
| 28 | EBaud2400 = CBR_2400, // 2400 bits/sec |
28 | EBaud2400 = CBR_2400, // 2400 bits/sec |
| 29 | EBaud4800 = CBR_4800, // 4800 bits/sec |
29 | EBaud4800 = CBR_4800, // 4800 bits/sec |
| 30 | EBaud9600 = CBR_9600, // 9600 bits/sec |
30 | EBaud9600 = CBR_9600, // 9600 bits/sec |
| 31 | EBaud14400 = CBR_14400, // 14400 bits/sec |
31 | EBaud14400 = CBR_14400, // 14400 bits/sec |
| 32 | EBaud19200 = CBR_19200, // 19200 bits/sec (default) |
32 | EBaud19200 = CBR_19200, // 19200 bits/sec (default) |
| 33 | EBaud38400 = CBR_38400, // 38400 bits/sec |
33 | EBaud38400 = CBR_38400, // 38400 bits/sec |
| 34 | EBaud56000 = CBR_56000, // 56000 bits/sec |
34 | EBaud56000 = CBR_56000, // 56000 bits/sec |
| 35 | EBaud57600 = CBR_57600, // 57600 bits/sec |
35 | EBaud57600 = CBR_57600, // 57600 bits/sec |
| 36 | EBaud115200 = CBR_115200, // 115200 bits/sec |
36 | EBaud115200 = CBR_115200, // 115200 bits/sec |
| 37 | EBaud128000 = CBR_128000, // 128000 bits/sec |
37 | EBaud128000 = CBR_128000, // 128000 bits/sec |
| 38 | EBaud256000 = CBR_256000, // 256000 bits/sec |
38 | EBaud256000 = CBR_256000, // 256000 bits/sec |
| 39 | } |
39 | } |
| 40 | EBaudrate; |
40 | EBaudrate; |
| 41 | 41 | ||
| 42 | // Data bits (5-8) |
42 | // Data bits (5-8) |
| 43 | typedef enum |
43 | typedef enum |
| 44 | { |
44 | { |
| 45 | EDataUnknown = -1, // Unknown |
45 | EDataUnknown = -1, // Unknown |
| 46 | EData5 = 5, // 5 bits per byte |
46 | EData5 = 5, // 5 bits per byte |
| 47 | EData6 = 6, // 6 bits per byte |
47 | EData6 = 6, // 6 bits per byte |
| 48 | EData7 = 7, // 7 bits per byte |
48 | EData7 = 7, // 7 bits per byte |
| 49 | EData8 = 8 // 8 bits per byte (default) |
49 | EData8 = 8 // 8 bits per byte (default) |
| 50 | } |
50 | } |
| 51 | EDataBits; |
51 | EDataBits; |
| 52 | 52 | ||
| 53 | // Parity scheme |
53 | // Parity scheme |
| 54 | typedef enum |
54 | typedef enum |
| 55 | { |
55 | { |
| 56 | EParUnknown = -1, // Unknown |
56 | EParUnknown = -1, // Unknown |
| 57 | EParNone = NOPARITY, // No parity (default) |
57 | EParNone = NOPARITY, // No parity (default) |
| 58 | EParOdd = ODDPARITY, // Odd parity |
58 | EParOdd = ODDPARITY, // Odd parity |
| 59 | EParEven = EVENPARITY, // Even parity |
59 | EParEven = EVENPARITY, // Even parity |
| 60 | EParMark = MARKPARITY, // Mark parity |
60 | EParMark = MARKPARITY, // Mark parity |
| 61 | EParSpace = SPACEPARITY // Space parity |
61 | EParSpace = SPACEPARITY // Space parity |
| 62 | } |
62 | } |
| 63 | EParity; |
63 | EParity; |
| 64 | 64 | ||
| 65 | // Stop bits |
65 | // Stop bits |
| 66 | typedef enum |
66 | typedef enum |
| 67 | { |
67 | { |
| 68 | EStopUnknown = -1, // Unknown |
68 | EStopUnknown = -1, // Unknown |
| 69 | EStop1 = ONESTOPBIT, // 1 stopbit (default) |
69 | EStop1 = ONESTOPBIT, // 1 stopbit (default) |
| 70 | EStop1_5 = ONE5STOPBITS,// 1.5 stopbit |
70 | EStop1_5 = ONE5STOPBITS,// 1.5 stopbit |
| 71 | EStop2 = TWOSTOPBITS // 2 stopbits |
71 | EStop2 = TWOSTOPBITS // 2 stopbits |
| 72 | } |
72 | } |
| 73 | EStopBits; |
73 | EStopBits; |
| 74 | 74 | ||
| 75 | 75 | ||
| 76 | public: |
76 | public: |
| 77 | SerialConnection(LPCTSTR portName,EBaudrate baudRate,EDataBits byteSize,EParity parity, EStopBits stopBits); |
77 | SerialConnection(LPCTSTR portName,EBaudrate baudRate,EDataBits byteSize,EParity parity, EStopBits stopBits); |
| 78 | ~SerialConnection(); |
78 | ~SerialConnection(); |
| 79 | bool open(void); |
79 | bool open(void); |
| 80 | bool close(void); |
80 | bool close(void); |
| 81 | bool isOpen(void); |
81 | bool isOpen(void); |
| 82 | bool write(LPCVOID lpBuffer, unsigned int nNumberOfBytesToWrite); |
82 | bool write(LPCVOID lpBuffer, unsigned int nNumberOfBytesToWrite); |
| 83 | HANDLE getHandle(void); |
83 | HANDLE getHandle(void); |
| 84 | bool getMessage(CanProtoMessage *cpm); |
84 | bool getMessage(CanProtoMessage *cpm); |
| 85 | 85 | ||
| 86 | protected: |
86 | protected: |
| 87 | LPCTSTR uportName; |
87 | LPCTSTR uportName; |
| 88 | EBaudrate ubaudRate; |
88 | EBaudrate ubaudRate; |
| 89 | EDataBits ubyteSize; |
89 | EDataBits ubyteSize; |
| 90 | EParity uparity; |
90 | EParity uparity; |
| 91 | EStopBits ustopBits; |
91 | EStopBits ustopBits; |
| 92 | 92 | ||
| 93 | }; |
93 | }; |
| 94 | 94 | ||
| 95 | 95 | ||
| 96 | #endif |
96 | #endif |