Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetDeviceList Null when device initially attached, only connects is I re-plug the device #53

Open
marioorlandoout opened this issue Jul 17, 2023 · 0 comments

Comments

@marioorlandoout
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant