Exemple #1
0
        /// <summary>
        /// Read information about external device
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="port">Port number [0-31]</param>
        /// <returns>Format</returns>
        /// <remarks>
        /// Instruction opInput_Device (CMD, …)
        /// Opcode 0x99
        /// CMD: GET_FORMAT = 0x02
        /// Arguments
        /// (Data8) LAYER – Specify chain layer number [0-3]
        /// (Data8) NO – Port number
        /// Returns
        /// (Data8) Datasets – Number of data sets
        /// (Data8) FORMAT – Format [0-3], (0: 8-bit, 1: 16-bit, 2: 32-bit, 3: Float point)
        /// (Data8) MODES – Number of modes [1-8]
        /// (Data8) VIEW – Number of modes visible within port view app [1-8]
        /// </remarks>
        internal static async Task <Format> GetFormat(ISocket socket, ChainLayer layer, int port)
        {
            if (port < 0 || port > 31)
            {
                throw new ArgumentException("Number of port must be between 0 and 31", nameof(port));
            }

            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_REPLY, 4, 0))
            {
                cb.OpCode(OP.opINPUT_DEVICE);
                cb.Raw((byte)INPUT_DEVICE_SUBCODE.GET_FORMAT);
                cb.PAR8((byte)layer);
                cb.PAR8((byte)port);
                cb.GlobalIndex(0);
                cb.GlobalIndex(1);
                cb.GlobalIndex(2);
                cb.GlobalIndex(3);
                cmd = cb.ToCommand();
            }
            Response response = await socket.Execute(cmd);

            byte[] data = response.PayLoad;
            return(new Format(data[0], (DataType)data[1], data[2], data[3]));
        }
Exemple #2
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);
        }
Exemple #3
0
        /// <summary>
        /// Gets the connection type for the given port
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="port">Port number [0 - 31]</param>
        /// <returns></returns>
        /// <remarks>
        /// Instruction opInput_Device (CMD, …)
        /// Opcode 0x99
        /// CMD: GET_CONNECTION = 0x0C
        /// Arguments
        /// (Data8) LAYER – Specify chain layer number [0-3]
        /// (Data8) NO – Port number
        /// Returns
        /// (Data8) CONN – Connection type
        /// </remarks>
        internal static async Task <ConnectionType> GetConnection(ISocket socket, int port)
        {
            if (port < 0 || port > 31)
            {
                throw new ArgumentException("Number of port must be between 0 and 31", "port");
            }
            ChainLayer layer = GetLayer(port);

            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_REPLY, 1, 0))
            {
                cb.OpCode(OP.opINPUT_DEVICE);
                cb.Raw((byte)INPUT_DEVICE_SUBCODE.GET_CONNECTION);
                cb.PAR8((byte)layer);
                cb.PAR8((ushort)port);
                cb.GlobalIndex(0);
                cmd = cb.ToCommand();
            }
            Response response = await socket.Execute(cmd);

            ConnectionType type = ConnectionType.CONN_UNKNOW;

            if (response.Type == ResponseType.OK)
            {
                byte[] data = response.PayLoad;
                if (data.Length > 0)
                {
                    type = (ConnectionType)data[0];
                }
            }
            return(type);
        }
Exemple #4
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);
        }
