cordova_serial.requestPermission() driver fix

Fight controller based on silabs CP2104 was not working as function call cordova_serial.requestPermission() without specify the driver parameter uses the default driver "CdcAcmSerialDriver" which is the wrong when usb-uart chip is a CP2104. This chip requires the driver "Cp21xxSerialDriver"

fix code smells

fix the automatically reported code smells

'CdcAcmSerialDriver' as default driver

In order to not rely on the fallback driver in the driver library define 'CdcAcmSerialDriver' explicit locally

Co-authored-by: haslinghuis <mark@numloq.nl>

add CP2102 and other CP210x single port devices into usb device filter
10.8-maintenance
danybd 2021-03-14 14:55:27 +01:00 committed by Michael Keller
parent 898a6b974b
commit f4abe55308
2 changed files with 9 additions and 1 deletions

View File

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="1155" product-id="22336" /> <!--STMicroelectronics / Virtual COM Port -->
<usb-device vendor-id="4292" product-id="60000" /> <!--CP2102 and other CP210x single port devices -->
</resources>

View File

@ -60,6 +60,13 @@ const chromeapiSerial = {
stopBits: 'one',
ctsFlowControl: false,
},
getDriver: function(vid, pid) {
if (vid === 4292 && pid === 60000) {
return 'Cp21xxSerialDriver'; //for Silabs CP2102 and all other CP210x
} else {
return 'CdcAcmSerialDriver';
}
},
setConnectionOptions: function(ConnectionOptions) {
if (ConnectionOptions.persistent) {
this.connection.persistent = ConnectionOptions.persistent;
@ -158,7 +165,7 @@ const chromeapiSerial = {
const vid = parseInt(pathSplit[0]);
const pid = parseInt(pathSplit[1]);
console.log(`${self.logHeader}request permission (vid=${vid} / pid=${pid})`);
cordova_serial.requestPermission({vid: vid, pid: pid}, function() {
cordova_serial.requestPermission({vid: vid, pid: pid, driver: self.getDriver(vid, pid)}, function() {
const options = self.getCordovaSerialConnectionOptions();
cordova_serial.open(options, function () {
cordova_serial.registerReadCallback(function (data) {