admin管理员组

文章数量:1425761

The code below works on my Xubuntu machine, but now I'm on Kubuntu and it isn't working anymore - it won't open the port.

The Arduino IDE works fine (can write code to the board) and I'm able to select the device (Arduino Uno) in Chrome, but the code will stop when I try to open the port: Uncaught (in promise) DOMException: Failed to open serial port or required member baudRate is undefined will e up.

const filters = [
  // Filter on devices with the Arduino Uno USB Vendor/Product IDs.
  { usbVendorId: 0x2341, usbProductId: 0x0043 },
  { usbVendorId: 0x2341, usbProductId: 0x0001 },
];

  async function getPortAndStartReading() {
    if (!portFound) {
      const port = await navigator.serial.requestPort({ filters });
      await port.open({ baudRate: 9600 }) //problem here
      reader = port.readable.getReader();
      outputStream = port.writable
      readLoop();
      if (port) {
          connectionToPortSuccessfulMessage = 'Connection successful'
          setPortFound(true)
      }
    }
  }

I've tried changing the permissions on the serial port by following this, so now if I run groups user I get user : user adm dialout cdrom sudo dip plugdev lpadmin lxd sambashare, but it still won't work.

I've also checked chrome://device-log to see if I could find any errors but all I get is info about (physically) adding or removing a USB device.

The code below works on my Xubuntu machine, but now I'm on Kubuntu and it isn't working anymore - it won't open the port.

The Arduino IDE works fine (can write code to the board) and I'm able to select the device (Arduino Uno) in Chrome, but the code will stop when I try to open the port: Uncaught (in promise) DOMException: Failed to open serial port or required member baudRate is undefined will e up.

const filters = [
  // Filter on devices with the Arduino Uno USB Vendor/Product IDs.
  { usbVendorId: 0x2341, usbProductId: 0x0043 },
  { usbVendorId: 0x2341, usbProductId: 0x0001 },
];

  async function getPortAndStartReading() {
    if (!portFound) {
      const port = await navigator.serial.requestPort({ filters });
      await port.open({ baudRate: 9600 }) //problem here
      reader = port.readable.getReader();
      outputStream = port.writable
      readLoop();
      if (port) {
          connectionToPortSuccessfulMessage = 'Connection successful'
          setPortFound(true)
      }
    }
  }

I've tried changing the permissions on the serial port by following this, so now if I run groups user I get user : user adm dialout cdrom sudo dip plugdev lpadmin lxd sambashare, but it still won't work.

I've also checked chrome://device-log to see if I could find any errors but all I get is info about (physically) adding or removing a USB device.

Share Improve this question edited Dec 7, 2020 at 23:45 MikeiLL 6,5805 gold badges43 silver badges73 bronze badges asked Oct 15, 2020 at 19:36 uberuber 5,1136 gold badges32 silver badges65 bronze badges 3
  • I'm having the same issue in Windows, but not on OSX. – MikeiLL Commented Dec 7, 2020 at 23:48
  • 1 In the device log, if you plugin and unplug your device, do you see: Serial->Event: Serial Device Added path=COM3, etc and USB->USER: USB Device added, etc and similar for removed? If I log the output of port.getSignals, that's where I'm seeing a Promise with State of "rejected" and Result of "DOMException: The device has been lost" – MikeiLL Commented Dec 8, 2020 at 0:03
  • Also, for me, initial connection works, but subsequent connections produce the error. – MikeiLL Commented Dec 8, 2020 at 0:21
Add a ment  | 

2 Answers 2

Reset to default 4

I believe the member name has recently been changed from 'baudrate' to 'baudRate'. At least in my case changing from 'baudrate' (which used to work) to 'baudRate' fixed it for me. Could it perhaps be Kubuntu is using an older chrome version that expects 'baudrate'.

Maybe permission and port select manuality, repost and script below. stackoverflow.

developer.mozilla

<button onclick="SerialRiderStart()">Connect</button>
    
<button id="Send" onclick="SerialWriter()">Send</button>
<button id="Read" onclick="SerialReader()">Read</button>
    
<script>
var port = "null";
//////////////////////////Serial begin/////////////////////////
async function SerialRiderStart() {
    
   port = await navigator.serial.requestPort();
   await port.open({ baudRate: 9600});  
   console.log(port.getInfo()); //Start debug.
}
//////////////////////////Serial read//////////////////////////    
async function SerialReader() {
    
    let reader = port.readable.getReader();
    let ReadData = await reader.read();   
    reader.releaseLock();    
    console.log(ReadData.value); //Read debug.
}
//////////////////////////Serial write/////////////////////////      
async function SerialWriter() {
    
    let data = new Uint8Array([79, 75, 32]); //"OK" String.
      
    let writer = port.writable.getWriter();
    await writer.write(data);
    writer.releaseLock();   
    console.log(data); //Send debug. 
}

</script>

本文标签: