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;
}
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;
}
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;
}
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);
}
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();
}
Aggregations