示例#1
0
        public int GetLocationFromName(string name)
        {
            EepromAddressInfo eepromInfo = eepromProfile.GetEepromInfo(name);

            if (eepromInfo != null)
            {
                return(eepromInfo.EepromAddr);
            }

            return(-1);
        }
示例#2
0
        public bool SetValue(EepromAddressInfo eepromValue, int data)
        {
            if (eepromValue == null)
            {
                return(false);
            }

            var eepromAddr = (int)eepromValue.EepromAddr;
            var mappedAddr = EepromAddrToMappedAddr(eepromAddr);

            if (mappedAddr < 0 || mappedAddr > eeprom_data.Length)
            {
                return(false);
            }

            byte[] bytes = BitConverter.GetBytes(data);
            SetBytes(eepromAddr, bytes, eepromValue.Size);
            return(true);
        }
示例#3
0
        public ushort GetAlignedByte(string name)
        {
            EepromAddressInfo eepromInfo = eepromProfile.GetEepromInfo(name);

            if (eepromInfo != null)
            {
                var mappedAddr = EepromAddrToMappedAddr(eepromInfo.EepromAddr);
                if (eepromInfo.Type == typeof(byte))
                {
                    return(eeprom_data[mappedAddr]);
                }

                if (eepromInfo.Type == typeof(ushort))
                {
                    return(BitConverter.ToUInt16(eeprom_data, mappedAddr));
                }
            }
            if (Debugger.IsAttached)
            {
                Debugger.Break();
            }

            return(0);
        }
示例#4
0
        public bool SaveToXMLFile(string filename)
        {
            TextWriter textWriter;

            try
            {
                textWriter = new StreamWriter(filename);
            }
            catch (IOException ex)
            {
                textWriter = null;
            }
            if (textWriter == null)
            {
                return(false);
            }

            SortedList <int, EepromAddressInfo> allData = eepromProfile.GetAllData();
            var serializableEepromMapping = new SerializableEEPROMMapping(eepromProfile.ProfileName);

            foreach (KeyValuePair <int, EepromAddressInfo> keyValuePair in allData)
            {
                EepromAddressInfo eepromAddressInfo = keyValuePair.Value;
                SerializableEEPROMMapping.SerializableData serializableData;
                serializableData.key   = eepromAddressInfo.Name;
                serializableData.value = "";
                if (eepromAddressInfo.EepromAddr <= eeprom_data.Length)
                {
                    var mappedAddr = EepromAddrToMappedAddr(eepromAddressInfo.EepromAddr);
                    if (eepromAddressInfo.Type == typeof(float))
                    {
                        var single = BitConverter.ToSingle(eeprom_data, mappedAddr);
                        serializableData.value = single.ToString();
                    }
                    else if (eepromAddressInfo.Type == typeof(uint))
                    {
                        var uint32 = BitConverter.ToUInt32(eeprom_data, mappedAddr);
                        serializableData.value = uint32.ToString();
                    }
                    else if (eepromAddressInfo.Type == typeof(byte))
                    {
                        var num = eeprom_data[mappedAddr];
                        serializableData.value = num.ToString();
                    }
                    else if (eepromAddressInfo.Type == typeof(ushort))
                    {
                        var uint16 = BitConverter.ToUInt16(eeprom_data, mappedAddr);
                        serializableData.value = uint16.ToString();
                    }
                    else
                    {
                        if (!(eepromAddressInfo.Type == typeof(int)))
                        {
                            throw new NotImplementedException();
                        }

                        var int16 = (int)BitConverter.ToInt16(eeprom_data, mappedAddr);
                        serializableData.value = int16.ToString();
                    }
                    serializableEepromMapping.serializedData.Add(serializableData);
                }
            }
            var namespaces = new XmlSerializerNamespaces();

            namespaces.Add(string.Empty, string.Empty);
            new XmlSerializer(typeof(SerializableEEPROMMapping)).Serialize(textWriter, serializableEepromMapping, namespaces);
            textWriter.Close();
            return(true);
        }