bastengao / react-native-usb-serialport-for-android

MIT License
16 stars 30 forks source link

React Native Expo - no driver for device #16

Closed desmond58 closed 4 months ago

desmond58 commented 8 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);
    }
  }

image

Hi @bastengao, am I doing anything wrong? Please Help!

The device I am using:

  1. Android Tablet with simple_usb_terminal app by kai-morich installed
  2. N910 Pro CDC serial device IMG_4218

By using the simple USB terminal, it can send and receive but my app showed an error that I mentioned above.

desmond58 commented 7 months ago

@bastengao hi, 能帮我升级 mik3y/usb-serial-for-android to 3.7.0 版本吗,我怀疑3.4.3并不能自动检测到我的CDC设备。