-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadWriteData.cpp
More file actions
68 lines (54 loc) · 1.48 KB
/
ReadWriteData.cpp
File metadata and controls
68 lines (54 loc) · 1.48 KB
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
#include "stdafx.h"
#include "windows.h"
#include "QuickUSB.h"
#include <iostream>
#include <stdio.h>
#include <bitset>
#include <stdlib.h>
#include <conio.h>
using namespace std;
int main(int argc, char* argv[])
{
printf("Read and Write Data test!\n");
// Global Variables
char nameList[120];
char *namePtr;
int result;
// Find the QuickUSB modules in the system
unsigned long len = 512;
result = QuickUsbFindModules(nameList, len);
// Check for no modules and bail if we don't find any
if (*nameList == '\0') {
printf("Couldn't find any modules\n");
return 0;
}
// Print out the name of each module found
char *namePtr;
namePtr = nameList;
while (*namePtr != '\0') {
printf("Found %s\n", namePtr);
namePtr = namePtr + strlen(namePtr) + 1;
}
// Open the first device
QHANDLE hDev;
result = QuickUsbOpen(&hDev, nameList);
if (result == FALSE) {
printf("Cannot open %s\n", nameList);
return 1;
}
// Read some data
unsigned char data2read[2];
unsigned long errorCode, length2read = 2;
ReadResult = QuickUsbReadData(hDev, data2read, &length2read);
std::cout << "ReadResult = " << ReadResult << std::endl;
if (ReadResult == FALSE) {
QuickUsbGetLastError(&errorCode);
printf("Cannot read data from %s\n", nameList);
std::cout << "Error Code = " << errorCode << std::endl;
//return 1;
}
// Close the port when you're done with it
QuickUsbClose(hDev);
printf("DONE");
return 0;
}