private void sendPidButton_Click(object sender, EventArgs e) { //save all settings before sending CurrentData currentData = new CurrentData(); //have to do each one individually because two-dimentional arrays are wierd. for (int i = 0; i < 3; i++) { currentData.altPID[i] = PIDs[0, i]; currentData.pitchPID[i] = PIDs[1, i]; currentData.bankPID[i] = PIDs[2, i]; currentData.speedPID[i] = PIDs[3, i]; currentData.headingPID[i] = PIDs[4, i]; currentData.runwayLineupPID[i] = PIDs[5, i]; } var writer = new XmlSerializer(typeof(CurrentData)); var wfile = new StreamWriter("currentData.xml"); writer.Serialize(wfile, currentData); wfile.Close(); //encode and send the values to the serial port if (serialPort.IsOpen) { //send only selected PIDs if (pidPickerDropdown.SelectedIndex != -1) { string str = "CP"; switch (pidPickerDropdown.SelectedIndex) { case 0: str += "A"; break; case 1: str += "P"; break; case 2: str += "B"; break; case 3: str += "S"; break; case 4: str += "H"; break; case 5: str += "R"; break; default: break; } string strSave = str; //the first part of the message will be the same throughout all 3 messages str += "p"; str += (float)pBox.Value; str += strSave; str += "i"; str += (float)iBox.Value; str += strSave; str += "d"; str += (float)dBox.Value; Console.WriteLine(str); serialPort.Write(str); } } }
private void loadLastPIDs() { //check for settings on startup and load them if (File.Exists("currentData.xml")) { XmlSerializer reader = new XmlSerializer(typeof(CurrentData)); StreamReader file = new StreamReader("currentData.xml"); CurrentData readData = (CurrentData)reader.Deserialize(file); file.Close(); // Apperantly you can't copy an entire array when using two-dimentional arrays for (int i = 0; i < 3; i++) { PIDs[0, i] = readData.altPID[i]; PIDs[1, i] = readData.pitchPID[i]; PIDs[2, i] = readData.bankPID[i]; PIDs[3, i] = readData.speedPID[i]; PIDs[4, i] = readData.headingPID[i]; PIDs[5, i] = readData.runwayLineupPID[i]; } } }