public static void testDevicePathToInvalidTTYInCommPortIdentifier() throws Exception { begin("TestDevicePathToInvalidTTY");// - getPortIdentifier on invalid device"); // Must throw NoSuchPortException File tempFile = File.createTempFile("pjc", null); tempFile.deleteOnExit(); try { CommPortIdentifier.getPortIdentifier(tempFile.getAbsolutePath()); fail("Got an identifier for an invalid device"); } catch (NoSuchPortException nspe) { // All good } finishedOK(); } }
.getPortIdentifier(m_Port); if (id == null) { fail("No id for this serial port");
SerialPort p = (SerialPort) CommPortIdentifier.getPortIdentifier( args[0]).open(TwoPortSerialTest.class.getName(), 0);
public static void testMissingPortInCommPortIdentifier() throws Exception { begin("TestMissingPort"); // - getPortIdentifier on missing port // Must throw NoSuchPortException try { CommPortIdentifier.getPortIdentifier("blablub"); fail("Got an identifier for non-exisiting path"); } catch (NoSuchPortException nspe) { // All good } finishedOK(); }
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(portName);
SerialPort p = (SerialPort) CommPortIdentifier.getPortIdentifier( args[0]).open(TwoPortSerialTest.class.getName(), 0);
public static void testDevicePathInCommPortIdentifier() throws Exception { begin("TestDevicePath "); // - getPortIdentifier on device path"); // Must return an identifier try { CommPortIdentifier.getPortIdentifier(getPortName()); } catch (NoSuchPortException nspe) { fail("Couldn't obtain identifier for device path"); } finishedOK(); }
CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier( portName );
static protected void openPort() throws Exception { try { CommPortIdentifier portid = CommPortIdentifier.getPortIdentifier(m_TestPortName); m_Port = (SerialPort) portid.open(APPLICATION_NAME, 1000); m_Out = m_Port.getOutputStream(); m_In = m_Port.getInputStream(); drain(m_In); } catch (NoSuchPortException e) { fail("could no open port '%s'\n", m_TestPortName); } }
static protected void openPort() throws Exception { try { CommPortIdentifier portid = CommPortIdentifier.getPortIdentifier(m_TestPortName); m_Port = (SerialPort) portid.open("PureJavaCommTestSuite", 1000); m_Out = m_Port.getOutputStream(); m_In = m_Port.getInputStream(); drain(m_In); } catch (NoSuchPortException e) { fail("could no open port '%s'\n", m_TestPortName); } }
/** * Returns the serial port instance. * * @param aOptions * the serial port options, cannot be <code>null</code>. * @return the serial port instance, never <code>null</code>. * @throws NoSuchPortException * in case the desired port does not exist; * @throws PortInUseException * in case the desired port is already in use; * @throws IOException * in case of other I/O problems. */ private SerialPort getSerialPort( final CommPortOptions aOptions ) throws NoSuchPortException, PortInUseException, IOException { final CommPortIdentifier commPortId = CommPortIdentifier.getPortIdentifier( aOptions.getPortName() ); if ( commPortId.isCurrentlyOwned() && ( commPortId.getCurrentOwner() != CONNECT_ID ) ) { throw new PortInUseException(); } final CommPort commPort = commPortId.open( CONNECT_ID, 2000 ); if ( !( commPort instanceof SerialPort ) ) { throw new IOException( "Not a serial port?!" ); } return ( SerialPort )commPort; }