Search in sources :

Example 41 with ProgListener

use of jmri.ProgListener in project JMRI by JMRI.

the class BoosterProgPanel method durationPart2.

void durationPart2() {
    status.setText(rb.getString("StatusProgramming"));
    int val = Integer.parseInt(length.getText()) % 256;
    try {
        p.writeCV(254, val, new ProgListener() {

            @Override
            public void programmingOpReply(int value, int retval) {
                status.setText(rb.getString("StatusOK"));
            }
        });
    } catch (ProgrammerException e) {
        status.setText(rb.getString("StatusError") + e);
    } finally {
        releaseProgrammer();
    }
}
Also used : ProgrammerException(jmri.ProgrammerException) ProgListener(jmri.ProgListener)

Example 42 with ProgListener

use of jmri.ProgListener in project JMRI by JMRI.

the class BoosterProgPanel method setDurationPushed.

void setDurationPushed() {
    getProgrammer();
    status.setText(rb.getString("StatusProgramming"));
    int val = Integer.parseInt(length.getText()) / 256;
    try {
        p.writeCV(253, val, new ProgListener() {

            @Override
            public void programmingOpReply(int value, int retval) {
                synchronized (this) {
                    try {
                        // needed for booster to reset
                        wait(1500);
                    } catch (InterruptedException i) {
                    }
                }
                durationPart2();
            }
        });
    } catch (ProgrammerException e) {
        status.setText(rb.getString("StatusError") + e);
        releaseProgrammer();
    }
}
Also used : ProgrammerException(jmri.ProgrammerException) ProgListener(jmri.ProgListener)

Example 43 with ProgListener

use of jmri.ProgListener in project JMRI by JMRI.

the class ProgDebugger method readCV.

@Override
public void readCV(int CV, ProgListener p) throws ProgrammerException {
    final ProgListener m = p;
    _lastReadCv = CV;
    nOperations++;
    int readValue = _nextRead;
    // try to get something from hash table
    Integer saw = mValues.get(CV);
    if (saw != null) {
        readValue = saw;
    }
    log.info("read CV: " + CV + " mode: " + getMode() + " will read " + readValue);
    final int returnValue = readValue;
    // return a notification via the queue to ensure end
    Runnable r = new Runnable() {

        int retval = returnValue;

        ProgListener l = m;

        @Override
        public void run() {
            // log.debug("read CV reply - start sleep");
            // try { Thread.sleep(100); } catch (Exception e) {}
            log.debug("read CV reply");
            l.programmingOpReply(retval, 0);
        }
    };
    sendReturn(r);
}
Also used : ProgListener(jmri.ProgListener)

Example 44 with ProgListener

use of jmri.ProgListener in project JMRI by JMRI.

the class ProgDebugger method confirmCV.

@Override
public void confirmCV(String CVname, int val, ProgListener p) throws ProgrammerException {
    int CV = Integer.parseInt(CVname);
    final ProgListener m = p;
    nOperations++;
    // guess by comparing current value in val to has table
    Integer saw = mValues.get(CV);
    // what was read
    int result;
    if (saw != null) {
        result = saw;
        confirmOK = (result == val);
        log.info("confirm CV: " + CV + " mode: " + getMode() + " will return " + result + " pass: " + confirmOK);
    } else {
        result = -1;
        confirmOK = false;
        log.info("confirm CV: " + CV + " mode: " + getMode() + " will return -1 pass: false due to no previous value");
    }
    _lastReadCv = CV;
    // return a notification via the queue to ensure end
    // final to allow passing to inner class
    final int returnResult = result;
    Runnable r = new Runnable() {

        ProgListener l = m;

        int result = returnResult;

        @Override
        public void run() {
            log.debug("read CV reply");
            if (confirmOK) {
                l.programmingOpReply(result, ProgListener.OK);
            } else {
                l.programmingOpReply(result, ProgListener.ConfirmFailed);
            }
        }
    };
    sendReturn(r);
}
Also used : ProgListener(jmri.ProgListener)

Example 45 with ProgListener

use of jmri.ProgListener in project JMRI by JMRI.

the class DebugProgrammerTest method testKnowsWriteString.

public void testKnowsWriteString() throws jmri.ProgrammerException {
    ProgDebugger 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;
        }
    };
    Assert.assertTrue("initially not written", !p.hasBeenWritten(4));
    p.writeCV("4", 12, l);
    Assert.assertTrue("after 1st write", p.hasBeenWritten(4));
    p.clearHasBeenWritten(4);
    Assert.assertTrue("now longer written", !p.hasBeenWritten(4));
    p.writeCV("4", 12, l);
    Assert.assertTrue("after 2nd write", p.hasBeenWritten(4));
}
Also used : ProgListener(jmri.ProgListener)

Aggregations

ProgListener (jmri.ProgListener)53 Programmer (jmri.Programmer)27 ProgDebugger (jmri.progdebugger.ProgDebugger)27 ProgrammerException (jmri.ProgrammerException)3