Search in sources :

Example 1 with GetValueCommand

use of com.neuronrobotics.sdk.commands.bcs.io.GetValueCommand in project java-bowler by NeuronRobotics.

the class DyIOChannel method getValue.

/* (non-Javadoc)
	 * @see com.neuronrobotics.sdk.dyio.IDyIOChannel#getValue()
	 */
public int getValue() {
    int val = 0;
    if (getDevice().isLegacyParser()) {
        BowlerDatagram response = null;
        try {
            response = getDevice().send(new GetValueCommand(number));
        } catch (InvalidResponseException e) {
            response = getDevice().send(new GetValueCommand(number));
        }
        ByteList bl = response.getData();
        Byte b = bl.pop();
        if (b == null || b.intValue() != number) {
            Log.error("Failed to get value " + response);
            return 0;
        }
        val = new DyIOChannelEvent(this, bl).getValue();
        setCachedValue(val);
        setPreviousValue(val);
    } else {
        // Object [] args =getDevice().send("bcs.io.*;0.3;;",
        // BowlerMethod.GET,
        // "gchv",
        // new Object[]{number});
        // val=(Integer)args[1];
        // Log.debug("Got Value: "+val);
        // For the new API the channel values should come in through the asynchronous path.
        val = getPreviousValue();
    }
    return val;
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) GetValueCommand(com.neuronrobotics.sdk.commands.bcs.io.GetValueCommand) InvalidResponseException(com.neuronrobotics.sdk.common.InvalidResponseException)

Example 2 with GetValueCommand

use of com.neuronrobotics.sdk.commands.bcs.io.GetValueCommand in project java-bowler by NeuronRobotics.

the class PPMReaderChannel method updateValues.

private void updateValues() {
    if (getChannel().getDevice().isLegacyParser()) {
        BowlerDatagram b = null;
        // System.out.println("Updating value map");
        try {
            b = getChannel().getDevice().send(new GetValueCommand(23));
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (b != null) {
            crossLinks = new int[6];
            values = new int[6];
            for (int i = 0; i < values.length; i++) {
                values[i] = b.getData().getUnsigned(1 + i);
            }
            for (int i = 0; i < crossLinks.length; i++) {
                crossLinks[i] = b.getData().getUnsigned(1 + 6 + i);
            }
        }
    } else {
        Object[] args = getChannel().getDevice().send("bcs.io.*;0.3;;", BowlerMethod.GET, "strm", new Object[] { 23 });
        crossLinks = new int[6];
        values = new int[6];
        ByteList data = (ByteList) args[1];
        Log.debug("PPM link data: " + data.size());
        for (int i = 0; i < values.length; i++) {
            values[i] = data.getUnsigned(i);
        }
        for (int i = 0; i < crossLinks.length; i++) {
            crossLinks[i] = data.getUnsigned(6 + i);
        }
    }
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) GetValueCommand(com.neuronrobotics.sdk.commands.bcs.io.GetValueCommand)

Aggregations

GetValueCommand (com.neuronrobotics.sdk.commands.bcs.io.GetValueCommand)2 BowlerDatagram (com.neuronrobotics.sdk.common.BowlerDatagram)2 ByteList (com.neuronrobotics.sdk.common.ByteList)2 InvalidResponseException (com.neuronrobotics.sdk.common.InvalidResponseException)1