List All Comport in a Combo list

Post

Posted
Rating:
#1 (In Topic #609)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
 Hi all,

Does anyone have any code they could share with me on how to get all active Comports and list them in a combo list so i can have it so a user can select them from the list
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
 try this (you need to be root or member of dialout):

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#3
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
 Hi PJ,

That works perfectly but i get a Error saying "Port must be closed first" but if you click ignore it works

how would i add that function to my own app now? as the file only had the exe in it and not the source code
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
very good question … i've deleted that one yesterday without thinking  :roll:

rewriting it  ;)

EDIT:

try out if it works …

Code (gambas)

  1.  
  2. Public Function GetActivePorts() As String[]
  3.  
  4.     Dim ReturnValue As New String[]
  5.     '----------------------------------------
  6.     Dim sShell As String
  7.     Dim aSerPorts As String[]
  8.  
  9.     oRS232 = New SerialPort
  10.  
  11.     Shell "ls -m /dev/ttyS*" To sShell
  12.     Replace(sShell, "\n", "")
  13.     aSerPorts = Split(sShell, ",")
  14.     For Each sSP As String In aSerPorts
  15.         oRS232.PortName = Trim(sSP)
  16.         Try oRS232.Open()
  17.         If oRS232.Status = Net.Active Then ReturnValue.add(sSP)
  18.         oRS232.Close
  19.     Next
  20.  
  21.     '----------------------------------------
  22.     Return ReturnValue
  23.  
  24.     ' Do some Error Handling if you like
  25.  
  26.  
Online now: No Back to the top

Post

Posted
Rating:
#5
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Thank-you PJ I shall add that to my project :)

For this to list USB Ports would I just change the tty to USB?
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’
 i did not have rs232 or usb2seriell converter so i'm not shure but i guess it will maybe named ttyUSBxx ???
Online now: No Back to the top

Post

Posted
Rating:
#7
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Ill try it and let you know

Some of my Printers are USB so I can test it :)
Online now: No Back to the top
1 guest and 0 members have just viewed this.