DavesCodeMusings / mpremote-vscode

Visual Studio Code extension for mpremote Python module
BSD 2-Clause "Simplified" License
10 stars 1 forks source link

Serial Port Skip List #22

Closed SteveKerle closed 2 months ago

SteveKerle commented 3 months ago

The serial port skip list does not appear to work correctly. On my system I add four entries, /dev/ttyS0,/dev/ttyS1,/dev/ttyS2,/dev/ttyS3. Only /dev/ttyS0 and /dev/ttyS2 are removed from the serial port list.

DavesCodeMusings commented 3 months ago

I am not able to recreate this. I'm using Windows and I don't have enough serial ports. If anyone out there has a similar setup and can lend a hand, I'd appreciate any insights.

What I was able to do was verify the serial port skip list shows up properly in debugging info and that a port in the skip list does indeed get skipped. (See below.)

With /dev/ttyS0,/dev/ttyS1,/dev/ttyS2,/dev/ttyS3 in the skip list...

Calling mpremote as: py.exe -m mpremote
Creating new mpremote terminal.
mpremote version: 1.22.0
Detected serial ports: (1) [{…}]
Serial port skip list: (4) ['/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/ttyS3']
Avaiable serial ports: (1) [TreeItem]
arg1:
(1) [TreeItem]
0:
TreeItem {collapsibleState: 0, label: 'COM9'}
length:
1

With COM9 by itself in the skip list...

Calling mpremote as: py.exe -m mpremote
Creating new mpremote terminal.
mpremote version: 1.22.0
Detected serial ports: (1) [{…}]
Serial port skip list: (1) ['COM9']
Avaiable serial ports: (0) []
arg1:
(0) []
length:
0

I also tried various combinations like: COM1,COM2,COM3,COM4 ; COM1,COM2,COM3,COM4,COM9,COM10 and all results were consistent with expected behavior.

The only thing I can think of to suspect is hot-plugging USB devices. If you add or remove a device, you need to hover over SERIAL PORTS in the VS Code Explorer pane (on the left side of VS Code) and click the Refresh icon (circular arrow thing.)

mhavill commented 3 months ago

I am having the same issue as Steve on Windows 10 I have 3 ports which are dedicated to my laptop subsystems COM3, COM4, COM5 However when I out "COM3, COM4, COM5" in the skip list, it will hide only COM4 and COM5 I am currently using COM15 for my microcontroller

DavesCodeMusings commented 3 months ago

Just curious if folks are using spaces after commas or not.

If you are using spaces after the commas, try taking them out and see if that fixes things. It might be a whitespace problem. Just a guess.

SteveKerle commented 3 months ago

Sorry for taking a while to reply, only just returned from the UK and didn't have my laptop with me. I don't have much experience of Javascript but I would suspect the refresh function in PortListDataProvider. The comPortList is iterated over using a for loop. If found in comPortSkipList then that com port is removed using the splice function which will cause all following entries to be shifted in the list. The for loop will then increment causing the entry after one that has been removed by the splice function to be skipped from the check.

mhavill commented 3 months ago

Hi Steve,Sounds like a good idea. For me trying to hide COM3, COM4 and COM5 it seems to leave COM3 regardless of its order in the list. Just any two in the list and both are hidden. BtW same result with and without spaces between entries.  SteveKerle @.***> wrote: Sorry for taking a while to reply, only just returned from the UK and didn't have my laptop with me. I don't have much experience of Javascript but I would suspect the refresh function in PortListDataProvider. The comPortList is iterated over using a for loop. If found in comPortSkipList then that com port is removed using the splice function which will cause all following entries to be shifted in the list. The for loop will then increment causing the entry after one that has been removed by the splice function to be skipped from the check.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

DavesCodeMusings commented 3 months ago

@SteveKerle ... No problem. Been on spring break myself and still catching up. Probably be a while before I can look at it in depth.

SteveKerle commented 3 months ago

I don't yet know how to build and test vscode extensions so am unable to test my suggestion but may I propose the code below

this.portList = [];
for (let i=0; i<comPortList.length; i++) {
    if (comPortSkipList.includes(comPortList[i].path)) {
        comPortList.splice(i, 1);
    }
}
comPortList.forEach(port => {
    this.portList.push(new TreeItem(port.path));
});
console.debug('Avaiable serial ports:', this.portList);

is changed to something like this?

this.portList = [];
comPortList.forEach(port => {
    if (!comPortSkipList.includes(port.path)) {
        this.portList.push(new TreeItem(port.path));
    }
});
console.debug('Avaiable serial ports:', this.portList);
DavesCodeMusings commented 3 months ago

@SteveKerle I started building extensions with the help of this dude's video: https://www.youtube.com/watch?v=q5V4T3o3CXE

DavesCodeMusings commented 2 months ago

Sorry to take so long on this. Looks like @SteveKerle has identified the problem and the proposed solution should do the trick.

DavesCodeMusings commented 2 months ago

Updating to version 1.21.10 should fix this bug. I only have one serial device and that's the ESP32, so I'm unable to test. Nothing is broken, so I'm closing the issue. Please open a new issue if the problem persists.