def getSerialHandlerForPort(port):
	""" Return a constructed and started SerialHandler for a port.
	:param port: A serial port name
	:return: A SerialHandler instance
	"""
	serialHandler = SerialHandler()
	serialHandler.openPort(port)
	serialHandler.start()
	return serialHandler
	def __init__(self, port, addDeviceCallback):
		threading.Thread.__init__(self)
		self.daemon = True
		self.port = port
		self.serialHandler = SerialHandler()
		self.messages = queue.Queue()
		self.addDeviceCallback = addDeviceCallback
class DeviceQueryThread(threading.Thread):
	""" Support class for identifying the type of device on a port """
	timeoutInSeconds = 0.5

	def __init__(self, port, addDeviceCallback):
		threading.Thread.__init__(self)
		self.daemon = True
		self.port = port
		self.serialHandler = SerialHandler()
		self.messages = queue.Queue()
		self.addDeviceCallback = addDeviceCallback

	def run(self):
		try:
			self.serialHandler.openPort(self.port[0])
			self.serialHandler.start()
		except (SerialPortLocked, BlockingIOError) as exception:
			# ignore locked port errors, devices may already be open
			return
		except IOError:
			logger.exception("Failed to open port %s", self.port)
			return
		try:
			device = PractichemSerialDevice(None, self.serialHandler)
			deviceInfo = {portId: self.port[0]}
			deviceInfo[productNameId] = device.getProductName()
			deviceInfo[productNumberId] = device.getProductNumber()
			deviceInfo[firmwareVersionId] = device.getFirmwareVersion()
			deviceInfo[firmwareBuildDateId] = device.getFirmwareBuildDate()
			deviceInfo[uuidId] = device.getUuid()
			self.addDeviceCallback(deviceInfo)
		except (IOError, queue.Empty):
			# the device had a valid Practichem CDC VID:PID combination, failure means the device is not functioning
			logger.error("Practichem device not found on %s", self.port)
		finally:
			device.shutdown()
			# need to wait for the serial handler to shutdown to free the port, otherwise the
			# main application will fail trying to open the port
			self.serialHandler.join(10)