use of jmri.JmriException in project JMRI by JMRI.
the class Dcc4PcSensorManager method createSystemName.
//we want the system name to be in the format of board:input
@Override
public String createSystemName(String curAddress, String prefix) throws JmriException {
String iName;
if (curAddress.contains(":")) {
board = 0;
channel = 0;
//Address format passed is in the form of board:channel or T:turnout address
int seperator = curAddress.indexOf(":");
try {
board = Integer.valueOf(curAddress.substring(0, seperator));
} catch (NumberFormatException ex) {
log.error("Unable to convert " + curAddress + " into the cab and channel format of nn:xx");
throw new JmriException("Hardware Address passed should be a number");
}
try {
channel = Integer.valueOf(curAddress.substring(seperator + 1));
if ((channel > 16) || (channel < 1)) {
log.error("Channel number is out of range");
throw new JmriException("Channel number should be in the range of 1 to 16");
}
} catch (NumberFormatException ex) {
log.error("Unable to convert " + curAddress + " into the cab and channel format of nn:xx");
throw new JmriException("Hardware Address passed should be a number");
}
iName = curAddress;
} else {
log.error("Unable to convert " + curAddress + " Hardware Address to a number");
throw new JmriException("Unable to convert " + curAddress + " Hardware Address to a number");
}
return prefix + typeLetter() + iName;
}
use of jmri.JmriException in project JMRI by JMRI.
the class DCCppSensorManager method getNextValidAddress.
/**
* Does not enforce any rules on the encoder or input values.
*/
@Override
public synchronized String getNextValidAddress(String curAddress, String prefix) {
String tmpSName = "";
try {
tmpSName = createSystemName(curAddress, prefix);
} catch (JmriException ex) {
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showErrorMessage("Error", "Unable to convert " + curAddress + " to a valid Hardware Address", "" + ex, "", true, false);
return null;
}
//Check to determine if the systemName is in use, return null if it is,
//otherwise return the next valid address.
Sensor s = getBySystemName(tmpSName);
if (s != null) {
for (int x = 1; x < 10; x++) {
iName = iName + 1;
s = getBySystemName(prefix + typeLetter() + iName);
if (s == null) {
return Integer.toString(iName);
}
}
return null;
} else {
return Integer.toString(iName);
}
}
use of jmri.JmriException in project JMRI by JMRI.
the class SerialSensorManager method createSystemName.
@Override
public String createSystemName(String curAddress, String prefix) throws JmriException {
if (curAddress.contains(":")) {
//Address format passed is in the form of sysNode:address or T:turnout address
int seperator = curAddress.indexOf(":");
try {
sysNode = Integer.valueOf(curAddress.substring(0, seperator)).intValue();
address = Integer.valueOf(curAddress.substring(seperator + 1)).intValue();
} catch (NumberFormatException ex) {
log.error("Unable to convert " + curAddress + " into the cab and address format of nn:xx");
throw new JmriException("Hardware Address passed should be a number");
}
iName = (sysNode * 1000) + address;
} else {
//Entered in using the old format
try {
iName = Integer.parseInt(curAddress);
} catch (NumberFormatException ex) {
log.error("Unable to convert " + curAddress + " Hardware Address to a number");
throw new JmriException("Hardware Address passed should be a number");
}
}
return prefix + typeLetter() + iName;
}
use of jmri.JmriException in project JMRI by JMRI.
the class NceSensorManager method getNextValidAddress.
@Override
public String getNextValidAddress(String curAddress, String prefix) {
String tmpSName = "";
try {
tmpSName = createSystemName(curAddress, prefix);
} catch (JmriException ex) {
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showErrorMessage("Error", "Unable to convert " + curAddress + " to a valid Hardware Address", "" + ex, "", true, false);
return null;
}
//Check to determine if the systemName is in use, return null if it is,
//otherwise return the next valid address.
Sensor s = getBySystemName(tmpSName);
if (s != null) {
for (int x = 1; x < 10; x++) {
iName = iName + 1;
pin = pin + 1;
if (pin > MAXPIN) {
return null;
}
s = getBySystemName(prefix + typeLetter() + iName);
if (s == null) {
return Integer.toString(iName);
}
}
return null;
} else {
return Integer.toString(iName);
}
}
use of jmri.JmriException in project JMRI by JMRI.
the class TamsSensorManager method createSystemName.
@Override
public String createSystemName(String curAddress, String prefix) throws JmriException {
if (!curAddress.contains(":")) {
log.error("Unable to convert " + curAddress + " into the Module and port format of nn:xx");
throw new JmriException("Hardware Address passed should be past in the form 'Module:port'");
}
//Address format passed is in the form of board:channel or T:turnout address
int seperator = curAddress.indexOf(":");
try {
board = Integer.valueOf(curAddress.substring(0, seperator)).intValue();
} catch (NumberFormatException ex) {
log.error("Unable to convert " + curAddress + " into the Module and port format of nn:xx");
throw new JmriException("Module Address passed should be a number");
}
try {
port = Integer.valueOf(curAddress.substring(seperator + 1)).intValue();
} catch (NumberFormatException ex) {
log.error("Unable to convert " + curAddress + " into the Module and port format of nn:xx");
throw new JmriException("Port Address passed should be a number");
}
if (port == 0 || port > 16) {
log.error("Port number must be between 1 and 16");
throw new JmriException("Port number must be between 1 and 16");
}
StringBuilder sb = new StringBuilder();
sb.append(getSystemPrefix());
sb.append("S");
sb.append(board);
sb.append(":");
//Little work around to pad single digit address out.
padPortNumber(port, sb);
return sb.toString();
}
Aggregations