Search in sources :

Example 1 with SetChannelValueCommand

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

the class PPMReaderChannel method setCrossLink.

/**
 * This sets up the PPM cross link. For each PPM channel you can assign it one DyIO output channel as its direct
 * control. Indecies in the array corospond to the PPM channel, and values corospond to the DyIO output channel
 * @param links an array of channel numbers corosponding to the PPM channel to do a direct 1:1 mapping
 */
public void setCrossLink(int[] links) {
    if (links.length != 6)
        throw new IndexOutOfBoundsException("Array of cross links must be of legnth 6");
    if (crossLinks == null) {
        throw new RuntimeException("Must get cross link state before setting a new one");
    }
    // System.out.print("\nSetting cross link map: [");
    for (int i = 0; i < crossLinks.length; i++) {
        crossLinks[i] = links[i];
    // System.out.print(" "+crossLinks[i]);
    }
    // System.out.print("]");
    if (getChannel().getDevice().isLegacyParser()) {
        getChannel().getDevice().send(new SetChannelValueCommand(23, crossLinks, myMode));
    } else {
        ByteList data = new ByteList(crossLinks);
        getChannel().getDevice().send("bcs.io.*;0.3;;", BowlerMethod.POST, "strm", new Object[] { 23, data });
    }
}
Also used : SetChannelValueCommand(com.neuronrobotics.sdk.commands.bcs.io.SetChannelValueCommand) ByteList(com.neuronrobotics.sdk.common.ByteList)

Example 2 with SetChannelValueCommand

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

the class SPIChannel method sendSPIStream.

/**
 * THis method sends a byte array our the SPI peripheral. It uses another DyIO channel as its slave select pin.
 * @param ss the index of the DyIO channel to use as a slave select pin for the SPI
 * @param stream the Bytes to be sent out
 * @return true if success
 */
@Deprecated
private BowlerDatagram sendSPIStream(int ss, byte[] stream) {
    ByteList b = new ByteList();
    b.add(ss);
    b.add(stream);
    return dyio.send(new SetChannelValueCommand(0, b));
}
Also used : SetChannelValueCommand(com.neuronrobotics.sdk.commands.bcs.io.SetChannelValueCommand) ByteList(com.neuronrobotics.sdk.common.ByteList)

Example 3 with SetChannelValueCommand

use of com.neuronrobotics.sdk.commands.bcs.io.SetChannelValueCommand 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

SetChannelValueCommand (com.neuronrobotics.sdk.commands.bcs.io.SetChannelValueCommand)3 ByteList (com.neuronrobotics.sdk.common.ByteList)2 InvalidResponseException (com.neuronrobotics.sdk.common.InvalidResponseException)1 DyIOChannelMode (com.neuronrobotics.sdk.dyio.DyIOChannelMode)1