Exemple #5
0
        /// <summary>
        /// Gets the Negative changes since last clear. (Button release)
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="port">Port number [0 - 31]</param>
        /// <returns></returns>
        /// <remarks>
        /// Instruction opInput_Device (CMD, …)
        /// Opcode 0x99
        /// CMD: GET_BUMPS = 0x1F
        /// Arguments
        /// (Data8) LAYER – Specify chain layer number [0-3]
        /// (Data8) NO – Port number
        /// Returns
        /// (DataF) VALUE1 – Negative changes since last clear. (Button release)
        /// </remarks>
        internal static async Task <int> GetBumps(ISocket socket, int port)
        {
            if (port < 0 || port > 31)
            {
                throw new ArgumentException("Number of port must be between 0 and 31", "port");
            }
            ChainLayer layer = GetLayer(port);
            Command    cmd   = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_REPLY, 1, 0))
            {
                GetBumpsValue_BatchCommand(cb, layer, port, 0);
                cmd = cb.ToCommand();
            }
            Response response = await socket.Execute(cmd);

            float value = 0;

            if (response.Type == ResponseType.OK)
            {
                byte[] data = response.PayLoad;
                if (data.Length > 1)
                {
                    value = BitConverter.ToSingle(data, 0);
                }
            }
            //Bumps are negative, but output them positive :)
            return(-1 * (int)value);
        }
        /// <summary>
        /// Plays a tone based on frequency for given duration and at a given volume.
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="volume">Specify volume for playback, [0 - 100]</param>
        /// <param name="frequency">Specify frequency, [250 - 10000]</param>
        /// <param name="duration">Specify duration in milliseconds [1 - n]</param>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <remarks>
        /// Instruction opSound (CMD, …)
        /// Opcode 0x94
        /// Arguments (Data8) CMD => Specific command parameter documented below
        /// Dispatch status Unchanged
        /// Description Sound control entry
        /// CMD: TONE = 0x01
        /// Arguments
        /// (Data8) VOLUME – Specify volume for playback, [0 - 100]
        /// (Data16) FREQUENCY – Specify frequency, [250 - 10000]
        /// (Data16) DURATION – Specify duration in millisecond
        /// </remarks>
        internal static async Task Tone(ISocket socket, int volume, int frequency, int duration)
        {
            if (volume < 0 || volume > 100)
            {
                throw new ArgumentOutOfRangeException("Volume must be between 0 and 100", "volume");
            }
            if (frequency < 250 || frequency > 10000)
            {
                throw new ArgumentOutOfRangeException("Frequency must be between 250 and 10000", "frequency");
            }
            if (duration < 1)
            {
                throw new ArgumentOutOfRangeException("Duration must be longer than 0", "duration");
            }

            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opSOUND);
                cb.Raw((byte)SOUND_SUBCODE.TONE);
                cb.PAR8(volume);
                cb.PAR16(frequency);
                cb.PAR16(duration);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
Exemple #7
0
        /// <summary>
        /// This function enables reading specific device and mode in Pct
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="port">Port</param>
        /// <param name="type">Type of the device (0 = Don’t change type)</param>
        /// <param name="mode"> Device mode [0 - 7] (-1 = Don’t change mode)</param>
        /// <param name="numberOfValues">Number of values to expect in return</param>
        /// <returns></returns>
        /// <remarks>
        /// Instruction
        ///        opINPUT_DEVICE
        ///         CMD: READY_PCT = 0x1B
        ///Arguments
        ///(Data8) LAYER – Specify chain layer number [0-3]
        ///(Data8) NO – Port number
        ///(Data8) TYPE – Specify device type (0 = Don’t change type)
        ///(Data8) MODE – Device mode [0-7] (-1 = Don’t change mode)
        ///(Data8) VALUES – Number of return values
        ///Returns (Depending on number of data samples requested in (VALUES))
        ///(Data8) VALUE1 – First value received from sensor in the specified mode
        /// </remarks>
        internal static async Task <int> GetReadyPct(ISocket socket, int port, ushort type = 0, int mode = -1, int numberOfValues = 1)
        {
            if (port < 0 || port > 31)
            {
                throw new ArgumentException("Number of port must be between 0 and 31", "port");
            }
            ChainLayer layer = GetLayer(port);

            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_REPLY, 4, 0))
            {
                GetReadyPct_BatchCommand(cb, layer, port, type, mode, numberOfValues, 1);
                cmd = cb.ToCommand();
            }
            Response response = await socket.Execute(cmd);

            int value = 0;

            if (response.Type == ResponseType.OK)
            {
                byte[] data = response.PayLoad;
                if (data.Length > 0)
                {
                    value = BitConverter.ToInt32(data, 0);
                }
            }
            return(value);
        }
