79111606

Date: 2024-10-21 20:12:43
Score: 3.5
Natty:
Report link

thanks for the link, indeed this is where I pulled some of my code...

I fiddled some more with my code and managed to get it running:

serial.js

    // get available USB devices 
serial.getPorts = async function() {
  console.log('Ser: getPorts'); 
  return navigator.usb.getDevices().then( devices => { // get WinUSB devices 
    console.log('getPorts: devices: ',devices)
    const deviceList = [];

    devices.sort((a, b) =>  a.serialNumber < b.serialNumber ? -1 : 1 );   // sort devices by serial number

    devices.forEach(element => {                    // list only devices of interest
      if (element.manufacturerName === 'Tardy' &&     
          element.productName === 'T-BOS 3.0')
        deviceList.push(new serial.Port(element));               
    });

    deviceList.forEach( element => {
      let listed = false; 

      // Check is the channel is already listed in channelListe
      channelList.forEach((item) => {                 // check if has already been listed
        if (item.serialNumber === element.device_.serialNumber) {
          listed = true;      
        }
      })

      // Not listed => Push the port to channelList... this creates a new entry...
      if (listed != true) {
        channelList.push(new channel(element.device_.productName + ' ' + element.device_.serialNumber, element.device_.serialNumber, 0));
      } 
    });

    console.log('getPorts: deviceList: ',deviceList)
    return deviceList;
  });
};

is working for me now.

I missed the need to add .device_. to access the entries of deviceList.

When pushing elements of devices (devices.forEach( element => ...) into my deviceList then .device_. is added? Any hint on this?

As you can see at the arrow device_ is added in deviceList

Greetings GvTT

Reasons:
  • Blacklisted phrase (0.5): thanks
  • Contains signature (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: GvTT