Search in sources :

Example 36 with JmriException

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();
    }
}
Also used : JmriException(jmri.JmriException) JmriException(jmri.JmriException) Sensor(jmri.Sensor)

Example 37 with JmriException

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();
}
Also used : JmriException(jmri.JmriException)

Example 38 with JmriException

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);
    }
}
Also used : JmriException(jmri.JmriException) Sensor(jmri.Sensor)

Example 39 with JmriException

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);
}
Also used : JmriException(jmri.JmriException) JmriException(jmri.JmriException)

Example 40 with JmriException

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());
        }
    }
}
Also used : JmriException(jmri.JmriException) Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Aggregations

JmriException (jmri.JmriException)80 Sensor (jmri.Sensor)22 JsonException (jmri.server.json.JsonException)22 IOException (java.io.IOException)20 JsonNode (com.fasterxml.jackson.databind.JsonNode)19 JsonMockConnection (jmri.server.json.JsonMockConnection)18 ArrayList (java.util.ArrayList)10 NamedBean (jmri.NamedBean)10 Turnout (jmri.Turnout)10 Test (org.junit.Test)7 SignalMast (jmri.SignalMast)6 ConfigureManager (jmri.ConfigureManager)5 SensorManager (jmri.SensorManager)5 File (java.io.File)4 PowerManager (jmri.PowerManager)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Light (jmri.Light)3 SignalHead (jmri.SignalHead)3 FileNotFoundException (java.io.FileNotFoundException)2 Hashtable (java.util.Hashtable)2