Closed desmond58 closed 4 months ago
const handlePressSave = async (data) => { try { const devices = await UsbSerialManager.list(); devices.forEach(device => { console.log('Device ID:', device.deviceId, 'Product ID:', device.productId, 'Vendor ID:', device.vendorId); // Log other properties if needed console.log('-----------------------------------'); }); await UsbSerialManager.tryRequestPermission(5023); const usbSerialport = await UsbSerialManager.open(5023, { baudRate: 9600, parity: Parity.None, dataBits: 8, stopBits: 1 }); const sub = usbSerialport.onReceived((event) => { console.log(event.deviceId, event.data); }); // unsubscribe // sub.remove(); const jsonData = { "tranType": "ping-test" }; // Convert JSON object to JSON string const jsonString = JSON.stringify(jsonData); // Convert each character in the JSON string to its hex representation const hexData = Array.from(jsonString) .map(char => char.charCodeAt(0).toString(16).padStart(2, '0')) .join(''); // Send the hex data using the serial port await usbSerialport.send(hexData); usbSerialport.close(); } catch (error) { console.error('Error opening serial port:', error); } }
Hi @bastengao, am I doing anything wrong? Please Help!
The device I am using:
By using the simple USB terminal, it can send and receive but my app showed an error that I mentioned above.
@bastengao hi, 能帮我升级 mik3y/usb-serial-for-android to 3.7.0 版本吗,我怀疑3.4.3并不能自动检测到我的CDC设备。
Hi @bastengao, am I doing anything wrong? Please Help!
The device I am using:
By using the simple USB terminal, it can send and receive but my app showed an error that I mentioned above.