Search in sources :

Example 41 with Programmer

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);
}
Also used : Programmer(jmri.Programmer)

Example 42 with Programmer

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);
}
Also used : Programmer(jmri.Programmer) ProgListener(jmri.ProgListener)

Example 43 with Programmer

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;
}
Also used : ProgrammerException(jmri.ProgrammerException) Programmer(jmri.Programmer)

Example 44 with Programmer

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);
        }
    }
}
Also used : Programmer(jmri.Programmer)

Example 45 with Programmer

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();
}
Also used : Programmer(jmri.Programmer) IdentifyLoco(jmri.jmrit.roster.IdentifyLoco)

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