コード例 #1
0
        /// <summary>
        /// This function enables synchonizing two motors.
        /// Synchonization should be used when motors should run as synchrone as possible,
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="layer">Specify chain layer number [0 - 3]</param>
        /// <param name="ports">Output bit field [0x00 – 0x0F]</param>
        /// <param name="speed">Speed level, [-100 – 100]</param>
        /// <param name="turnRatio">Turn ratio, [-200 - 200]
        /// 0 : Motor will run with same power
        /// 100 : One motor will run with specified power while the other will be close to zero
        /// 200: One motor will run with specified power forward while the other will run in the opposite direction at the same power level.
        /// </param>
        /// <param name="time">Time in milliseconds, 0 = Infinite</param>
        /// <param name="brake">Specify break level, [0: Float, 1: Break]</param>
        /// <remarks>
        /// Instruction opOutput_Time_Sync (LAYER, NOS, SPEED, TURN, STEP, BRAKE)
        /// Opcode 0xB1
        /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3]
        /// (Data8) NOS – Output bit field [0x00 – 0x0F]
        /// (Data8) SPEED – Power level, [-100 – 100]
        /// (Data16) TURN – Turn ratio, [-200 - 200], see documentation below
        /// (Data32) TIME – Time in milliseconds, 0 = Infinite
        /// (Data8) BRAKE - Specify break level [0: Float, 1: Break]
        /// Dispatch status Unchanged
        /// Description This function enables synchonizing two motors. Synchonization should be used when motors should run as synchrone as possible,
        /// </remarks>
        public static async Task TimeSync(ISocket socket, ChainLayer layer, OutputPortFlag ports, int speed, int turnRatio, int time, Brake brake = Brake.Float, bool requireReply = true)
        {
            if (time < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(time), ">=0");
            }
            if (speed < -100 || speed > 100)
            {
                throw new ArgumentOutOfRangeException(nameof(speed), "[-100,100]");
            }
            if (turnRatio < -200 || turnRatio > 200)
            {
                throw new ArgumentOutOfRangeException(nameof(turnRatio), "[-200,200]");
            }

            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opOUTPUT_TIME_SYNC);
                cb.SHORT((int)layer);
                cb.SHORT((int)ports);
                cb.PAR8(speed);
                cb.PAR16(turnRatio);
                cb.PAR32(time);
                cb.PAR8((byte)brake);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
コード例 #2
0
        /// <summary>
        /// This function enables specifying a full motor power cycle in time.
        /// RampUp specifies the power ramp up periode in milliseconds,
        /// ContinuesRun specifies the constant power period in milliseconds,
        /// RampDown specifies the power down period in milliseconds.
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="layer">Specify chain layer number [0 - 3]</param>
        /// <param name="ports">Output bit field [0x00 – 0x0F]</param>
        /// <param name="power">Specify output power [-100 – 100]</param>
        /// <param name="timeRampUp">Time in milliseconds for ramp up</param>
        /// <param name="timeContinuesRun">Time in milliseconds for continues run</param>
        /// <param name="timeRampDown">Time in milliseconds for ramp down</param>
        /// <param name="brake">Specify break level, [0: Float, 1: Break]</param>
        /// <remarks>
        /// Instruction opOutput_Time_Power (LAYER, NOS, POWER, STEP1, STEP2, STEP3, BRAKE)
        /// Opcode 0xAD
        /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3]
        /// (Data8) NOS – Output bit field [0x00 – 0x0F]
        /// (Data8) POWER – Power level, [-100 – 100]
        /// (Data32) STEP1 – Time in milliseconds for ramp up
        /// (Data32) STEP2 – Time in milliseconds for continues run
        /// (Data32) STEP3 – Time in milliseconds for ramp down
        /// (Data8) BRAKE - Specify break level [0: Float, 1: Break]
        /// Dispatch status Unchanged
        /// Description This function enables specifying a full motor power cycle in time. Step1 specifies the power ramp up periode in milliseconds, Step2 specifies the constant power period in milliseconds, Step 3 specifies the power down period in milliseconds.
        /// </remarks>
        public static async Task TimePower(ISocket socket, ChainLayer layer, OutputPortFlag ports, int power, int timeRampUp, int timeContinuesRun, int timeRampDown, Brake brake = Brake.Float, bool requireReply = true)
        {
            if (power < -100 || power > 100)
            {
                throw new ArgumentOutOfRangeException(nameof(power), "[-100,100]");
            }
            if (timeContinuesRun < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(timeContinuesRun), ">=0");
            }
            if (timeRampUp < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(timeRampUp), ">=0");
            }
            if (timeRampDown < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(timeRampDown), ">=0");
            }

            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opOUTPUT_TIME_POWER);
                cb.SHORT((int)layer);
                cb.SHORT((int)ports);
                cb.PAR8(power);
                cb.PAR32(timeRampUp);
                cb.PAR32(timeContinuesRun);
                cb.PAR32(timeRampDown);
                cb.PAR8((byte)brake);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
