Ejemplo n.º 1
0
        /// <summary>
        /// Write a single value to the EV3's memory
        /// </summary>
        /// <param name="value">Value to write</param>
        /// <param name="memoryIndex">Memory index on the EV3</param>
        public void Write(TValue value, Int32 memoryIndex)
        {
            var command = new Command(0, 0, 130, true);

            command.Append(ByteCodes.ArrayWrite);
            command.Append(Handle, ConstantParameterType.Value);
            command.Append(memoryIndex, ConstantParameterType.Value);
            if (typeof(TValue) == typeof(byte))
            {
                command.Append((byte)Convert.ToByte(value), ConstantParameterType.Value);
            }
            if (typeof(TValue) == typeof(Int16))
            {
                command.Append(Convert.ToInt16(value));
            }
            if (typeof(TValue) == typeof(Int32))
            {
                command.Append(Convert.ToInt32(value));
            }
            if (typeof(TValue) == typeof(float))
            {
                command.Append(Convert.ToSingle(value));
            }
            //command.Append((byte)0, VariableScope.Global);
            command.Print();
            connection.Send(command);
            var reply = connection.Receive();

            Error.CheckForError(reply, 130);
        }
				/// <summary>
				/// Send a byte array to the mailbox
				/// </summary>
				/// <param name="mailboxName">Mailbox name to send to.</param>
				/// <param name="data">Data to send.</param>
				/// <param name="reply">If set to <c>true</c> reply from the brick will be send.</param>
				public void Send (string mailboxName, byte[] data, bool reply = false)
				{
					var command = new Command (SystemCommand.WriteMailbox, 100, reply);
					Int16 payloadLength = (Int16)data.Length;
					byte nameLength = (byte)(mailboxName.Length + 1);
					command.Append (nameLength);
					command.Append (mailboxName);
					command.Append(payloadLength);
					command.Append(data);
					connection.Send(command);
					if(reply){
						var brickReply = connection.Receive();
						Error.CheckForError(brickReply,100);
					}
					command.Print();
				}
Ejemplo n.º 3
0
        /// <summary>
        /// Send a byte array to the mailbox
        /// </summary>
        /// <param name="mailboxName">Mailbox name to send to.</param>
        /// <param name="data">Data to send.</param>
        /// <param name="reply">If set to <c>true</c> reply from the brick will be send.</param>
        public void Send(string mailboxName, byte[] data, bool reply = false)
        {
            var   command       = new Command(SystemCommand.WriteMailbox, 100, reply);
            Int16 payloadLength = (Int16)data.Length;
            byte  nameLength    = (byte)(mailboxName.Length + 1);

            command.Append(nameLength);
            command.Append(mailboxName);
            command.Append(payloadLength);
            command.Append(data);
            connection.Send(command);
            if (reply)
            {
                var brickReply = connection.Receive();
                Error.CheckForError(brickReply, 100);
            }
            command.Print();
        }