com.hoho.android.usbserial.util.SerialInputOutputManager Java Examples
The following examples show how to use
com.hoho.android.usbserial.util.SerialInputOutputManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeviceTest.java From usb-serial-for-android with GNU Lesser General Public License v2.1 | 6 votes |
private void usbOpen(EnumSet<UsbOpenFlags> flags, int ioManagerTimeout) throws Exception { usbDeviceConnection = usbManager.openDevice(usbSerialDriver.getDevice()); usbSerialPort = usbSerialDriver.getPorts().get(test_device_port); usbSerialPort.open(usbDeviceConnection); if(!flags.contains(UsbOpenFlags.NO_CONTROL_LINE_INIT)) { usbSerialPort.setDTR(true); usbSerialPort.setRTS(true); } if(!flags.contains(UsbOpenFlags.NO_IOMANAGER_THREAD)) { usbIoManager = new SerialInputOutputManager(usbSerialPort, this) { @Override public void run() { if (SERIAL_INPUT_OUTPUT_MANAGER_THREAD_PRIORITY != null) Process.setThreadPriority(SERIAL_INPUT_OUTPUT_MANAGER_THREAD_PRIORITY); super.run(); } }; usbIoManager.setReadTimeout(ioManagerTimeout); usbIoManager.setWriteTimeout(ioManagerTimeout); Executors.newSingleThreadExecutor().submit(usbIoManager); } synchronized (usbReadBuffer) { usbReadBuffer.clear(); } usbReadError = null; }
Example #2
Source File: SnifferDeviceService.java From sniffer154 with GNU General Public License v3.0 | 6 votes |
private void setupUsbDevice() { mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE); mSerialDevice = UsbSerialProber.acquire(mUsbManager); if (mSerialDevice == null) { Toast.makeText(this, "Cannot find USB device", Toast.LENGTH_SHORT) .show(); } else { try { mSerialDevice.open(); } catch (IOException e) { Log.e(TAG, "Error setting up device: " + e.getMessage(), e); try { mSerialDevice.close(); } catch (IOException e2) { // Ignore. } mSerialDevice = null; return; } } mSerialIoManager = new SerialInputOutputManager(mSerialDevice, mListener); mExecutor.submit(mSerialIoManager); }
Example #3
Source File: SerialSocket.java From SimpleUsbTerminal with MIT License | 5 votes |
void connect(SerialListener listener) throws IOException { this.listener = listener; context.registerReceiver(disconnectBroadcastReceiver, new IntentFilter(Constants.INTENT_ACTION_DISCONNECT)); serialPort.setDTR(true); // for arduino, ... serialPort.setRTS(true); ioManager = new SerialInputOutputManager(serialPort, this); Executors.newSingleThreadExecutor().submit(ioManager); }
Example #4
Source File: Serial.java From cordovarduino with MIT License | 5 votes |
/** * Observe serial connection */ private void startIoManager() { if (driver != null) { Log.i(TAG, "Starting io manager."); mSerialIoManager = new SerialInputOutputManager(port, mListener); mExecutor.submit(mSerialIoManager); } }
Example #5
Source File: UsbCommService.java From AndrOBD with GNU General Public License v3.0 | 4 votes |
/** * Set USB serial port device * @param port serial port to be set */ private void setDevice(UsbSerialPort port) { sPort = port; mSerialIoManager = new SerialInputOutputManager(sPort, mListener); }
Example #6
Source File: TerminalFragment.java From usb-serial-for-android with GNU Lesser General Public License v2.1 | 4 votes |
private void connect() { UsbDevice device = null; UsbManager usbManager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE); for(UsbDevice v : usbManager.getDeviceList().values()) if(v.getDeviceId() == deviceId) device = v; if(device == null) { status("connection failed: device not found"); return; } UsbSerialDriver driver = UsbSerialProber.getDefaultProber().probeDevice(device); if(driver == null) { driver = CustomProber.getCustomProber().probeDevice(device); } if(driver == null) { status("connection failed: no driver for device"); return; } if(driver.getPorts().size() < portNum) { status("connection failed: not enough ports at device"); return; } usbSerialPort = driver.getPorts().get(portNum); UsbDeviceConnection usbConnection = usbManager.openDevice(driver.getDevice()); if(usbConnection == null && usbPermission == UsbPermission.Unknown && !usbManager.hasPermission(driver.getDevice())) { usbPermission = UsbPermission.Requested; PendingIntent usbPermissionIntent = PendingIntent.getBroadcast(getActivity(), 0, new Intent(INTENT_ACTION_GRANT_USB), 0); usbManager.requestPermission(driver.getDevice(), usbPermissionIntent); return; } if(usbConnection == null) { if (!usbManager.hasPermission(driver.getDevice())) status("connection failed: permission denied"); else status("connection failed: open failed"); return; } try { usbSerialPort.open(usbConnection); usbSerialPort.setParameters(baudRate, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE); if(withIoManager) { usbIoManager = new SerialInputOutputManager(usbSerialPort, this); Executors.newSingleThreadExecutor().submit(usbIoManager); } status("connected"); connected = true; controlLines.start(); } catch (Exception e) { status("connection failed: " + e.getMessage()); disconnect(); } }