//---#+************************************************************************ //---NOTATION: //- readDataThread() //- //--- DESCRIPTION: //-- ThreadMethod for reading Data // Autor: F.L. //-*************************************************************************+#* /// <summary> /// ThreadMethod for reading Data /// </summary> public void readDataThread() { int receivedNull = 0; while (true) { int myPtrToPreparsedData = -1; if (myUSB.CT_HidD_GetPreparsedData(myUSB.HidHandle, ref myPtrToPreparsedData) != 0) { int code = myUSB.CT_HidP_GetCaps(myPtrToPreparsedData); int reportLength = myUSB.myHIDP_CAPS.InputReportByteLength; while (true) {//read until thread is stopped byte[] myRead = myUSB.CT_ReadFile(myUSB.myHIDP_CAPS.InputReportByteLength); if (myRead != null) { //ByteCount + bytes received byteCount += myRead.Length; //Store received bytes /* lock (recieveBuffer.SyncRoot) * { * recieveBuffer.Add(myRead); * }*/ lock (USBHIDDRIVER.USBInterface.usbBuffer.SyncRoot) { USBHIDDRIVER.USBInterface.usbBuffer.Add(myRead); } } else { //Recieved a lot of null bytes! //mybe device disconnected? if (receivedNull > 100) { receivedNull = 0; Thread.Sleep(1); } receivedNull++; } } } } }
/// <summary> /// Read HID report from hid device /// </summary> /// <returns></returns> public byte[] ReadData() { byte[] retval = myUSB.CT_ReadFile(myUSB.myHIDP_CAPS.InputReportByteLength); return(retval); }
public byte[] ReadData() { return(myUSB.CT_ReadFile()); }