I'm reading in tags and values from an XML file for information that is needed for a functional test software. When adding the Frequencies to the list, the frequencies for all other existing list items are overwritten by the new frequencies.
public struct Configuration
{
public string Description;
public byte Mode;
public byte Deviation;
public string PartNumber;
public UInt16[] Frequencies;
public byte TxPower;
public byte PWM;
public Int16 HeaterSetpoint;
public string FirmwareVersion;
public bool Active;
public int Threshold;
} // struct Configuration
Configurations = new List<Configuration>();
ushort[] Frequencies = new ushort [7];
Configuration TestConfig = new Configuration();
/*Open the XML file, load all the tag values into XmlNodeList */
//Pull in all the XML Tag Values Sorted by Tag Name
XmlNodeList xml_description = ConfigFile.GetElementsByTagName("description");
XmlNodeList xml_mode = ConfigFile.GetElementsByTagName("mode");
XmlNodeList xml_deviation = ConfigFile.GetElementsByTagName("deviation");
XmlNodeList xml_partnumber = ConfigFile.GetElementsByTagName("partnumber");
XmlNodeList xml_channel0 = ConfigFile.GetElementsByTagName("channel0");
XmlNodeList xml_channel1 = ConfigFile.GetElementsByTagName("channel1");
XmlNodeList xml_channel2 = ConfigFile.GetElementsByTagName("channel2");
XmlNodeList xml_channel3 = ConfigFile.GetElementsByTagName("channel3");
XmlNodeList xml_channel4 = ConfigFile.GetElementsByTagName("channel4");
XmlNodeList xml_channel5 = ConfigFile.GetElementsByTagName("channel5");
XmlNodeList xml_channel6 = ConfigFile.GetElementsByTagName("channel6");
XmlNodeList xml_txpower = ConfigFile.GetElementsByTagName("txpower");
XmlNodeList xml_pwm = ConfigFile.GetElementsByTagName("pwm");
XmlNodeList xml_hsp = ConfigFile.GetElementsByTagName("hsp");
XmlNodeList xml_firmware = ConfigFile.GetElementsByTagName("firmware");
XmlNodeList xml_active = ConfigFile.GetElementsByTagName("active");
XmlNodeList xml_threshold = ConfigFile.GetElementsByTagName("threshold");
/*Use LINQ to check that the XmlNodeLists are all the same length. This way we don't try and load invalid data*/
if(!listsaresamelength)
{
/*Alert user there is a problem with the XML file and close the application*/
}
//Loop to add values to the List
for(i = 0; i < NumberofXmlValues; i++)
{
/*check that the description, Mode, Deviation are valid and add them to DummyConfig*/
try
{
Frequencies[0] = UInt16.Parse(xml_channel0[i].InnerText);
Frequencies[1] = UInt16.Parse(xml_channel1[i].InnerText);
Frequencies[2] = UInt16.Parse(xml_channel2[i].InnerText);
Frequencies[3] = UInt16.Parse(xml_channel3[i].InnerText);
Frequencies[4] = UInt16.Parse(xml_channel4[i].InnerText);
Frequencies[5] = UInt16.Parse(xml_channel5[i].InnerText);
Frequencies[6] = UInt16.Parse(xml_channel6[i].InnerText);
//Move the frequencies to the list
TestConfig.Frequencies = Frequencies;
}
catch
{
/*Problem with the XML file. Alert the user and close the application*/
}
/*check that the heater set point, PWM set point, partnumber, Txpower, and Threshold are valid and add them to DummyConfig*/
Configurations.Add(TestConfig)
}
The first iteration of the for loop works fine; here's the result: first loop iteration second loop iteration
I've tried a few different ways to change how I'm writing to the list, but they all generate the same result. I feel like I'm missing something obvious.