static public SerialPort getCommPort()

in src/main/java/com/fazecast/jSerialComm/SerialPort.java [511:558]


	static public SerialPort getCommPort(String portDescriptor) throws SerialPortInvalidPortException
	{
		// Make this method a no-op on Android
		if (isAndroid)
			return null;

		// Correct port descriptor, if needed
		libraryLock.lock();
		final String originalPortDescriptor = portDescriptor;
		try
		{
			// Resolve home directory ~
			if (portDescriptor.startsWith("~" + File.separator))
				portDescriptor = System.getProperty("user.home", "/tmp") + portDescriptor.substring(1);

			// See what kind of descriptor was passed in
			if (isWindows)
				portDescriptor = "\\\\.\\" + portDescriptor.substring(portDescriptor.lastIndexOf('\\')+1);
			else if (isSymbolicLink(new File(portDescriptor)))
				portDescriptor = (new File(portDescriptor)).getCanonicalPath();
			else if (!((new File(portDescriptor)).exists()))
			{
				// Attempt to locate the correct port descriptor
				portDescriptor = "/dev/" + portDescriptor;
				if (!((new File(portDescriptor)).exists()))
					portDescriptor = "/dev/" + portDescriptor.substring(portDescriptor.lastIndexOf('/')+1);

				// Check if the updated port descriptor exists
				if (!((new File(portDescriptor)).exists()))
					throw new IOException();
			}

			// Create the SerialPort object
			SerialPort serialPort = new SerialPort();
			serialPort.comPort = portDescriptor;
			serialPort.vendorID = serialPort.productID = -1;
			serialPort.friendlyName = "User-Specified Port";
			serialPort.portDescription = "User-Specified Port";
			serialPort.serialNumber = "Unknown";
			serialPort.manufacturer = "Unknown";
			serialPort.deviceDriver = "Unknown";
			serialPort.portLocation = "0-0";
			serialPort.retrievePortDetails();
			return serialPort;
		}
		catch (Exception e) { throw new SerialPortInvalidPortException("Unable to create a serial port object from the invalid port descriptor: " + originalPortDescriptor, e); }
		finally { libraryLock.unlock(); }
	}