コード例 #3
0
        /// <summary>
        /// This function enables specifying a full motor power cycle in tacho counts.
        /// The system will automatically adjust the power level to the motor to keep the specified output speed.
        /// RampDown specifies the power ramp up periode in tacho count,
        /// ContinuesRun specifies the constant power period in tacho counts,
        /// RampUp specifies the power down period in tacho counts.
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="layer">Specify chain layer number [0 - 3]</param>
        /// <param name="ports">Output bit field [0x00 – 0x0F]</param>
        /// <param name="speed">Specify output speed [-100 – 100]</param>
        /// <param name="tachoPulsesRampUp">Tacho pulses during ramp up</param>
        /// <param name="tachoPulsesContinuesRun">Tacho pulses during continues run</param>
        /// <param name="tachoPulsesRampDown">Tacho pulses during ramp down</param>
        /// <param name="brake">Specify break level, [0: Float, 1: Break]</param>
        /// <remarks>
        /// Instruction opOutput_Step_Speed (LAYER, NOS, SPEED, STEP1, STEP2, STEP3, BRAKE)
        /// Opcode 0xAE
        /// Arguments (Data8) LAYER – Specify chain layer number, [0 - 3]
        /// (Data8) NOS – Output bit field, [0x00 – 0x0F]
        /// (Data8) SPEED – Power level, [-100 - 100]
        /// (Data32) STEP1 – Tacho pulses during ramp up
        /// (Data32) STEP2 – Tacho pulses during continues run
        /// (Data32) STEP3 – Tacho pulses during ramp down
        /// (Data8) BRAKE - Specify break level, [0: Float, 1: Break]
        /// Dispatch status Unchanged
        /// Description This function enables specifying a full motor power cycle in tacho counts. The system will automatically adjust the power level to the motor to keep the specified output speed. Step1 specifies the power ramp up periode in tacho count, Step2 specifies the constant power period in tacho counts, Step 3 specifies the power down period in tacho counts.
        /// </remarks>
        public static async Task StepSpeed(ISocket socket, ChainLayer layer, OutputPortFlag ports, int speed, int tachoPulsesRampUp, int tachoPulsesContinuesRun, int tachoPulsesRampDown, Brake brake = Brake.Float, bool requireReply = true)
        {
            if (speed < -100 || speed > 100)
            {
                throw new ArgumentOutOfRangeException(nameof(speed), "[-100,100]");
            }
            if (tachoPulsesContinuesRun < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(tachoPulsesContinuesRun), ">=0");
            }
            if (tachoPulsesRampUp < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(tachoPulsesRampUp), ">=0");
            }
            if (tachoPulsesRampDown < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(tachoPulsesRampDown), ">=0");
            }

            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opOUTPUT_STEP_SPEED);
                cb.PAR8((int)layer);
                cb.PAR8((int)ports);
                cb.PAR8(speed);
                cb.PAR32((uint)tachoPulsesRampUp);
                cb.PAR32((uint)tachoPulsesContinuesRun);
                cb.PAR32((uint)tachoPulsesRampDown);
                cb.PAR8((byte)brake);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
コード例 #4
0
 /// <summary>
 /// This function enables starting the device on all ports on all bricks
 /// </summary>
 /// <param name="portFlag">A flag indicating the ports to target. Eg PortNames.A|PortNames.C</param>
 public async Task Start(OutputPortFlag portFlag = OutputPortFlag.All)
 {
     for (int i = 0; i < 4; i++)
     {
         await OutputMethods.Start(Brick.Socket, (ChainLayer)i, portFlag);
     }
 }
コード例 #5
0
 /// <summary>
 /// This function enables setting the output percentage speed on the device on all ports on all bricks
 /// This automatically enables speed control, which means the system will automatically adjust the power to keep the specified speed.
 /// </summary>
 /// <param name="portFlag">A flag indicating the ports to target. Eg PortNames.A|PortNames.C</param>
 /// <param name="speed">Specify output speed [-100 – 100 %]</param>
 public async Task SetSpeed(int speed, OutputPortFlag portFlag = OutputPortFlag.All)
 {
     for (int i = 0; i < 4; i++)
     {
         await OutputMethods.SetSpeed(Brick.Socket, (ChainLayer)i, portFlag, speed);
     }
 }
