openPort();
// Check ownership of the id of our test port first
{
CommPortIdentifier id = CommPortIdentifier
.getPortIdentifier(m_Port);
if (id == null) {
fail("No id for this serial port");
}
if (id.getCurrentOwner() == null
|| !id.getCurrentOwner().equals(APPLICATION_NAME)) {
fail("Wrong or missing owner for this serial port (got \"%s\", expected \"%s\")",
id.getCurrentOwner(), APPLICATION_NAME);
}
}
//first call to enumerate port identifiers
cpiEnum = CommPortIdentifier.getPortIdentifiers();
//get original owner name
while (cpiEnum.hasMoreElements()) {
CommPortIdentifier cpi = cpiEnum.nextElement();
if (cpi.getName().equals(getPortName())) {
origOwnerName = cpi.getCurrentOwner();
break;
}
}
//second call to enumerate port identifiers
cpiEnum = CommPortIdentifier.getPortIdentifiers();
//get owner name again
while (cpiEnum.hasMoreElements()) {
CommPortIdentifier cpi = cpiEnum.nextElement();
if (cpi.getName().equals(getPortName())) {
checkOwnerName = cpi.getCurrentOwner();
break;
}
}
//these should be exactly the same