/// <summary> /// Start a new command of a speicifc type with a global and/or local buffer on the EV3 brick /// </summary> /// <param name="commandType">The type of the command to start</param> /// <param name="globalSize">The size of the global buffer in bytes (maximum of 1024 bytes)</param> /// <param name="localSize">The size of the local buffer in bytes (maximum of 64 bytes)</param> public void Initialize(CommandType commandType, ushort globalSize, int localSize) { if (globalSize > 1024) { throw new ArgumentException("Global buffer must be less than 1024 bytes", nameof(globalSize)); } if (localSize > 64) { throw new ArgumentException("Local buffer must be less than 64 bytes", nameof(localSize)); } _stream = new MemoryStream(); _writer = new BinaryWriter(_stream); Response = ResponseManager.CreateResponse(); CommandType = commandType; // 2 bytes (this gets filled in later when the user calls ToBytes()) _writer.Write((ushort)0xffff); // 2 bytes _writer.Write(Response.Sequence); // 1 byte _writer.Write((byte)commandType); if (commandType == CommandType.DirectReply || commandType == CommandType.DirectNoReply) { // 2 bytes (llllllgg gggggggg) _writer.Write((byte)globalSize); // lower bits of globalSize _writer.Write((byte)((localSize << 2) | (globalSize >> 8) & 0x03)); // upper bits of globalSize + localSize } }
/// <summary> /// Create a directory on the EV3 brick /// </summary> /// <param name="devicePath">Destination path on the brick.</param> /// <returns></returns> /// <remarks>devicePath is relative from "lms2012/sys" on the EV3 brick. Destination folders are automatically created if provided in the path. The path must start with "apps", "prjs", or "tools".</remarks> public async Task CreateDirectoryAsync(string devicePath) { var r = ResponseManager.CreateResponse(); var c = new Command(CommandType.SystemReply); c.CreateDirectory(devicePath); await _brick.SendCommandAsyncInternal(c); if (r.SystemReplyStatus != SystemReplyStatus.Success) { throw new Exception("Error creating directory: " + r.SystemReplyStatus); } }
/// <summary> /// Delete file from the EV3 brick /// </summary> /// <param name="devicePath">Destination path on the brick.</param> /// <returns></returns> /// <remarks>devicePath is relative from "lms2012/sys" on the EV3 brick. The path must start with "apps", "prjs", or "tools".</remarks> public async Task DeleteFileAsync(string devicePath) { var r = ResponseManager.CreateResponse(); var c = new Command(CommandType.SystemReply); c.DeleteFile(devicePath); await _brick.SendCommandAsyncInternal(c); if (r.SystemReplyStatus != SystemReplyStatus.Success) { throw new Exception("Error deleting file: " + r.SystemReplyStatus); } }