Esempio n. 1
0
        public async Task <bool> Equals(MemoryRegister <T> other)
        {
            if (other == null)
            {
                return(false);
            }

            bool ok_id          = string.Equals(this.id, other.id);
            bool ok_description = string.Equals(this.description, other.description);
            bool ok_address     = (this.address == other.address);
            bool ok_size        = (this.size == other.size);
            bool ok_write       = (this.write == other.write);

            byte[] valLocal = new byte[] { };
            byte[] valOther = new byte[] { };

            bool ok_value = true;

            try
            {
                if (this.valueType != RegType.BOOL)
                {
                    valLocal = this.ValueByteArrayRaw;
                    valOther = await other.GetValueByteArray();

                    ok_value = valLocal.SequenceEqual(valOther);

                    Utils.Print("Equals: " + this.id + " -> " +
                                Utils.ByteArrayToString(valLocal) + " == " +
                                Utils.ByteArrayToString(valOther) + " = " +
                                ok_value);
                }
                else
                {
                    T bitLocal = this.ValueRaw;
                    T bitOther = await other.GetValueFromMtu();

                    ok_value = (bool.Equals(bitLocal, bitOther));

                    Utils.Print("Equals: " + this.id + " -> " +
                                bitLocal + " == " +
                                bitOther + " = " +
                                ok_value);
                }
            }
            catch (Exception e)
            {
                return(false);
            }

            return(ok_id &&
                   ok_description &&
                   ok_address &&
                   ok_size &&
                   ok_write &&
                   ok_value);
        }
Esempio n. 2
0
        // Use with <CustomGet>method:ULongToBcd</CustomGet>
        public async Task <ulong> BcdToULong(MemoryRegister <ulong> MemoryRegister)
        {
            byte[] bytes = await MemoryRegister.GetValueByteArray();

            string outNum = string.Empty;

            foreach (byte b in bytes)
            {
                outNum += b.ToString("X");
            }
            outNum = outNum.TrimEnd(new char[] { 'F' });

            outNum = outNum
                     .Replace("A", "10")
                     .Replace("B", "11")
                     .Replace("C", "12")
                     .Replace("D", "13")
                     .Replace("E", "14")
                     .Replace("F", "15");

            return(ulong.Parse(outNum));
        }