Search in sources :

Example 6 with Programmer

use of jmri.Programmer in project JMRI by JMRI.

the class VSDConfigDialog method storeFile.

/**
     * Write roster settings to the Roster file
     */
protected boolean storeFile(RosterEntry _rosterEntry) {
    log.debug("storeFile starts");
    // We need to create a programmer, a cvTableModel, an iCvTableModel, and a variableTableModel.
    // Doesn't matter which, so we'll use the Global programmer.
    Programmer p = InstanceManager.getDefault(jmri.ProgrammerManager.class).getGlobalProgrammer();
    CvTableModel cvModel = new CvTableModel(null, p);
    IndexedCvTableModel iCvModel = new IndexedCvTableModel(null, p);
    VariableTableModel variableModel = new VariableTableModel(null, new String[] { "Name", "Value" }, cvModel, iCvModel);
    // Now, in theory we can call _rosterEntry.writeFile...
    if (_rosterEntry.getFileName() != null) {
        // set the loco file name in the roster entry
        // read, but don't yet process
        _rosterEntry.readFile();
        _rosterEntry.loadCvModel(variableModel, cvModel, iCvModel);
    }
    // id has to be set!
    if (_rosterEntry.getId().equals("")) {
        log.debug("storeFile without a filename; issued dialog");
        return false;
    }
    // if there isn't a filename, store using the id
    _rosterEntry.ensureFilenameExists();
    // create the RosterEntry to its file
    // where to get the models???
    _rosterEntry.writeFile(cvModel, iCvModel, variableModel);
    // mark this as a success
    variableModel.setFileDirty(false);
    // and store an updated roster file
    Roster.getDefault().writeRoster();
    return true;
}
Also used : CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) Programmer(jmri.Programmer) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel)

Example 7 with Programmer

use of jmri.Programmer in project JMRI by JMRI.

the class AbstractAutomaton method writeOpsModeCV.

/**
     * Write a CV in ops mode, including waiting for completion.
     *
     * @param CV          Number 1 through 512
     * @param value       0-255 value to be written
     * @param loco        Locomotive decoder address
     * @param longAddress true is the locomotive is using a long address
     * @return true if completed OK
     */
public boolean writeOpsModeCV(int CV, int value, boolean longAddress, int loco) {
    // get service mode programmer
    Programmer programmer = InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(longAddress, loco);
    if (programmer == null) {
        log.error("No programmer available as JMRI is currently configured");
        return false;
    }
    // do the write, response will wake the thread
    try {
        programmer.writeCV(CV, value, (int value1, int status) -> {
            synchronized (self) {
                // should be only one thread waiting, but just in case
                self.notifyAll();
            }
        });
    } catch (ProgrammerException e) {
        log.warn("Exception during writeServiceModeCV: " + e);
        return false;
    }
    // wait for the result
    wait(-1);
    return true;
}
Also used : ProgrammerException(jmri.ProgrammerException) Programmer(jmri.Programmer)

Example 8 with Programmer

use of jmri.Programmer in project JMRI by JMRI.

the class AbstractAutomaton method readServiceModeCV.

/**
     * Read a CV on the service track, including waiting for completion.
     *
     * @param CV Number 1 through 512
     * @return -1 if error, else value
     */
public int readServiceModeCV(int CV) {
    // get service mode programmer
    Programmer programmer = InstanceManager.getDefault(jmri.ProgrammerManager.class).getGlobalProgrammer();
    if (programmer == null) {
        log.error("No programmer available as JMRI is currently configured");
        return -1;
    }
    // do the read, response will wake the thread
    cvReturnValue = -1;
    try {
        programmer.readCV(CV, (int value, int status) -> {
            cvReturnValue = value;
            synchronized (self) {
                // should be only one thread waiting, but just in case
                self.notifyAll();
            }
        });
    } catch (ProgrammerException e) {
        log.warn("Exception during writeServiceModeCV: " + e);
        return -1;
    }
    // wait for the result
    wait(-1);
    return cvReturnValue;
}
Also used : ProgrammerException(jmri.ProgrammerException) Programmer(jmri.Programmer)

Example 9 with Programmer

use of jmri.Programmer in project JMRI by JMRI.

the class ProgServiceModeComboBox method programmerSelected.

/**
     * reload the interface with the new programmers
     */