Exemple #8
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);
        }
Exemple #9
0
        /// <summary>
        /// Reads the type and mode of the connected device
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="port">Port [0-31]</param>
        /// <returns>TypeMode</returns>
        /// <remarks>
        /// Instruction opInput_Device (CMD, …)
        /// Opcode 0x99
        /// CMD: GET_TYPEMODE = 0x05
        /// Arguments
        /// (Data8) LAYER – Specify chain layer number [0-3]
        /// (Data8) NO – Port number
        /// Returns
        /// (Data8) TYPE – See device type list (Please reference section 0)
        /// (Data8) MODE – Device mode [0-7]
        /// </remarks>
        internal static async Task <DeviceTypeMode> GetTypeMode(ISocket socket, int port)
        {
            if (port < 0 || port > 31)
            {
                throw new ArgumentException("Number of port must be between 0 and 31", nameof(port));
            }
            ChainLayer layer = GetLayer(port);

            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_REPLY, 2, 0))
            {
                cb.OpCode(OP.opINPUT_DEVICE);
                cb.Raw((byte)INPUT_DEVICE_SUBCODE.GET_TYPEMODE);
                cb.PAR8((byte)layer);
                cb.PAR8((byte)port);
                cb.GlobalIndex(0);
                cb.GlobalIndex(1);
                cmd = cb.ToCommand();
            }
            Response response = await socket.Execute(cmd);

            byte[] data = response.PayLoad;
            return(new DeviceTypeMode((DeviceType)data[0], (DeviceMode)data[1]));
        }
        /// <summary>
        /// Enables program execution to wait for sound ready. (Wait for completion)
        /// Dispatch status Can changed to BUSYBREAK
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <remarks>
        /// Instruction opSound_Ready ()
        /// Opcode 0x96
        /// Arguments
        /// Dispatch status Can changed to BUSYBREAK
        /// Description Enables program execution to wait for sound ready. (Wait for completion)
        /// </remarks>
        internal static async Task Ready(ISocket socket)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opSOUND_READY);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
Exemple #11
0
        /// <summary>
        /// This function should be called a program end. It enables breaking the motor for a short period and right after floating the motors. The function relates to the layer on which it is executed.
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <remarks>
        /// Instruction opOutput_Prg_Stop
        /// Opcode 0xB4
        /// Arguments
        /// Dispatch status Unchanged
        /// Description This function should be called a program end. It enables breaking the motor for a short period and right after floating the motors. The function relates to the layer on which it is executed.
        /// </remarks>
        public static async Task ProgramStop(ISocket socket, 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_PRG_STOP);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
        /// <summary>
        /// Stops current sound playback.
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <remarks>
        /// Instruction opSound (CMD, …)
        /// Opcode 0x94
        /// Arguments (Data8) CMD => Specific command parameter documented below
        /// Dispatch status Unchanged
        /// Description Sound control entry
        /// CMD: BREAK = 0x00 (Stop current sound playback)
        /// </remarks>
        internal static async Task Break(ISocket socket)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opSOUND);
                cb.Raw((byte)SOUND_SUBCODE.BREAK);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
        /// <summary>
        /// Flushes all button states
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="requireReply">indicate if the brick should reply</param>
        /// <returns></returns>
        public static async Task Flush(ISocket socket, bool requireReply = true)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.Raw((byte)OP.opUI_BUTTON);
                cb.Raw((byte)UI_BUTTON_SUBCODE.FLUSH);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
        //CMD: UPDATE = 0x00
        //Description
        //Automatically triggers a refreshes of the display.
        internal static async Task Update(ISocket socket)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opUI_DRAW);
                cb.Raw((byte)UI_DRAW_SUBCODE.UPDATE);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
        private static async Task <Response> ContinueDownload(ISocket socket, byte handle, ushort payLoad)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.SYSTEM_COMMAND_REPLY))
            {
                cb.OpCode(SYSTEM_OP.CONTINUE_UPLOAD);
                cb.Raw(handle);
                cb.Raw(payLoad);
                cmd = cb.ToCommand();
            }
            return(await socket.Execute(cmd));
        }
