Esempio n. 1
0
        /// <summary>
        /// This function enables specifying a full power cycle in time.
        /// The system will automatically adjust the power level to keep the specified output speed.
        /// RampUp specifies the power ramp up periode in milliseconds,
        /// ContinuesRun specifies the constant speed 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="speed">Specify output speed [-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_Speed (LAYER, NOS, SPEED, STEP1, STEP2, STEP3, BRAKE)
        /// Opcode 0xAF
        /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3]
        /// (Data8) NOS – Output bit field [0x00 – 0x0F]
        /// (Data8) SPEED – 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. 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 milliseconds, Step2 specifies the constant power period in milliseconds, Step 3 specifies the power down period in milliseconds.
        /// </remarks>
        public static async Task TimeSpeed(ISocket socket, ChainLayer layer, OutputPortFlag ports, int speed, int timeRampUp, int timeContinuesRun, int timeRampDown, Brake brake = Brake.Float, bool requireReply = true)
        {
            if (speed < -100 || speed > 100)
            {
                throw new ArgumentOutOfRangeException(nameof(speed), "[-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_SPEED);
                cb.SHORT((int)layer);
                cb.SHORT((int)ports);
                cb.PAR8(speed);
                cb.PAR32(timeRampUp);
                cb.PAR32(timeContinuesRun);
                cb.PAR32(timeRampDown);
                cb.PAR8((byte)brake);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
Esempio n. 2
0
        /// <summary>
        /// This function enables synchonizing two motors.
        /// Synchonization should be used when motors should run as synchrone as possible, for example to achieve a model driving straight.
        /// Duration is specified 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">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="tachoCounts">Tacho pulses, 0 = Infinite</param>
        /// <param name="brake">Specify break level, [0: Float, 1: Break]</param>
        /// <remarks>
        /// Instruction opOutput_Step_Sync (LAYER, NOS, SPEED, TURN, STEP, BRAKE)
        /// Opcode 0xB0
        /// 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) STEP – Tacho pulses, 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, for example to archieve a model driving straight. Duration is specified in tacho counts.
        /// </remarks>
        public static async Task StepSync(ISocket socket, ChainLayer layer, OutputPortFlag ports, int speed, int turnRatio, int tachoCounts, Brake brake = Brake.Float, bool requireReply = true)
        {
            if (tachoCounts < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(tachoCounts), ">=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_STEP_SYNC);
                cb.SHORT((int)layer);
                cb.SHORT((int)ports);
                cb.PAR8(speed);
                cb.PAR16(turnRatio);
                cb.PAR32(tachoCounts);
                cb.PAR8((byte)brake);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
Esempio n. 3
0
        /// <summary>
        /// Apply new minimum and maximum raw value for device type to be used in scaling PCT and SI value
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="type">Device type</param>
        /// <param name="mode">Device mode [0-7]</param>
        /// <param name="minimum">32 bit raw minimum value (Zero point)</param>
        /// <param name="maximum">32 bit raw maximum value (Full scale)</param>
        /// <returns></returns>
        /// <remarks>
        /// Instruction opInput_Device (CMD, …)
        /// Opcode 0x99
        /// CMD: CAL_MINMAX = 0x03
        /// Arguments
        /// (Data8) TYPE – Device type (Please reference section 0)
        /// (Data8) MODE – Device mode [0-7]
        /// (Data32) CAL_MIN – 32 bit raw minimum value (Zero point)
        /// (Data32) CAL_MAX – 32 bit raw maximum value (Full scale)
        /// Description
        /// Apply new minimum and maximum raw value for device type to be used in scaling PCT and SI value
        /// </remarks>
        internal static async Task SetMinMax(ISocket socket, DeviceType type, DeviceMode mode, int minimum, int maximum)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opINPUT_DEVICE);
                cb.Raw((byte)INPUT_DEVICE_SUBCODE.CAL_MINMAX);
                cb.PAR8((byte)type);
                cb.PAR8((byte)mode);
                cb.PAR32(minimum);
                cb.PAR32(maximum);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the Operating System version
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <returns></returns>
        public static async Task <string> GetOSVersion(ISocket socket)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_REPLY, 255, 0))
            {
                cb.OpCode(OP.opUI_READ);
                cb.Raw((byte)UI_READ_SUBCODE.GET_OS_VERS);
                cb.PAR32(255);
                cb.GlobalIndex(0);
                cmd = cb.ToCommand();
            }
            Response response = await socket.Execute(cmd);

            byte[] data  = response.PayLoad;
            int    index = Array.IndexOf(data, (byte)0);

            return(Encoding.UTF8.GetString(data, 0, index));
        }