-
Notifications
You must be signed in to change notification settings - Fork 8
/
usb.h
79 lines (64 loc) · 1.39 KB
/
usb.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
// usb.h
//
// Author: Beat Meier
//
// Class provides basic functionalities to use the USB interface
//
#ifndef USB_H
#define USB_H
#ifdef _WIN32
#include "windows.h"
#include "win32\FTD2XX.h"
#else
#include "linux/ftd2xx.h"
#endif
#include "rpc_io.h"
#define USBWRITEBUFFERSIZE 1024
#define USBREADBUFFERSIZE 4096
/*
class CUsbLog
{
FILE *f;
enum { IDLE, CMD_1, CMD_2, CMD_CNT, DAT_CNT1, DAT_CNT2, DAT_CNT3, DATA } state;
unsigned int count;
unsigned int cmd;
public:
CUsbLog();
~CUsbLog();
void Add(unsigned int x);
};
*/
class CUSB : public CRpcIo
{
bool isUSB_open;
FT_HANDLE ftHandle;
FT_STATUS ftStatus;
DWORD enumPos, enumCount;
DWORD m_posW;
unsigned char m_bufferW[USBWRITEBUFFERSIZE];
DWORD m_posR, m_sizeR;
unsigned char m_bufferR[USBREADBUFFERSIZE];
bool FillBuffer(DWORD minBytesToRead);
public:
CUSB()
{
m_posR = m_sizeR = m_posW = 0;
isUSB_open = false;
ftHandle = 0; ftStatus = 0;
enumPos = enumCount = 0;
}
~CUSB() { /* Close(); */ }
int GetLastError() { return ftStatus; }
static const char* GetErrorMsg(int error);
bool EnumFirst(unsigned int &nDevices);
bool EnumNext(char name[]);
bool Enum(char name[], unsigned int pos);
bool Open(char serialNumber[]);
void Close();
bool Connected() { return isUSB_open; };
void Write(const void *buffer, unsigned int size);
void Flush();
void Clear();
void Read(void *buffer, unsigned int size);
};
#endif