Exemple #16
0
        /// <summary>
        /// Set Led mode
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="ledMode">Pattern of the led</param>
        public static async Task Led(ISocket socket, LedMode ledMode, bool requireReply = false)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(requireReply ? CommandType.DIRECT_COMMAND_REPLY : CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opUI_WRITE);
                cb.Raw((byte)UI_WRITE_SUBCODE.LED);
                cb.PAR8((byte)ledMode);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
Exemple #17
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);
        }
        /// <summary>
        /// Verifies if a button has been clicked, or depending on mode pressed.
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="button">type of the button</param>
        /// <param name="mode">mode of click</param>
        /// <returns><c>true</c> if clicked, otherwise <c>false</c></returns>
        public static async Task <bool> GetClick(ISocket socket, ButtonType button, ButtonMode mode = ButtonMode.Click)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_REPLY, 1, 0))
            {
                BatchCommand(cb, button, mode, 0);
                cmd = cb.ToCommand();
            }
            Response response = await socket.Execute(cmd);

            return(BitConverter.ToBoolean(response.PayLoad, 0));
        }
Exemple #19
0
        /// <summary>
        /// Stop all input devices
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="layer">Specify chain layer number [0 - 3]</param>
        /// <returns></returns>
        /// <remarks>
        /// Instruction opInput_Device (CMD, …)
        /// Opcode 0x99
        /// CMD: STOP_ALL= 0x0D (Stop all devices)
        /// Arguments
        /// (Data8) LAYER – Specify chain layer number [0-3] (-1 = All)
        /// </remarks>
        internal static async Task Stop(ISocket socket, ChainLayer layer)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opINPUT_DEVICE);
                cb.Raw((byte)INPUT_DEVICE_SUBCODE.STOP_ALL);
                cb.PAR8((byte)layer);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
Exemple #20
0
        /// <summary>
        /// Gets battery values : voltage, current, temperature and level
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <returns></returns>
        public static async Task <BatteryValue> GetBatteryValue(ISocket socket)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_REPLY, 13, 0))
            {
                GetBatteryValue_BatchCommand(cb, 0);
                cmd = cb.ToCommand();
            }
            Response response = await socket.Execute(cmd);

            return(BatteryValue(response.PayLoad, 0));
        }
        private static async Task <Response> BeginUpload(ISocket socket, int fileSize, string brickFilePath)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.SYSTEM_COMMAND_REPLY))
            {
                cb.OpCode(SYSTEM_OP.BEGIN_DOWNLOAD);
                cb.Raw((uint)fileSize);
                cb.Raw(brickFilePath);
                cmd = cb.ToCommand();
            }
            return(await socket.Execute(cmd));
        }
        private static async Task <Response> BeginDownload(ISocket socket, string brickFilePath)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.SYSTEM_COMMAND_REPLY))
            {
                cb.OpCode(SYSTEM_OP.BEGIN_UPLOAD);
                cb.Raw((ushort)0); // set to 0 to just have handle and filesize returned
                cb.Raw(brickFilePath);
                cmd = cb.ToCommand();
            }
            return(await socket.Execute(cmd));
        }
Exemple #23
0
        /// <summary>
        /// Apply the default 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>
        /// <returns></returns>
        /// <remarks>
        /// Instruction opInput_Device (CMD, …)
        /// Opcode 0x99
        /// CMD: CAL_DEFAULT = 0x04
        /// Arguments
        /// (Data8) TYPE – Device type (Please reference section 0)
        /// (Data8) MODE – Device mode [0-7]
        /// Description
        /// Apply the default minimum and maximum raw value for device type to be used in scaling PCT and SI value
        /// </remarks>
        internal static async Task SetDefaultMinMax(ISocket socket, DeviceType type, DeviceMode mode)
        {
            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_DEFAULT);
                cb.PAR8((byte)type);
                cb.PAR8((byte)mode);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
