Finding serial ports doesn't work on Windows

Filling a popup menu with the names of serial ports works on my Mac but not on Windows 10. Under windows10, SerialDevice.LastIndex finds the right number of ports, but then filling a popupmenu with serial port names throws an array bounds exception at PopupMenu1.AddRow(SerialDevice.At(i).Name. It’s as if Windows knows the ports are there, but didn’t bother to get all their names. Is there a way of telling windows to update its list to get all the names? Or to tell Xojo to stop reporting a different number of available serial ports than it has names for? Is there a workaround for this? Thanks,

I have only 1 serialDevice (COM1) currently.

Var count As Integer = SerialDevice.Count

If count > 0 Then
  Var lastIndex As Integer = SerialDevice.LastIndex
  For i As Integer = 0 To lastIndex
    System.DebugLog "Index: " + i.ToString + " PORT: "+ SerialDevice.At(i).Name
End If

This does work here shows: Index: 0 PORT: COM1
in the debug messages.

How many ports do you have? and what should their names be? COM1, COM10 ?

I remember I once made WindowsSerialPortsMBS class to find ports.

If it’s throwing an out of bounds exception it’s because SerialDeviceAt() doesn’t have a member at i, not because there’s a device there without a name.

Seems like a device or devices has been removed from the system between whenever you got LastIndex and when you try to populate the PopUpMenu.

Julia, your response prompted me to look for something that might be taking away serial ports. XOJO would find the correct number of ports (4) but somehow the array only had 2 names it. There was a USB serial port manager driver software installed on the computer (Eltima Virtual Serial Port Driver 10) that was somehow interfering with the creation of the array or taking away ports. I uninstalled it, and now the out-of-bounds exception is gone and it works properly.

1 Like
Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.