use of jmri.Programmer in project JMRI by JMRI.
the class PaneOpsProgAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (log.isDebugEnabled()) {
log.debug("Pane programmer requested");
}
// create the initial frame that steers
final JmriJFrame f = new JmriJFrame(SymbolicProgBundle.getMessage("FrameOpsProgrammerSetup"));
f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
// add the Roster menu
JMenuBar menuBar = new JMenuBar();
// menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
menuBar.add(new jmri.jmrit.roster.swing.RosterMenu(SymbolicProgBundle.getMessage("MenuRoster"), jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
f.setJMenuBar(menuBar);
// known loco on main track
JPanel pane1 = new // no ident in ops mode yet
KnownLocoSelPane(// no ident in ops mode yet
false) {
@Override
protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String filename) {
String title = java.text.MessageFormat.format(SymbolicProgBundle.getMessage("FrameOpsProgrammerTitle"), new Object[] { re.getId() });
// find the ops-mode programmer
int address = Integer.parseInt(re.getDccAddress());
boolean longAddr = re.isLongAddress();
Programmer programmer = InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(longAddr, address);
// and created the frame
JFrame p = new PaneOpsProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", programmer);
p.pack();
p.setVisible(true);
// f.setVisible(false);
// f.dispose();
}
};
// load primary frame
pane1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
f.getContentPane().add(pane1);
f.pack();
if (log.isDebugEnabled()) {
log.debug("Tab-Programmer setup created");
}
f.setVisible(true);
}
use of jmri.Programmer in project JMRI by JMRI.
the class VSDConfigPanel method storeFile.
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 MultiIndexProgrammerFacadeTest method testWriteReadDoubleIndexed.
public void testWriteReadDoubleIndexed() throws jmri.ProgrammerException, InterruptedException {
ProgDebugger dp = new ProgDebugger();
Programmer p = new MultiIndexProgrammerFacade(dp, "81", "82", true, false);
ProgListener l = new ProgListener() {
@Override
public void programmingOpReply(int value, int status) {
log.debug("callback value=" + value + " status=" + status);
replied = true;
readValue = value;
}
};
p.writeCV("123.45.46", 12, l);
waitReply();
Assert.assertEquals("index 1 written", 45, dp.getCvVal(81));
Assert.assertEquals("index 2 written", 46, dp.getCvVal(82));
Assert.assertEquals("value written", 12, dp.getCvVal(123));
dp.clearHasBeenWritten(81);
dp.clearHasBeenWritten(82);
p.readCV("123.45.46", l);
waitReply();
Assert.assertEquals("read back", 12, readValue);
Assert.assertEquals("index 1 written", 45, dp.getCvVal(81));
Assert.assertEquals("index 2 written", 46, dp.getCvVal(82));
}
use of jmri.Programmer in project JMRI by JMRI.
the class MultiIndexProgrammerFacadeTest method testWriteReadDoubleIndexedSkip.
public void testWriteReadDoubleIndexedSkip() throws jmri.ProgrammerException, InterruptedException {
ProgDebugger dp = new ProgDebugger();
Programmer p = new MultiIndexProgrammerFacade(dp, "81", "82", true, true);
ProgListener l = new ProgListener() {
@Override
public void programmingOpReply(int value, int status) {
log.debug("callback value=" + value + " status=" + status);
replied = true;
readValue = value;
}
};
p.writeCV("123.45.46", 12, l);
waitReply();
Assert.assertEquals("index 1 written", 45, dp.getCvVal(81));
Assert.assertEquals("index 2 written", 46, dp.getCvVal(82));
Assert.assertEquals("value written", 12, dp.getCvVal(123));
dp.clearHasBeenWritten(81);
dp.clearHasBeenWritten(82);
p.readCV("123.45.46", l);
waitReply();
Assert.assertEquals("read back", 12, readValue);
Assert.assertTrue("index 1 not written", !dp.hasBeenWritten(81));
Assert.assertTrue("index 2 not written", !dp.hasBeenWritten(82));
}
use of jmri.Programmer in project JMRI by JMRI.
the class MultiIndexProgrammerFacadeTest method testWriteReadSingleIndexed.
public void testWriteReadSingleIndexed() throws jmri.ProgrammerException, InterruptedException {
ProgDebugger dp = new ProgDebugger();
Programmer p = new MultiIndexProgrammerFacade(dp, "81", "82", true, false);
ProgListener l = new ProgListener() {
@Override
public void programmingOpReply(int value, int status) {
log.debug("callback value=" + value + " status=" + status);
replied = true;
readValue = value;
}
};
p.writeCV("123.45", 12, l);
waitReply();
Assert.assertEquals("index 1 written", 45, dp.getCvVal(81));
Assert.assertTrue("index 2 not written", !dp.hasBeenWritten(82));
Assert.assertEquals("value written", 12, dp.getCvVal(123));
dp.clearHasBeenWritten(81);
dp.clearHasBeenWritten(82);
p.readCV("123.45", l);
waitReply();
Assert.assertEquals("read back", 12, readValue);
Assert.assertEquals("index 1 written", 45, dp.getCvVal(81));
Assert.assertTrue("index 2 not written", !dp.hasBeenWritten(82));
Assert.assertEquals("index written", 45, dp.getCvVal(81));
}
Aggregations