コード例 #6
0
 /// <summary>
 /// This function enables setting the output percentage power on all ports on all bricks
 /// </summary>
 /// <param name="portFlag">A flag indicating the ports to target. Eg PortNames.A|PortNames.C</param>
 /// <param name="power">Specify output power [-100 – 100 %]</param>
 public async Task SetPower(int power, OutputPortFlag portFlag = OutputPortFlag.All)
 {
     for (int i = 0; i < 4; i++)
     {
         await OutputMethods.SetPower(Brick.Socket, (ChainLayer)i, portFlag, power);
     }
 }
コード例 #7
0
 /// <summary>
 /// This function sends stop to device on all ports on all bricks
 /// </summary>
 /// <param name="portFlag">A flag indicating the ports to target. Eg PortNames.A|PortNames.C</param>
 /// <param name="brake">Specify break level, [0: Float, 1: Break]</param>
 public async Task Stop(OutputPortFlag portFlag = OutputPortFlag.All, Brake brake = Brake.Float)
 {
     for (int i = 0; i < 4; i++)
     {
         await OutputMethods.Stop(Brick.Socket, (ChainLayer)i, portFlag, brake);
     }
 }
コード例 #8
0
 /// <summary>
 /// This function enables the program to clear the tacho count used as sensor input on all ports on all bricks
 /// </summary>
 /// <param name="portFlag">A flag indicating the ports to target. Eg PortNames.A|PortNames.C</param>
 public async Task ClearCount(OutputPortFlag portFlag = OutputPortFlag.All)
 {
     for (int i = 0; i < 4; i++)
     {
         await OutputMethods.ResetTachoCount(Brick.Socket, (ChainLayer)i, portFlag);
     }
 }
コード例 #9
0
        /// <summary>
        /// This function enables the program to clear the tacho count used as sensor input.
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="layer">Specify chain layer number [0 - 3]</param>
        /// <param name="ports">Output bit field [0x00 – 0x0F]</param>
        /// <remarks>
        /// Instruction opOutput_Clr_Count (LAYER, NOS)
        /// Opcode 0xB2
        /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3]
        /// (Data8) NOS – Output bit field [0x00 – 0x0F]
        /// Dispatch status Unchanged
        /// Description This function enables the program to clear the tacho count used as sensor input.
        /// </remarks>
        public static async Task ResetTachoCount(ISocket socket, ChainLayer layer, OutputPortFlag ports, bool requireReply = true)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opOUTPUT_CLR_COUNT);
                cb.SHORT((int)layer);
                cb.SHORT((int)ports);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
コード例 #10
0
        /// <summary>
        /// This function enables the program to test if a output device is busy on all ports on all bricks
        /// </summary>
        public async Task <bool> IsBusy(OutputPortFlag portFlag = OutputPortFlag.All)
        {
            for (int i = 0; i < 4; i++)
            {
                bool result = await OutputMethods.IsBusy(Brick.Socket, (ChainLayer)i, portFlag);

                if (result)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #11
0
        /// <summary>
        /// This function sends stop to all individual output ports
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="layer">Specify chain layer number [0 - 3]</param>
        /// <param name="ports">Output bit field [0x00 – 0x0F]</param>
        /// <param name="brake">Specify break level [0: Float, 1: Break]</param>
        /// <remarks>
        /// Instruction opOutput_Stop (LAYER, NOS, BRAKE)
        /// Opcode 0xA3
        /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3]
        /// (Data8) NOS – Output bit field [0x00 – 0x0F]
        /// (Data8) BRAKE – Specify break level [0: Float, 1: Break]
        /// Dispatch status Unchanged
        /// Description This function enables restting the tacho count for the individual output ports
        /// </remarks>
        public static async Task Stop(ISocket socket, ChainLayer layer, OutputPortFlag ports, Brake brake = Brake.Float, bool requireReply = true)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opOUTPUT_STOP);
                cb.SHORT((int)layer);
                cb.SHORT((int)ports);
                cb.PAR8((byte)brake);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
コード例 #12
0
        /// <summary>
        /// This function sets the polarity of the specified output port(s).
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="layer">Specify chain layer number [0 - 3]</param>
        /// <param name="ports">Output bit field [0x00 – 0x0F]</param>
        /// <param name="polarity">Polarity -1 : backward 0 : opposite direction 1 : forward</param>
        /// <remarks>
        /// Instruction opOutput_Polarity (LAYER, NOS, POL)
        /// Opcode 0xA7
        /// Arguments (Data8) LAYER – Specify chain layer number, [0 - 3]
        /// (Data8) NOS – Output bit field, [0x00 – 0x0F]
        /// (Data8) POL – Polarity [-1, 0, 1], see documentation below
        /// Dispatch status Unchanged
        /// Description This function enables starting the specified output port.
        /// </remarks>
        public static async Task SetPolarity(ISocket socket, ChainLayer layer, OutputPortFlag ports, Polarity polarity, bool requireReply = true)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opOUTPUT_POLARITY);
                cb.PAR8((int)layer);
                cb.PAR8((int)ports);
                cb.PAR8((byte)polarity);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
