Serial Module - List Available Serial Ports

Hi

Is there a way to List the available serial ports in a drop down list on the client PC when using the serial module, I could do with a setup page to allow ‘engineers’ to change the assigned serial port number of a barcode scanner which is connected through a USB/Serial convertor, these can when plugged into different USB ports change there serial port assignment.

You would only be able to create a static drop down list of available ports to use. There isn’t going to be a way to grab the available ports then add them to the drop down.

No idea how fast this would be, but you might try using Ignition’s system.serial module to try all COM ports (1…255). If you get a connection, close it and add the COM# to a list and then display the list.

1 Like

I know this is a old post but for the next person who needs i wrote a quick little script that returns the active Serial ports and stores them in a dataset.

import telnetlib
import system

def serial_ports():
#    """ Lists serial port names
    #Create a list of Ports
    ports = ['COM%s' % (i + 1) for i in range(256)]
    #Place to store Active Ports
    result = []
    #System Declare
    s = system.serial
    #loop Through and try all the ports to find which are open
    for port in ports:
		try:
			print 'Connecting to Serial Port: ' + str(port)
			s.openSerialPort(port)
			s.closeSerialPort(port)
			#store active Ports
			result.append(port)
			print 'Port added to active list: ' + str(port)
		except:
			pass
			print 'PORT IS NOT ACTIVE: ' + str(port)
	#Return the Dataset of Ports.  
    return result
    
def main():
    ##Main SUB
	print'Start of Main'
	#Call Module for finding Serial Ports.
	ActivePorts = serial_ports()
	#Print Available Ports
	print ActivePorts
	print'End of Main'


#Main Sub Call
main()
1 Like

Since we upgraded to jserialcomm in most recent Ignition versions, the following should do the same thing:

from com.fazecast.jSerialComm import SerialPort

ports = list(SerialPort.getCommPorts())
1 Like

Well, your approach has the advantage of not closing every port. ):