use of jmri.ProgrammerException in project JMRI by JMRI.
the class DccConsist method addToAdvancedConsist.
/*
* Add a Locomotive to an Advanced Consist
* @param address is the Locomotive address to add to the locomotive
* @param directionNormal is True if the locomotive is traveling
* the same direction as the consist, or false otherwise.
*/
protected void addToAdvancedConsist(DccLocoAddress LocoAddress, boolean directionNormal) {
AddressedProgrammer opsProg = InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(LocoAddress.isLongAddress(), LocoAddress.getNumber());
if (opsProg == null) {
log.error("Can't make consisting change because no programmer exists; this is probably a configuration error in the preferences");
return;
}
if (directionNormal) {
try {
opsProg.writeCV(19, ConsistAddress.getNumber(), this);
} catch (ProgrammerException e) {
// Don't do anything with this yet
log.warn("Exception writing CV19 while adding from consist", e);
}
} else {
try {
opsProg.writeCV(19, ConsistAddress.getNumber() + 128, this);
} catch (ProgrammerException e) {
// Don't do anything with this yet
log.warn("Exception writing CV19 while adding to consist", e);
}
}
InstanceManager.getDefault(jmri.ProgrammerManager.class).releaseAddressedProgrammer(opsProg);
}
use of jmri.ProgrammerException in project JMRI by JMRI.
the class DccConsist method removeFromAdvancedConsist.
/*
* Remove a Locomotive from an Advanced Consist
* @param address is the Locomotive address to remove from the consist
*/
protected void removeFromAdvancedConsist(DccLocoAddress LocoAddress) {
AddressedProgrammer opsProg = InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(LocoAddress.isLongAddress(), LocoAddress.getNumber());
if (opsProg == null) {
log.error("Can't make consisting change because no programmer exists; this is probably a configuration error in the preferences");
return;
}
try {
opsProg.writeCV(19, 0, this);
} catch (ProgrammerException e) {
// Don't do anything with this yet
log.warn("Exception writing CV19 while removing from consist", e);
}
InstanceManager.getDefault(jmri.ProgrammerManager.class).releaseAddressedProgrammer(opsProg);
}
use of jmri.ProgrammerException 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.ProgrammerException 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.ProgrammerException 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;
}
Aggregations