void programmerSelected() {
    DefaultComboBoxModel<ProgrammingMode> model = new DefaultComboBoxModel<ProgrammingMode>();
    Programmer p = getProgrammer();
    if (p != null) {
        for (ProgrammingMode mode : getProgrammer().getSupportedModes()) {
            model.addElement(mode);
        }
    }
    log.trace("programmerSelected sets model");
    modeBox.setModel(model);
    ProgrammingMode mode = (getProgrammer() != null) ? getProgrammer().getMode() : null;
    log.trace("programmerSelected sets mode {}", mode);
    modeBox.setSelectedItem(mode);
}
Also used : Programmer(jmri.Programmer) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ProgrammingMode(jmri.ProgrammingMode)

Example 10 with Programmer

use of jmri.Programmer in project JMRI by JMRI.

the class RosterFrame method startIdentifyLoco.

/**
     * Start the identify operation after [Identify Loco] button pressed.
     * <p>
     * This defines what happens when the identify is done.
     */
//taken out of CombinedLocoSelPane
protected void startIdentifyLoco() {
    final RosterFrame me = this;
    Programmer programmer = null;
    if (modePanel.isSelected()) {
        programmer = modePanel.getProgrammer();
    }
    if (programmer == null) {
        GlobalProgrammerManager gpm = InstanceManager.getNullableDefault(GlobalProgrammerManager.class);
        if (gpm != null) {
            programmer = gpm.getGlobalProgrammer();
            log.warn("Selector did not provide a programmer, attempt to use GlobalProgrammerManager default: {}", programmer);
        } else {
            ProgrammerManager dpm = InstanceManager.getNullableDefault(jmri.ProgrammerManager.class);
            if (dpm != null) {
                programmer = dpm.getGlobalProgrammer();
                log.warn("Selector did not provide a programmer, attempt to use InstanceManager default: {}", programmer);
            } else {
                log.warn("Selector did not provide a programmer, and no ProgramManager found in InstanceManager");
            }
        }
    }
    // if failed to get programmer, tell user and stop
    if (programmer == null) {
        log.error("Identify loco called when no service mode programmer is available; button should have been disabled");
        JOptionPane.showMessageDialog(null, Bundle.getMessage("IdentifyError"));
        return;
    }
    // and now do the work
    IdentifyLoco ident = new IdentifyLoco(programmer) {

        private final RosterFrame who = me;

        @Override
        protected void done(int dccAddress) {
            // if Done, updated the selected decoder
            // on the GUI thread, right now
            jmri.util.ThreadingUtil.runOnGUI(() -> {
                who.selectLoco(dccAddress, !shortAddr, cv8val, cv7val);
            });
        }

        @Override
        protected void message(String m) {
            // on the GUI thread, right now
            jmri.util.ThreadingUtil.runOnGUI(() -> {
                statusField.setText(m);
            });
        }

        @Override
        protected void error() {
        // raise the button again
        //idloco.setSelected(false);
        }
    };
    ident.start();
}
Also used : Programmer(jmri.Programmer) ProgrammerManager(jmri.ProgrammerManager) GlobalProgrammerManager(jmri.GlobalProgrammerManager) AddressedProgrammerManager(jmri.AddressedProgrammerManager) IdentifyLoco(jmri.jmrit.roster.IdentifyLoco) GlobalProgrammerManager(jmri.GlobalProgrammerManager)

Aggregations

Programmer (jmri.Programmer)63 ProgDebugger (jmri.progdebugger.ProgDebugger)33 ProgListener (jmri.ProgListener)27 JFrame (javax.swing.JFrame)4 JPanel (javax.swing.JPanel)3 ProgrammerException (jmri.ProgrammerException)3 IdentifyLoco (jmri.jmrit.roster.IdentifyLoco)3 PaneOpsProgFrame (jmri.jmrit.symbolicprog.tabbedframe.PaneOpsProgFrame)3 BoxLayout (javax.swing.BoxLayout)2 JLabel (javax.swing.JLabel)2 JMenuBar (javax.swing.JMenuBar)2 AddressedProgrammerManager (jmri.AddressedProgrammerManager)2 GlobalProgrammerManager (jmri.GlobalProgrammerManager)2 DecoderFile (jmri.jmrit.decoderdefn.DecoderFile)2 IdentifyDecoder (jmri.jmrit.decoderdefn.IdentifyDecoder)2 ProgModeSelector (jmri.jmrit.progsupport.ProgModeSelector)2 RosterEntry (jmri.jmrit.roster.RosterEntry)2 CvTableModel (jmri.jmrit.symbolicprog.CvTableModel)2 IndexedCvTableModel (jmri.jmrit.symbolicprog.IndexedCvTableModel)2 KnownLocoSelPane (jmri.jmrit.symbolicprog.KnownLocoSelPane)2