-
Notifications
You must be signed in to change notification settings - Fork 53
/
usbcan.h
257 lines (218 loc) · 4.96 KB
/
usbcan.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#ifndef USBCAN_H
#define USBCAN_H
#include <Windows.h>
//#include <windef.h>
//#include <minwindef.h>
#include <iostream>
#include "ControlCAN.h"
class USBCAN
{
public:
USBCAN();
~USBCAN();
USBCAN(DWORD nDevType, DWORD nDevIndex, DWORD nReserved);
/**
* @brief openDevice
* @param nDevType
* @param nDevIndex
* @param reserved
* @return
*/
bool openDevice();
/**
* @brief closeDevice
* @param nDevType
* @param DevIndex
* @return
*/
bool closeDevice();
/**
* @brief initCAN
* @param nDevType
* @param nDevIndex
* @param nCANIndex
* @param pInitConfig
* @return
*/
bool initCAN(PVCI_INIT_CONFIG pInitConfig);
/**
* @brief startCAN
* @param nDevType
* @param nDevIndex
* @param nCANIndex
* @return
*/
bool startCAN();
/**
* @brief getReceiveNumber
* @param nDevType
* @param nDevIndex
* @param nCANIndex
* @return
*/
bool getReceiveNumber();
/**
* @brief clearBuffer
* @param nDevType
* @param nDevIndex
* @param nCANIndex
* @return
*/
bool clearBuffer();
/**
* @brief transmitData
* @param nDevType
* @param nDevIndex
* @param nCANIndex
* @param pSend
* @param len
* @return
*/
bool transmitData(PVCI_CAN_OBJ pSend, ULONG len);
/**
* @brief transmitData
* @param nDevType
* @param nDevIndex
* @param nCANIndex
* @param pReceive
* @param len
* @param waitTime
* @return
*/
bool receiveData(PVCI_CAN_OBJ pReceive, ULONG len, INT waitTime=-1);
/**
* @brief resetCAN
* @param nDevType
* @param nDevIndex
* @param nCANIndex
* @return
*/
bool resetCAN();
/**
* @brief readBoardInfo
* @param nDevType
* @param nDevIndex
* @param nCANIndex
* @param pInfo
* @return
*/
bool readBoardInfo(PVCI_BOARD_INFO pInfo);
/**
* @brief readErrorInfo
* @param nDevType
* @param nDevIndex
* @param nCANIndex
* @param pErrInfo
* @return
*/
bool readErrorInfo(PVCI_ERR_INFO pErrInfo);
/**
* @brief readCANStatus
* @param nDevType
* @param nDevIndex
* @param nCANIndex
* @return
*/
bool readCANStatus(PVCI_CAN_STATUS pCANStatus);
/**
* @brief getReference
* @param nDevType
* @param nDevIndex
* @param nCANIndex
* @param refType
* @param pData
* @return
*/
bool getReference(DWORD refType, PVOID pData);
/**
* @brief setReference
* @param nDevType
* @param nDevIndex
* @param nCANIndex
* @param refType
* @param pData
* @return
*/
bool setReference(DWORD refType, PVOID pData);
/**
* @brief showErrorInfo
*/
void showErrorInfo();
/**
* @brief showBoardInfo
*/
void showBoardInfo();
/**
* @brief showCANStatus
*/
void showCANStatus();
/**
* @brief getUnreadFramesNumber
* @return
*/
ULONG getUnreadFramesNumber(){
return this->_unReadFramesNumber;
}
/**
* @brief getTransmittedFramesNumber
* @return
*/
ULONG getTransmittedFramesNumber(){
return this->_transmittedFramesNumber;
}
/**
* @brief getReveivedFramsNumber
* @return
*/
ULONG getReveivedFramsNumber(){
return this->_receivedFramesNumber;
}
/**
* @brief getLastReturnCode
* @return
*/
DWORD getLastReturnCode(){
return this->_retCode;
}
public:
// Device Index
const static DWORD _nDefaultDevType = VCI_USBCAN1;
const static DWORD _nDefaultDevIndex = 0;
const static DWORD _nDefaultCANIndex = -1;
const static DWORD _nDefaultReserved = 0;
private:
DWORD _nDevType;
DWORD _nDevIndex;
DWORD _nCANIndex;
// Varies of Structures
PVCI_BOARD_INFO _pBoardInfo;
PVCI_INIT_CONFIG _pInitConfig;
PVCI_CAN_STATUS _pCANStatus;
PVCI_ERR_INFO _pErrorInfo;
PVCI_FILTER_RECORD _pFilterRecord;
// Reference Type for setReference & getReference
DWORD _nRefType;
// Buffer for receiving and sending CAN Frames
PVCI_CAN_OBJ _pVCO;
VCI_CAN_OBJ _vco[1000];
// Check if the USBCAN device is opened or closed
bool _isOpened;
bool _isClosed;
// Check if the USBCAN device is initialized
bool _isInitialized;
// Check if the USBCAN device is started
bool _isStarted;
// Check if the last read Error Info call is successful
bool _isErrorInfoReady;
// Number of frames unread in the USBCAN device
ULONG _unReadFramesNumber;
// Number of frames reveived in one receive call
ULONG _receivedFramesNumber;
// Number of frames transmitted in one receive call
ULONG _transmittedFramesNumber;
// Return code of normal API invokes
DWORD _retCode;
// Reseverd
DWORD _nReserved;
};
#endif // USBCAN_H