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 {
mPort = driver.ports[0]
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
Log.d(TAG, "My Usb Connected ${mPort.driver}")
Log.d(TAG, "Usb Connected ${mPort.driver}")
val usbIoManager = SerialInputOutputManager(mPort,
object : SerialInputOutputManager.Listener {
@@ -47,7 +52,7 @@ class UsbService : Service() {
}
override fun onRunError(e: Exception?) {
Log.e(TAG, "onRunError() called inside eventDrivenWrite()")
Log.e(TAG, "onRunError() called")
listener?.onUsbError(e)
}
})
@@ -56,7 +61,7 @@ class UsbService : Service() {
} catch (ioException: IOException) {
Log.e(TAG, "IOException during USB connection: ${ioException.message}", ioException)
listener?.onUsbError(ioException)
} catch (e: Exception) {
} catch (e: Exception) {
Log.e(TAG, "Error connecting USB: ${e.message}", e)
listener?.onUsbError(e)
}