コード例 #13
0
        ///// <summary>
        ///// This function enables reading current motor speed and tacho count level.
        ///// </summary>
        ///// <param name="socket">socket for executing command to brick</param>
        ///// <param name="layer">Specify chain layer number [0 - 3]</param>
        ///// <param name="port">Port number [0 - 3]</param>
        ///// <remarks>
        ///// Instruction opOutput_Read (LAYER, NO, *SPEED, *TACHO)
        ///// Opcode 0xA8
        ///// Arguments (Data8) LAYER – Specify chain layer number [0 - 3]
        ///// (Data8) NO – Port number [0 - 3]
        ///// (Data8) *SPEED – Output speed level detected, [-100 - 100]
        ///// (Data32) *TACHO – Current output tacho count
        ///// Dispatch status Unchanged
        ///// Description This function enables reading current motor speed and tacho count level.
        ///// </remarks>
        //public static async Task Read(ISocket socket, ChainLayer layer, OutputPortName port)
        //{
        //    Command cmd = null;
        //    using (CommandBuilder cb = new CommandBuilder(DIRECT_COMMAND_TYPE.DIRECT_COMMAND_NO_REPLY,0,2))
        //    {
        //        cb.OpCode(OpCode.opOutput_Read);
        //        cb.Argument((byte)layer);
        //        cb.Argument((byte)port);
        //        cb.LocalIndex(0);
        //        cb.LocalIndex32(1);
        //        cmd = cb.ToCommand();
        //    }
        //    await socket.Execute(cmd);

        //    CommandReply reply = cmd.Reply;
        //}

        /// <summary>
        /// This function enables the program to test if a output port is busy.
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="layer">Specify chain layer number [0 - 3]</param>
        /// <param name="ports">Output bit field [0x00 – 0x0F]</param>
        /// <remarks>
        /// Instruction opOutput_Test (LAYER, NOS, BUSY)
        /// Opcode 0xA9
        /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3]
        /// (Data8) NOS – Output bit field [0x00 – 0x0F]
        /// Return (Data8) BUSY – Output busy flag, [0 = Ready, 1 = Busy]
        /// Dispatch status Unchanged
        /// Description This function enables the program to test if a output port is busy.
        /// </remarks>
        public static async Task <bool> IsBusy(ISocket socket, ChainLayer layer, OutputPortFlag ports)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_REPLY, 1, 0))
            {
                cb.OpCode(OP.opOUTPUT_TEST);
                cb.PAR8((int)layer);
                cb.PAR8((int)ports);
                cb.GlobalIndex(0);
                cmd = cb.ToCommand();
            }
            Response response = await socket.Execute(cmd);

            return(BitConverter.ToBoolean(response.PayLoad, 0));
        }
コード例 #14
0
        /// <summary>
        /// This function enables setting the output percentage speed on the output ports.
        /// This automatically enables speed control, which means the system will automatically adjust the power to keep the specified speed.
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="layer">Specify chain layer number [0 - 3]</param>
        /// <param name="ports">Output bit field [0x00 – 0x0F]</param>
        /// <param name="speed">Specify output speed [-100 – 100 %]</param>
        /// <remarks>
        /// Instruction opOutput_Speed (LAYER, NOS, SPEED)
        /// Opcode 0xA5
        /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3]
        /// (Data8) NOS – Output bit field [0x00 – 0x0F]
        /// (Data8) SPEED – Specify output speed [-100 – 100 %]
        /// Dispatch status Unchanged
        /// Description This function enables setting the output percentage speed on the output ports. This modes automatically enables speed control, which means the system will automa-tically adjust the power to keep the specified speed.
        /// </remarks>
        public static async Task SetSpeed(ISocket socket, ChainLayer layer, OutputPortFlag ports, int speed, bool requireReply = true)
        {
            if (speed < -100 || speed > 100)
            {
                throw new ArgumentException(nameof(speed), "[-100 and 100]");
            }

            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opOUTPUT_SPEED);
                cb.SHORT((int)layer);
                cb.SHORT((int)ports);
                cb.PAR8(speed);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }