use of jmri.JmriException in project JMRI by JMRI.
the class MarklinSensorManager 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) {
port++;
while (port < 17) {
try {
tmpSName = createSystemName(board + ":" + port, prefix);
} catch (Exception e) {
log.error("Error creating system name for " + board + ":" + port);
}
s = getBySystemName(tmpSName);
if (s == null) {
StringBuilder sb = new StringBuilder();
sb.append(board);
sb.append(":");
//Little work around to pad single digit address out.
padPortNumber(port, sb);
return sb.toString();
}
port++;
}
return null;
} else {
StringBuilder sb = new StringBuilder();
sb.append(board);
sb.append(":");
//Little work around to pad single digit address out.
padPortNumber(port, sb);
return sb.toString();
}
}
use of jmri.JmriException in project JMRI by JMRI.
the class MarklinSensorManager 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();
}
use of jmri.JmriException in project JMRI by JMRI.
the class SerialSensorManager 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;
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 AbstractTurnout method setStraightSpeed.
@Override
public void setStraightSpeed(String s) throws JmriException {
if (s == null) {
throw new JmriException("Value of requested turnout straight speed can not be null");
}
if (_straightSpeed.equals(s)) {
return;
}
if (s.contains("Global")) {
s = "Global";
} else if (s.contains("Block")) {
s = "Block";
} else {
try {
Float.parseFloat(s);
} catch (NumberFormatException nx) {
try {
jmri.InstanceManager.getDefault(SignalSpeedMap.class).getSpeed(s);
} catch (Exception ex) {
throw new JmriException("Value of requested turnout straight speed is not valid");
}
}
}
String oldSpeed = _straightSpeed;
_straightSpeed = s;
firePropertyChange("TurnoutStraightSpeedChange", oldSpeed, s);
}
use of jmri.JmriException in project JMRI by JMRI.
the class DefaultRoute method checkTurnoutAlignment.
/**
* Method to check if the turnouts for this route are correctly aligned.
* Sets turnouits aligned sensor (if there is one) to active if the turnouts
* are aligned. Sets the sensor to inactive if they are not aligned
*/
public void checkTurnoutAlignment() {
//check each of the output turnouts in turn
//turnouts are deemed not aligned if:
// - commanded and known states don't agree
// - non-toggle turnouts known state not equal to desired state
// turnouts aligned sensor is then set accordingly
Sensor sensor = this.getTurnoutsAlgdSensor();
if (sensor != null) {
try {
// route shows it as ACTIVE when it may not really be
if (this.isRouteBusy()) {
sensor.setKnownState(Sensor.INCONSISTENT);
return;
}
for (OutputTurnout ot : this._outputTurnoutList) {
Turnout turnout = ot.getTurnout();
int targetState = ot.getState();
if (!turnout.isConsistentState()) {
sensor.setKnownState(Sensor.INCONSISTENT);
return;
}
if (targetState != Route.TOGGLE && targetState != turnout.getKnownState()) {
sensor.setKnownState(Sensor.INACTIVE);
return;
}
}
sensor.setKnownState(Sensor.ACTIVE);
} catch (JmriException ex) {
log.warn("Exception setting sensor {} in route", getTurnoutsAlignedSensor());
}
}
}
Aggregations