-
Notifications
You must be signed in to change notification settings - Fork 0
/
usb.h
74 lines (61 loc) · 1.46 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
// 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 1024
//#define USBREADBUFFERSIZE 4096 // 4.1 MiB/s
#define USBREADBUFFERSIZE 65536 // 4.1 MiB/s
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];
int GetQueue( );
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 SetTimeout( int ms ); // DP
void Flush( );
void Clear( );
bool WaitForFilledQueue( int pSize, int pMaxWait = 10000 ); // DP, HP
void Read( void *buffer, unsigned int size );
};
#endif