public override void DoRun() { byte[] dataReceived = null; int numberBytes; if (inEndpoint != null) { numberBytes = device.connection.BulkTransfer(inEndpoint, device.serialBuffer.GetBufferCompatible(), SerialBuffer.DEFAULT_READ_BUFFER_SIZE, 0); } else { numberBytes = 0; } if (numberBytes > 0) { dataReceived = device.serialBuffer.GetDataReceivedCompatible(numberBytes); // FTDI devices reserve two first bytes of an IN endpoint with info about // modem and Line. if (device.IsFTDIDevice()) { ((FTDISerialDevice)device).ftdiUtilities.CheckModemStatus(dataReceived); if (dataReceived.Length > 2) { dataReceived = FTDISerialDevice.AdaptArray(dataReceived); OnReceivedData(dataReceived); } } else { OnReceivedData(dataReceived); } } }
public override void DoRun() { UsbRequest request = null; /** * blocking call on usb device. * Make sure for UsbRequest object RequestWait and Queue functions do not deadlock from different threads **/ //request = device.connection.RequestWait(); if (!isSpecialCase) { try { request = device.connection.RequestWait(2000); //blocking call on usbdevice with optional timeout } catch (Java.Lang.NoSuchMethodError) { isSpecialCase = true; Log.Error("com.felhr.usbserial.UsbSerialDevice.WorkerThread.DoRun", "Exception at RequestWait(): Special Case"); } catch (Java.Util.Concurrent.TimeoutException) { /*do nothing and continue*/ } } else { try { request = device.connection.RequestWait(); //blocking call on usbdevice } catch (Java.Lang.Exception) { /*do nothing and continue*/ Log.Error("com.felhr.usbserial.UsbSerialDevice.WorkerThread.DoRun", "Exception at RequestWait()"); } } if (request?.Endpoint.Type == UsbAddressing.XferBulk && request.Endpoint.Direction == UsbAddressing.In) { byte[] data = device.serialBuffer.GetDataReceived(); // FTDI devices reserves two first bytes of an IN endpoint with info about // modem and Line. if (device.IsFTDIDevice()) { ((FTDISerialDevice)device).ftdiUtilities.CheckModemStatus(data); //Check the Modem status device.serialBuffer.ClearReadBuffer(); if (data.Length > 2) { data = FTDISerialDevice.AdaptArray(data); OnReceivedData(data); } } else { // Clear buffer, execute the callback device.serialBuffer.ClearReadBuffer(); OnReceivedData(data); } if (debugging && !(data.Length <= 2 && device.IsFTDIDevice())) { UsbSerialDebugger.PrintReadLogGet(data, true); } // Queue a new request //System.Threading.Thread.Sleep(10); if (isAPI26Version) //required check for Java.Lang.NoSuchMethodError thrown for some manufacturers on Queue(buffer); deprecation of Queue(buffer, size) since API 26 { requestIN?.Queue(device.serialBuffer.GetReadBuffer()); } else { requestIN?.Queue(device.serialBuffer.GetReadBuffer(), SerialBuffer.DEFAULT_READ_BUFFER_SIZE); //blocking call on usbdevice } } }