I am working at a project witch is communication with an selfmade USB device. So far everything goes well, I can read and write from/to the device.
But sometimes there is a failure in the USB-device and it blocks. I still get a correct handle to the device, but when I use WriteFile my programm blocks, because it can't write a single byte.
My Code:
Code: Select all
//FileHandles zu dem USB-Device für Lese/Schreib Zugriff
HANDLE WriteHandleToMyDevice = INVALID_HANDLE_VALUE;
HANDLE ReadHandleToMyDevice = INVALID_HANDLE_VALUE;
WriteHandleToMyDevice = CreateFile(devicePath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
error = GetLastError();
if (error){
// FEHLER => Kein Handle erzeugt
return 0; //=> Abbruch mit FEHLER!!!
}
ReadHandleToMyDevice = CreateFile(devicePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
error = GetLastError();
if (error){
// FEHLER => Kein Handle erzeugt
CloseHandle(WriteHandleToMyDevice);
return 0; //=> Abbruch mit FEHLER!!!
}
// Vorbereitung des QueryCommand zur Abfrage des USB-Device
queryCommand.QueryDevice.WindowsReserved = 0;
queryCommand.QueryDevice.Command = QUERY_DEVICE;
//Senden des QueryCommand zum Device
WriteFile(WriteHandleToMyDevice,queryCommand.RawData, 65, &bytesWritten, 0);
Thanks