Esempio n. 1
0
        /// <summary>
        /// CreateMirrorMoveCommand is used to generate the Byte
        /// Array that will be sent to the NXT Brick to move a
        /// Mirror.
        /// </summary>
        /// <param name="axis">The Axis that needs to be moved -- X or Y</param>
        /// <param name="relativePos">The amount by which to move the mirror relative to the current position</param>
        /// <returns>Byte Array of LEGO Command</returns>
        private Byte[] CreateMirrorMoveCommand(Enums.MirrorAxis axis, Int32 relativePos)
        {
            //Declare a List to hold the command
            List <Byte> rtn = new List <Byte>();

            //Set the command type -- Direct with reply
            rtn.Add((Byte)LEGOCommandType.DirectCommand);

            //Set the MessageWrite command
            rtn.Add((Byte)LEGODirectCommand.MessageWrite);

            //Set the Mailbox to which to send message
            rtn.Add(LEGOMirror._mailboxID);

            //Create a string with the data in it
            String msg = Convert.ToByte(axis).ToString() + "|" + LEGOMirror._motorPower.ToString() + "|" + relativePos.ToString();

            //Add the length of the string for message size -- add
            //one for the null character added below
            rtn.Add(Convert.ToByte(msg.Length + 1));

            //Turn the String to a Char array
            Char[] msgChars = msg.ToCharArray();

            //Put each byte into the command
            foreach (Char c in msgChars)
            {
                rtn.Add((Byte)c);
            }

            //Add a null byte for the end of the string
            rtn.Add(0);

            //Return the result
            return(rtn.ToArray());
        }