use of jmri.Programmer in project JMRI by JMRI.
the class DebugProgrammerManagerTest method testOpsModeDistinct.
/**
* Any identical ops mode request gets the same object
*/
public void testOpsModeDistinct() {
InstanceManager.setProgrammerManager(new DebugProgrammerManager());
Programmer p = InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(true, 777);
Assert.assertTrue("different ops mode programmer", InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(true, 888) != p);
Assert.assertTrue("same ops mode programmer", InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(true, 777) == p);
}
use of jmri.Programmer in project JMRI by JMRI.
the class DebugProgrammerTest method testWriteReadString.
// Test names ending with "String" are for the new writeCV(String, ...)
// etc methods. If you remove the older writeCV(int, ...) tests,
// you can rename these. Note that not all (int,...) tests may have a
// String(String, ...) test defined, in which case you should create those.
public void testWriteReadString() throws jmri.ProgrammerException, InterruptedException {
Programmer p = new ProgDebugger();
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("4", 12, l);
waitReply();
log.debug("readValue is " + readValue);
p.readCV("4", l);
waitReply();
log.debug("readValue is " + readValue);
Assert.assertEquals("read back", 12, readValue);
}
use of jmri.Programmer in project JMRI by JMRI.
the class AbstractAutomaton method writeServiceModeCV.
/**
* Write a CV on the service track, including waiting for completion.
*
* @param CV Number 1 through 512
* @param value Value 0-255 to be written
* @return true if completed OK
*/
public boolean writeServiceModeCV(int CV, int value) {
// 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 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 DualDecoderSelectPane method readCV16.
void readCV16() {
Programmer p = modePane.getProgrammer();
if (p == null) {
state = IDLE;
status.setText(Bundle.getMessage("NoProgrammerConnected"));
} else {
try {
status.setText(Bundle.getMessage("StateReading"));
state = READCV16;
p.readCV(16, this);
} catch (jmri.ProgrammerException ex) {
state = IDLE;
status.setText("" + ex);
}
}
}
use of jmri.Programmer in project JMRI by JMRI.
the class CombinedLocoSelPane method startIdentifyLoco.
/**
* Identify loco button pressed, start the identify operation This defines
* what happens when the identify is done.
*/
protected void startIdentifyLoco() {
// start identifying a loco
final CombinedLocoSelPane me = this;
Programmer p = null;
if (selector != null && selector.isSelected()) {
p = selector.getProgrammer();
}
if (p == null) {
log.warn("Selector did not provide a programmer, use default");
p = jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).getGlobalProgrammer();
}
IdentifyLoco id = new IdentifyLoco(p) {
private CombinedLocoSelPane who = me;
@Override
protected void done(int dccAddress) {
// if Done, updated the selected decoder
who.selectLoco(dccAddress);
}
@Override
protected void message(String m) {
if (_statusLabel != null) {
_statusLabel.setText(m);
}
}
@Override
protected void error() {
// raise the button again
idloco.setSelected(false);
}
};
id.start();
}
Aggregations