You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a USB device attached but I can only connect if I unplug and plug again. I want to have the code to discover the device as soon as the program starts.
PLs can you pls help on the following issue:
I have a USB device attached but I can only connect if I unplug and plug again. I want to have the code to discover the device as soon as the program starts.
I have the code:
RNSerialport.setInterface(-1); //default -1
RNSerialport.setReturnedDataType(
definitions.RETURNED_DATA_TYPES.HEXSTRING
);
RNSerialport.setAutoConnect(true);
RNSerialport.setAutoConnectBaudRate(115200);
RNSerialport.startUsbService();
RNSerialport.isOpen()
.then((isOpen) => {
if (isOpen) {
console.log('Is open?', 'yes');
} else {
console.log('Is open?', 'no');
}
})
.catch((err) => {
console.log(err);
});
//2st way
RNSerialport.isServiceStarted()
.then((isServiceStarted) => {
if (isServiceStarted) {
console.log('Is service started?', 'yes');
} else {
console.log('Is service started?', 'no');
}
})
.catch((err) => {
console.log(err);
});
RNSerialport.getDeviceList().then((response) => {
console.log(response);
});
DeviceEventEmitter.addListener(actions.ON_DEVICE_ATTACHED, () => {
console.log('A NEW DEVICE WAS ATTACHED');
});
DeviceEventEmitter.addListener(actions.ON_SERVICE_STARTED, () => {
console.log('ON_SERVICE_STARTED');
});
DeviceEventEmitter.addListener(actions.ON_CONNECTED, () => {
console.log('DEVICE CONNECTED');
RNSerialport.getDeviceList().then(console.warn);
console.log('SEND START SCANNING');
So, initially, I don't see the device and get a [] in the RNSerialport.getDeviceList().then(console.warn);
LOG ON_SERVICE_STARTED
LOG Is open? no
LOG Is service started? yes
WARN []
As soon as I unplug the device and plug again, it connects and shows it in the list:
LOG A NEW DEVICE WAS ATTACHED
LOG DEVICE CONNECTED
LOG SEND START SCANNING
WARN [{"name": "/dev/bus/usb/001/002", "productId": 60000, "vendorId": 4292}]
Can you pls help to have the code finding the device attached since the beginning?
THANKS.
The text was updated successfully, but these errors were encountered: