Search in sources :

Example 1 with GetChannelModeCommand

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

the class DyIOChannel method resync.

/**
 * Live query the device for its mode and cache it.
 *
 * @param all - should all channels be refreshed.
 */
public void resync(boolean all) {
    if (all) {
        getDevice().resync();
        return;
    }
    BowlerDatagram bd = getDevice().send(new GetChannelModeCommand(number));
    // System.out.println(bd);
    fireModeChangeEvent(DyIOChannelMode.get(bd.getData().getByte(1)));
    throw new RuntimeException();
}
Also used : GetChannelModeCommand(com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeCommand) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram)

Example 2 with GetChannelModeCommand

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

the class DyIO method getAllChannelModes.

public ArrayList<DyIOChannelMode> getAllChannelModes() {
    ArrayList<DyIOChannelMode> modes = new ArrayList<DyIOChannelMode>();
    BowlerDatagram response;
    ByteList bl;
    if (isLegacyParser()) {
        try {
            response = send(new GetChannelModeCommand());
        } catch (Exception e) {
            if (getInternalChannels().size() == 0) {
                Log.error("Initilization failed once, retrying");
                try {
                    response = send(new GetChannelModeCommand());
                } catch (Exception e2) {
                    e2.printStackTrace();
                    setMuteResyncOnModeChange(false);
                    throw new DyIOCommunicationException("DyIO failed to report during initialization. Could not determine DyIO configuration: " + e2.getMessage());
                }
            } else {
                setMuteResyncOnModeChange(false);
                return null;
            }
        }
        if (response == null)
            checkFirmwareRev();
        // if(getAddress().equals(new MACAddress(MACAddress.BROADCAST))) {
        setAddress(response.getAddress());
        // }
        @SuppressWarnings("unused") int count = 0;
        if (getDyIOChannelCount() != null) {
            count = getDyIOChannelCount();
        }
        bl = response.getData();
        Log.error("Using old parsing model");
    } else {
        Object[] args = send("bcs.io.*;0.3;;", BowlerMethod.GET, "gacm", new Object[] {});
        bl = (ByteList) args[0];
    }
    for (int i = 0; i < bl.size(); i++) {
        DyIOChannelMode cm = DyIOChannelMode.get(bl.getByte(i));
        modes.add(cm);
    }
    return modes;
}
Also used : GetChannelModeCommand(com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeCommand) ByteList(com.neuronrobotics.sdk.common.ByteList) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) ArrayList(java.util.ArrayList) PIDCommandException(com.neuronrobotics.sdk.pid.PIDCommandException) InvalidConnectionException(com.neuronrobotics.sdk.common.InvalidConnectionException) InvalidResponseException(com.neuronrobotics.sdk.common.InvalidResponseException)

Aggregations

GetChannelModeCommand (com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeCommand)2 BowlerDatagram (com.neuronrobotics.sdk.common.BowlerDatagram)2 ByteList (com.neuronrobotics.sdk.common.ByteList)1 InvalidConnectionException (com.neuronrobotics.sdk.common.InvalidConnectionException)1 InvalidResponseException (com.neuronrobotics.sdk.common.InvalidResponseException)1 PIDCommandException (com.neuronrobotics.sdk.pid.PIDCommandException)1 ArrayList (java.util.ArrayList)1