コード例 #1
0
        /// <summary>
        /// Creates a byte array representation of this IR Code.
        /// </summary>
        /// <returns>Byte array representation (internally it is in Pronto format).</returns>
        public byte[] ToByteArray()
        {
            StringBuilder output = new StringBuilder();

            ushort[] prontoData = Pronto.ConvertIrCodeToProntoRaw(this);

            for (int index = 0; index < prontoData.Length; index++)
            {
                output.Append(prontoData[index].ToString("X4"));
                if (index != prontoData.Length - 1)
                {
                    output.Append(' ');
                }
            }

            return(Encoding.ASCII.GetBytes(output.ToString()));
        }
コード例 #2
0
        /// <summary>
        /// Creates an IrCode object from Pronto format file bytes.
        /// </summary>
        /// <param name="data">IR file bytes.</param>
        /// <returns>New IrCode object.</returns>
        private static IrCode FromProntoData(byte[] data)
        {
            string code = Encoding.ASCII.GetString(data);

            string[] stringData = code.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            ushort[] prontoData = new ushort[stringData.Length];
            for (int i = 0; i < stringData.Length; i++)
            {
                prontoData[i] = ushort.Parse(stringData[i], NumberStyles.HexNumber);
            }

            IrCode newCode = Pronto.ConvertProntoDataToIrCode(prontoData);

            if (newCode != null)
            {
                newCode.FinalizeData();
            }
            // Seems some old files have excessively long delays in them .. this might fix that problem ...

            return(newCode);
        }