Exemple #24
0
        /// <summary>
        /// This function enables specifying the output device type
        /// </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>
        /// <param name="type">Output device type, (0x07: Large motor, Medium motor = 0x08)</param>
        /// <param name="requireReply">indicate if the brick should respond OK on method call</param>
        /// <remarks>
        /// Instruction opOutput_Set_Type (LAYER, NO, TYPE)
        /// Opcode 0xA1
        /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3]
        /// (Data8) NO – Port number [0 - 3]
        /// (Data8) TYPE – Output device type, (0x07: Large motor, Medium motor = 0x08)
        /// Dispatch status Unchanged
        /// Description This function enables specifying the output device type
        /// </remarks>
        public static async Task SetType(ISocket socket, ChainLayer layer, OutputPortName port, DeviceType type, 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_SET_TYPE);
                cb.SHORT((int)layer);
                cb.SHORT((int)port);
                cb.PAR8((byte)type);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
Exemple #25
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);
        }
Exemple #26
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);
        }
Exemple #27
0
        /// <summary>
        /// Clear all device counters and values on all layers
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <returns></returns>
        /// <remarks>
        /// Instruction opInput_Device (CMD, …)
        /// Opcode 0x99
        /// CMD: CLR_ALL = 0x0A
        /// Arguments
        /// (Data8) LAYER – Specify chain layer number [0-3] (-1 = All)
        /// Description
        /// Clear all device counters and values
        /// </remarks>
        internal static async Task Reset(ISocket socket)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                int all = -1;
                cb.OpCode(OP.opINPUT_DEVICE);
                cb.Raw((byte)INPUT_DEVICE_SUBCODE.CLR_ALL);
                cb.PAR8((byte)all);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
        /// <summary>
        /// Delete a file or folder on the brick
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="brickPath">relative path to file or folder on brick</param>
        /// <returns><c>true</c> if success, otherwise <c>false</c></returns>
        /// <exception cref="ArgumentException"/>
        /// <exception cref="ArgumentNullException"/>
        public static async Task <bool> Delete(ISocket socket, string brickPath)
        {
            brickPath.IsBrickPath();

            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.SYSTEM_COMMAND_REPLY))
            {
                cb.OpCode(SYSTEM_OP.DELETE_FILE);
                cb.Raw(brickPath);
                cmd = cb.ToCommand();
            }
            Response response = await socket.Execute(cmd);

            return(response.Status == ResponseStatus.SUCCESS);
        }
Exemple #29
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));
        }
Exemple #30
0
        /// <summary>
        /// This function enables the program to read the tacho count 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_Get_Count (LAYER, NOS, *TACHO)
        /// Opcode 0xB3
        /// Arguments (Data8) LAYER – Specify chain layer number [0 - 3]
        /// (Data8) NOS – Output bit field [0x00 – 0x0F]
        /// (Data32) *TACHO – Tacho count as sensor value
        /// Dispatch status Unchanged
        /// Description This function enables the program to read the tacho count as sensor input.
        /// </remarks>
        public static async Task <int> GetTachoCount(ISocket socket, ChainLayer layer, OutputPortName port)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_REPLY, 4, 0))
            {
                cb.OpCode(OP.opOUTPUT_GET_COUNT);
                cb.PAR8((byte)layer);
                cb.PAR8((byte)port);
                cb.VARIABLE_PAR32(0, PARAMETER_VARIABLE_SCOPE.GLOBAL);
                cmd = cb.ToCommand();
            }

            Response response = await socket.Execute(cmd);

            return(BitConverter.ToInt32(response.PayLoad, 0));
        }