auto switch baud rate between old and new devices

This commit is contained in:
Pritimay Sarkar
2024-02-29 14:01:23 +05:30
parent a142717ef2
commit 2e1c932e72

View File

@@ -36,9 +36,14 @@ class UsbService : Service() {
try { try {
mPort = driver.ports[0] mPort = driver.ports[0]
mPort.open(connection) mPort.open(connection)
mPort.setParameters(9600, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
if (mPort.device.vendorId == 6790 && mPort.device.productId == 29987)
mPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
else
mPort.setParameters(9600, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
isUsbConnected = true isUsbConnected = true
Log.d(TAG, "My Usb Connected ${mPort.driver}") Log.d(TAG, "Usb Connected ${mPort.driver}")
val usbIoManager = SerialInputOutputManager(mPort, val usbIoManager = SerialInputOutputManager(mPort,
object : SerialInputOutputManager.Listener { object : SerialInputOutputManager.Listener {
@@ -47,7 +52,7 @@ class UsbService : Service() {
} }
override fun onRunError(e: Exception?) { override fun onRunError(e: Exception?) {
Log.e(TAG, "onRunError() called inside eventDrivenWrite()") Log.e(TAG, "onRunError() called")
listener?.onUsbError(e) listener?.onUsbError(e)
} }
}) })
@@ -56,7 +61,7 @@ class UsbService : Service() {
} catch (ioException: IOException) { } catch (ioException: IOException) {
Log.e(TAG, "IOException during USB connection: ${ioException.message}", ioException) Log.e(TAG, "IOException during USB connection: ${ioException.message}", ioException)
listener?.onUsbError(ioException) listener?.onUsbError(ioException)
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "Error connecting USB: ${e.message}", e) Log.e(TAG, "Error connecting USB: ${e.message}", e)
listener?.onUsbError(e) listener?.onUsbError(e)
} }