Skip to content

Instantly share code, notes, and snippets.

@sytsereitsma
Created August 4, 2014 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sytsereitsma/d0d181f4bef76ca5f41e to your computer and use it in GitHub Desktop.
Save sytsereitsma/d0d181f4bef76ca5f41e to your computer and use it in GitHub Desktop.
HANDLE handle = ::CreateFileW (L"\\\\.\\ezusb-0",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0,
OPEN_EXISTING,
0,
0);
unsigned short pipe;
unsigned short commandCode; //Command code sent to device which has the IC on board
unsigned receivedLength;
const unsigned long kBulkWrite = 0x0800 + 20;
const unsigned long kWriteRegister = (FILE_DEVICE_UNKNOWN << 16) | (FILE_ANY_ACCESS << 14) | (kBulkWrite << 2) | METHOD_IN_DIRECT;
const unsigned long kBulkRead = 0x0800 + 19;
const unsigned long kReadData = (FILE_DEVICE_UNKNOWN << 16) | (FILE_ANY_ACCESS << 14) | (kBulkRead << 2) | METHOD_OUT_DIRECT;
//Pipe 0, Device Tx register command
pipe = 0;
commandCode = 0xBEEF; //Control code sent to device which has the IC on board
DeviceIoControl (handle, kWriteRegister, &pipe, 2, &commandCode, 2, &receivedLength);
//Pipe 1, Rx register command
pipe = 1;
commandCode = 0xDEAD;
DeviceIoControl (handle, kWriteRegister, &pipe, 2, &commandCode, 2, &receivedLength);
//Pipe 2, Receive data into buffer
pipe = 2;
unsigned char buffer [128];
DeviceIoControl (handle, kReadData, &pipe, 2, &buffer, 128, &receivedLength);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment