Skip to content

Commit

Permalink
Added request for full list of CommPortIdentifiers if we're unable to…
Browse files Browse the repository at this point in the history
… get identifer by name.

Signed-off-by: Denis Denisov <[email protected]>
  • Loading branch information
denis-ftc-denisov committed Mar 16, 2021
1 parent bbab48b commit e637ed0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/net/wimpi/modbus/net/SerialConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class SerialConnection implements SerialPortEventListener, ModbusSlaveCon
private SerialPort m_SerialPort;
private boolean m_Open;
private InputStream m_SerialIn;
private boolean m_PortsRequested;

/**
* Creates a SerialConnection object and initializes variables passed in
Expand All @@ -66,6 +67,7 @@ public class SerialConnection implements SerialPortEventListener, ModbusSlaveCon
public SerialConnection(SerialParameters parameters) {
m_Parameters = parameters;
m_Open = false;
m_PortsRequested = false;
}// constructor

/**
Expand Down Expand Up @@ -111,7 +113,15 @@ public void open() throws Exception {

// 1. obtain a CommPortIdentifier instance
try {
m_PortIdentifyer = CommPortIdentifier.getPortIdentifier(m_Parameters.getPortName());
try {
m_PortIdentifyer = CommPortIdentifier.getPortIdentifier(m_Parameters.getPortName());
} catch (NoSuchPortException e) {
if (!m_PortsRequested) {
CommPortIdentifier.getPortIdentifiers();
} else {
throw e;
}
}
} catch (NoSuchPortException e) {
final String errMsg = "Could not get port identifier, maybe insufficient permissions. " + e.getMessage();
logger.debug("Could not get port identifier, maybe insufficient permissions. {}: {}",
Expand Down

0 comments on commit e637ed0

Please sign in to comment.