/// <summary>
        /// Check if file or folder exists
        /// </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 file or folder exists otherwise <c>false</c></returns>
        /// <exception cref="ArgumentException"/>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="FirmwareException"/>
        public static async Task <bool> Exists(ISocket socket, string brickPath)
        {
            brickPath.IsBrickPath();

            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_REPLY, 1, 0))
            {
                cb.OpCode(OP.opFILENAME);
                cb.Raw((byte)FILENAME_SUBCODE.EXIST);
                cb.PARS(brickPath);
                cb.GlobalIndex(0);
                cmd = cb.ToCommand();
            }
            Response response = await socket.Execute(cmd);

            return(response.PayLoad[0] == 1);
        }
        //CMD: BMPFILE = 0x1C
        //Arguments
        //(DATA8) Color – Specify either black or white, [0: White, 1: Black]
        //(Data16) X0 – Specify X start point, [0 - 177]
        //(Data16) Y0 – Specify Y start point, [0 - 127]
        //(Data8) NAME – First character in filename(Character string)
        //Description
        //Enable displaying BMP file from icon file within running project.
        internal static async Task BMPFile(ISocket socket, string path, int x = 0, int y = 0, UIColor color = UIColor.Black)
        {
            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opUI_DRAW);
                cb.Raw((byte)UI_DRAW_SUBCODE.BMPFILE);
                cb.PAR8((int)color);
                cb.PAR16(x);
                cb.PAR16(y);
                cb.PARS(path);
                cb.OpCode(OP.opUI_DRAW);
                cb.Raw((byte)UI_DRAW_SUBCODE.UPDATE);
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
        /// <summary>
        /// Repeats playing a sound file on the brick 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="filePath">FilePath to sound file: ../prjs/myproject/file.rsf</param>
        /// <remarks>
        /// Instruction opSound (CMD, …)
        /// Opcode 0x94
        /// Arguments (Data8) CMD => Specific command parameter documented below
        /// Dispatch status Unchanged
        /// Description Sound control entry
        /// CMD: REPEAT = 0x03
        /// Arguments
        /// (Data8) VOLUME – Specify volume for playback, [0 - 100]
        /// (Data8) NAME – First character in filename (Character string)
        /// </remarks>
        internal static async Task Repeat(ISocket socket, int volume, string filePath)
        {
            if (volume < 0 || volume > 100)
            {
                throw new ArgumentOutOfRangeException("Volume must be between 0 and 100", "volume");
            }

            //soundfiles will not play when extension in path
            filePath = Path.ChangeExtension(filePath, null);

            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_NO_REPLY))
            {
                cb.OpCode(OP.opSOUND);
                cb.Raw((byte)SOUND_SUBCODE.REPEAT);
                cb.PAR8(volume);   // (Data8) VOLUME
                cb.PARS(filePath); // (Data8) NAME – First character in filename (Character string) ?
                cmd = cb.ToCommand();
            }
            await socket.Execute(cmd);
        }
        /// <summary>
        /// Gets directoryinfo item count and total size
        /// </summary>
        /// <param name="socket">socket for executing command to brick</param>
        /// <param name="brickDirectoryPath">relative path to folder on brick</param>
        /// <returns>DirectoryInfo</returns>
        /// <exception cref="ArgumentException"/>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="FirmwareException"/>
        public static async Task <DirectoryInfo> GetDirectoryInfo(ISocket socket, string brickDirectoryPath)
        {
            brickDirectoryPath = FileSystem.ToBrickDirectoryPath(brickDirectoryPath);
            brickDirectoryPath.IsBrickDirectoryPath();

            Command cmd = null;

            using (CommandBuilder cb = new CommandBuilder(CommandType.DIRECT_COMMAND_REPLY, 8, 0))
            {
                cb.OpCode(OP.opFILENAME);
                cb.Raw((byte)FILENAME_SUBCODE.TOTALSIZE);
                cb.PARS(brickDirectoryPath);
                cb.GlobalIndex(0);
                cb.GlobalIndex(4);
                cmd = cb.ToCommand();
            }
            Response response = await socket.Execute(cmd);

            byte[] data  = response.PayLoad;
            int    items = BitConverter.ToInt32(data, 0);
            int    size  = BitConverter.ToInt32(data, 4);

            return(new DirectoryInfo(items, size));
        }