//private void DoSyncOpenActions() //{ // usbService.serialPortConnected = true; // usbService.serialPort.SetBaudRate(UsbSerialInterface.BAUD_RATE_9600); // usbService.serialPort.SetDataBits(UsbSerialInterface.DATA_BITS_8); // usbService.serialPort.SetStopBits(UsbSerialInterface.STOP_BITS_1); // usbService.serialPort.SetParity(UsbSerialInterface.PARITY_NONE); // /** // * Current flow control Options: // * UsbSerialInterface.FLOW_CONTROL_OFF // * UsbSerialInterface.FLOW_CONTROL_RTS_CTS only for CP2102 and FT232 // * UsbSerialInterface.FLOW_CONTROL_DSR_DTR only for CP2102 and FT232 // */ // usbService.serialPort.SetFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF); // //serialPort.Read(usbService.mCallback); // usbService.serialPort.GetCTS(usbService.ctsCallback); // usbService.serialPort.GetDSR(usbService.dsrCallback); // usbService.syncreadThread = new ReadThread(usbService); // usbService.syncreadThread.Start(); // // // // Some Arduinos would need some sleep because firmware wait some time to know whether a new sketch is going // // to be uploaded or not // //Thread.sleep(2000); // sleep some. YMMV with different chips. // // Everything went as expected. Send an intent to MainActivity // Intent intent = new Intent(ServiceConstants.ACTION_USB_READY); // usbService.context.SendBroadcast(intent); //} /// <summary> /// The Run /// </summary> public override void Run() { usbService.serialPort = UsbSerialDevice.CreateUsbSerialDevice(usbService.device, usbService.connection); //serialPort = null;// UsbSerialDevice.CreateUsbSerialDevice(usbService.device, usbService.connection); if (usbService.serialPort != null) { if (LNG.CommonFramework.StaticMethods.IsAsync) { if (usbService.serialPort.Open()) { DoOpenActions(true); } else { // Serial port could not be opened, maybe an I/O error or if CDC driver was chosen, it does not really fit // Send an Intent to Main Activity if (usbService.serialPort is CDCSerialDevice) { Intent intent = new Intent(ServiceConstants.ACTION_CDC_DRIVER_NOT_WORKING); usbService.context.SendBroadcast(intent); } else { Intent intent = new Intent(ServiceConstants.ACTION_USB_DEVICE_NOT_WORKING); usbService.context.SendBroadcast(intent); } } } else if (usbService.serialPort.SyncOpen()) { DoOpenActions(false); } else { // Serial port could not be opened, maybe an I/O error or if CDC driver was chosen, it does not really fit // Send an Intent to Main Activity if (usbService.serialPort is CDCSerialDevice) { Intent intent = new Intent(ServiceConstants.ACTION_CDC_DRIVER_NOT_WORKING); usbService.context.SendBroadcast(intent); } else { Intent intent = new Intent(ServiceConstants.ACTION_USB_DEVICE_NOT_WORKING); usbService.context.SendBroadcast(intent); } } } else { // No driver for given device, even generic CDC driver could not be loaded Intent intent = new Intent(ServiceConstants.ACTION_USB_NOT_SUPPORTED); usbService.context.SendBroadcast(intent); } }