Skip to content

Commit f4abe55

Browse files
danybdmikeller
authored andcommitted
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 <[email protected]> add CP2102 and other CP210x single port devices into usb device filter
1 parent 898a6b9 commit f4abe55

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

cordova/usb_device_filter.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<usb-device vendor-id="1155" product-id="22336" /> <!--STMicroelectronics / Virtual COM Port -->
4+
<usb-device vendor-id="4292" product-id="60000" /> <!--CP2102 and other CP210x single port devices -->
45
</resources>

src/js/cordova_chromeapi.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ const chromeapiSerial = {
6060
stopBits: 'one',
6161
ctsFlowControl: false,
6262
},
63+
getDriver: function(vid, pid) {
64+
if (vid === 4292 && pid === 60000) {
65+
return 'Cp21xxSerialDriver'; //for Silabs CP2102 and all other CP210x
66+
} else {
67+
return 'CdcAcmSerialDriver';
68+
}
69+
},
6370
setConnectionOptions: function(ConnectionOptions) {
6471
if (ConnectionOptions.persistent) {
6572
this.connection.persistent = ConnectionOptions.persistent;
@@ -158,7 +165,7 @@ const chromeapiSerial = {
158165
const vid = parseInt(pathSplit[0]);
159166
const pid = parseInt(pathSplit[1]);
160167
console.log(`${self.logHeader}request permission (vid=${vid} / pid=${pid})`);
161-
cordova_serial.requestPermission({vid: vid, pid: pid}, function() {
168+
cordova_serial.requestPermission({vid: vid, pid: pid, driver: self.getDriver(vid, pid)}, function() {
162169
const options = self.getCordovaSerialConnectionOptions();
163170
cordova_serial.open(options, function () {
164171
cordova_serial.registerReadCallback(function (data) {

0 commit comments

Comments
 (0)