Search in sources :

Example 1 with DyIOChannelMode

use of com.neuronrobotics.sdk.dyio.DyIOChannelMode in project java-bowler by NeuronRobotics.

the class DyIOConversation method onMessage.

@Override
public String onMessage(String input, Chat chat, String from) {
    String[] packet = input.split("\\ ");
    if (packet[0].toLowerCase().contains("ping")) {
        return "ping: \n" + ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).ping();
    } else if (packet[0].toLowerCase().contains("state")) {
        return "state: \n" + ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).toString();
    } else if (packet[0].toLowerCase().contains("setmode")) {
        DyIOChannelMode m = DyIOChannelMode.DIGITAL_IN;
        boolean found = false;
        String options = "";
        for (DyIOChannelMode cm : EnumSet.allOf(DyIOChannelMode.class)) {
            options += cm.toSlug() + "\n";
            if (packet[2].toLowerCase().equals(cm.toSlug())) {
                m = cm;
                found = true;
            }
        }
        try {
            int port = Integer.parseInt(packet[1]);
            if (found && ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).canBeMode(m)) {
                ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).setMode(port, m);
                return "setMode " + port + " " + m.toSlug();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "error: Mode not settible on channel #" + packet[1] + " mode options are:\n" + options;
    } else if (packet[0].toLowerCase().contains("setvalue")) {
        int port = Integer.parseInt(packet[1]);
        int value = Integer.parseInt(packet[2]);
        ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).setValue(value);
        return "setValue " + port + " " + value;
    } else if (packet[0].toLowerCase().contains("getvalue")) {
        int port = Integer.parseInt(packet[1]);
        int value = ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).getValue();
        return "getValue " + port + " " + value;
    } else if (packet[0].toLowerCase().contains("addasync")) {
        int port = Integer.parseInt(packet[1]);
        int rate = 500;
        try {
            rate = Integer.parseInt(packet[2]);
        } catch (Exception ex) {
            rate = 500;
        }
        if (rate < 500)
            rate = 500;
        ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).setAsync(true);
        ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).configAdvancedAsyncNotEqual(rate);
        ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).addChannelEventListener(getListener(chat, from));
        return "async " + port + " " + rate;
    } else if (packet[0].toLowerCase().contains("removeasync")) {
        int port = Integer.parseInt(packet[1]);
        ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).removeChannelEventListener(getListener(chat, from));
        return "async removed " + port + " ";
    } else if (packet[0].toLowerCase().contains("reset")) {
        for (int i = 0; i < 24; i++) {
            ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(i).removeAllChannelEventListeners();
        }
        return "system reset!";
    } else {
        return help();
    }
}
Also used : DyIOChannelMode(com.neuronrobotics.sdk.dyio.DyIOChannelMode) DyIO(com.neuronrobotics.sdk.dyio.DyIO) XMPPException(org.jivesoftware.smack.XMPPException)

Example 2 with DyIOChannelMode

use of com.neuronrobotics.sdk.dyio.DyIOChannelMode in project java-bowler by NeuronRobotics.

the class DyIOAPITest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    DyIO dyio = new DyIO();
    if (!ConnectionDialog.getBowlerDevice(dyio)) {
        System.exit(1);
    }
    int num = dyio.getDyIOChannelCount();
    System.out.println("Number of channels = " + num);
    for (int i = 0; i < num; i++) {
        System.out.println("Channel # " + i);
        ArrayList<DyIOChannelMode> modes = dyio.getAvailibleChannelModes(i);
        for (DyIOChannelMode m : modes) {
            System.out.println("\tHas " + m);
        }
    }
    System.exit(0);
}
Also used : DyIOChannelMode(com.neuronrobotics.sdk.dyio.DyIOChannelMode) DyIO(com.neuronrobotics.sdk.dyio.DyIO)

Example 3 with DyIOChannelMode

use of com.neuronrobotics.sdk.dyio.DyIOChannelMode in project java-bowler by NeuronRobotics.

the class CounterInputChannel method init.

private void init(DyIOChannel channel, boolean isAsync) {
    DyIOChannelMode mode = DyIOChannelMode.COUNT_IN_INT;
    channel.addChannelEventListener(this);
    if (!channel.setMode(mode, isAsync)) {
        throw new DyIOPeripheralException("Could not set channel " + channel + " to " + mode + " mode.");
    }
    channel.resync(true);
}
Also used : DyIOChannelMode(com.neuronrobotics.sdk.dyio.DyIOChannelMode)

Example 4 with DyIOChannelMode

use of com.neuronrobotics.sdk.dyio.DyIOChannelMode in project java-bowler by NeuronRobotics.

the class CounterOutputChannel method init.

private void init(DyIOChannel channel, boolean isAsync) {
    DyIOChannelMode mode = DyIOChannelMode.COUNT_OUT_INT;
    channel.addChannelEventListener(this);
    if (!channel.setMode(mode, isAsync)) {
        throw new DyIOPeripheralException("Could not set channel " + channel + " to " + mode + " mode.");
    }
    channel.resync(true);
}
Also used : DyIOChannelMode(com.neuronrobotics.sdk.dyio.DyIOChannelMode)

Example 5 with DyIOChannelMode

use of com.neuronrobotics.sdk.dyio.DyIOChannelMode in project java-bowler by NeuronRobotics.

the class DyIOAbstractPeripheral method SavePosition.

/**
 * This method sets the value of the output of the giver peripheral, and also stores this value as the "default"
 * value in non volatile memory to use at startup of the peripheral.
 *
 * @param pos the position to set as the new starting point for the channel
 * @return if the save worked or not.
 */
public boolean SavePosition(int pos) {
    try {
        DyIOChannelMode mode = getChannel().getMode();
        switch(mode) {
            case SERVO_OUT:
            case PWM_OUT:
                configuration = pos;
                if (getChannel().getDevice().isLegacyParser()) {
                    getChannel().send(new SetChannelValueCommand(getChannel().getChannelNumber(), pos, getMode(), true));
                } else {
                    getChannel().getDevice().send("bcs.io.*;0.3;;", BowlerMethod.CRITICAL, "cchn", new Object[] { getChannel().getChannelNumber(), true, new Integer[] { pos } });
                    getChannel().setValue(pos);
                    try {
                        Thread.sleep(30);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
                return true;
            default:
                return false;
        }
    } catch (InvalidResponseException e) {
        return false;
    }
}
Also used : SetChannelValueCommand(com.neuronrobotics.sdk.commands.bcs.io.SetChannelValueCommand) DyIOChannelMode(com.neuronrobotics.sdk.dyio.DyIOChannelMode) InvalidResponseException(com.neuronrobotics.sdk.common.InvalidResponseException)

Aggregations

DyIOChannelMode (com.neuronrobotics.sdk.dyio.DyIOChannelMode)5 DyIO (com.neuronrobotics.sdk.dyio.DyIO)2 SetChannelValueCommand (com.neuronrobotics.sdk.commands.bcs.io.SetChannelValueCommand)1 InvalidResponseException (com.neuronrobotics.sdk.common.InvalidResponseException)1 XMPPException (org.jivesoftware.smack.XMPPException)1