/// Continously loops and reads data from the FCU serial port, and /// then send status and data updates CSS_Writer_List. private void FCU_Reader() { Console.WriteLine("FCU Reader Initialized"); main_controls.CSS_Writer_List.Add("S" + (char)Communication_Constants.OC_OFC_C.Length + Communication_Constants.OC_OFC_C); main_controls.CSS_Writer_List.Add("S" + (char)Communication_Constants.OC_OBC_C.Length + Communication_Constants.OC_OBC_C); main_controls.CSS_Writer_List.Add("S" + (char)Communication_Constants.OC_OVC_C.Length + Communication_Constants.OC_OVC_C); main_controls.CSS_Writer_List.Add("S" + (char)Communication_Constants.OC_PFC_C.Length + Communication_Constants.OC_PFC_C); main_controls.CSS_Writer_List.Add("S" + (char)Communication_Constants.OC_PBC_C.Length + Communication_Constants.OC_PBC_C); DateTime earlier = DateTime.UtcNow; while (true) { while (((DateTime.UtcNow - earlier).TotalMilliseconds) < FCU_interval) { } earlier = DateTime.UtcNow; ArrayList list = new ArrayList(main_controls.FCU_List); main_controls.FCU_List.Clear(); if (list.Count != 0) { foreach (String i in list) { String FCU_status = FCU_Writer(i); Process_FCU(FCU_status); } } try { //Reads N2O Fuel Data Byte[] s = System.Text.Encoding.ASCII.GetBytes(Communication_Constants.OFC_FuelN2O); FCU.Write(s, 0, s.Length); int count = FCU.BytesToRead; while (count < 4 && (DateTime.UtcNow - earlier).TotalMilliseconds < 1000) { count = FCU.BytesToRead; } byte[] ByteArray = new byte[count]; FCU.Read(ByteArray, 0, count); if (ByteArray[0] == Communication_Constants.FCO_FuelN2O[0] && count >= 4) { int b = (ByteArray[1] << 16) + (ByteArray[2] << 8) + (ByteArray[3]); main_controls.D_FuelN2O = main_controls.RawData_Converter(b, 20); } else { Console.WriteLine("Lack Of Bytes for N20 Fuel Data"); } ////Reads N2 Ground Tank Data Byte[] z = System.Text.Encoding.ASCII.GetBytes(Communication_Constants.OFC_N2); FCU.Write(z, 0, z.Length); count = FCU.BytesToRead; while (count < 4 && (DateTime.UtcNow - earlier).TotalMilliseconds < 1000) { count = FCU.BytesToRead; } byte[] ByteArray1 = new byte[count]; FCU.Read(ByteArray1, 0, count); if (ByteArray1[0] == Communication_Constants.FCO_N2[0] && count >= 4) { int b = (ByteArray1[1] << 16) + (ByteArray1[2] << 8) + (ByteArray1[3]); main_controls.D_N2 = main_controls.RawData_Converter(b, 21); } else { Console.WriteLine("Lack Of Bytes for N2 Ground Tank Data"); } ////Reads Rocket Mass Byte[] x = System.Text.Encoding.ASCII.GetBytes(Communication_Constants.OFC_RocketMass); FCU.Write(x, 0, x.Length); count = FCU.BytesToRead; while (count < 4 && (DateTime.UtcNow - earlier).TotalMilliseconds < 1000) { count = FCU.BytesToRead; } byte[] ByteArray2 = new byte[count]; FCU.Read(ByteArray2, 0, count); if (ByteArray2[0] == Communication_Constants.FCO_RocketMass[0] && count >= 4) { int b = (ByteArray2[1] << 16) + (ByteArray2[2] << 8) + (ByteArray2[3]); main_controls.D_RocketMass = main_controls.RawData_Converter(b, 22); } else { Console.WriteLine("Lack Of Bytes for Rocket Mass"); } ////Reads Rocket Thrust Byte[] c = System.Text.Encoding.ASCII.GetBytes(Communication_Constants.OFC_RocketThrust); FCU.Write(c, 0, c.Length); count = FCU.BytesToRead; while (count < 4 && (DateTime.UtcNow - earlier).TotalMilliseconds < 1000) { count = FCU.BytesToRead; } byte[] ByteArray3 = new byte[count]; FCU.Read(ByteArray3, 0, count); if (ByteArray3[0] == Communication_Constants.FCO_RocketThrust[0] && count >= 4) { int b = (ByteArray3[1] << 16) + (ByteArray3[2] << 8) + (ByteArray3[3]); main_controls.D_RocketThrust = main_controls.RawData_Converter(b, 23); } else { Console.WriteLine("Lack Of Bytes for Rocket Thrust"); } } catch (Exception e) { Console.WriteLine(e + "" + FCU.IsOpen); if (FCU.IsOpen == false) { main_controls.CSS_Writer_List.Add("S" + (char)"FCUD".Length + "FCUD"); FCU.Close(); main_controls.FCU_PORT = ""; FCU = null; c.Abort(); } } } }
/// Continously loops and reads data from the FStarter serial port, and /// then send status and data updates to CSS_Writer_List. private void FStarter_Reader() { Console.WriteLine("FireStarter Reader Initialized"); DateTime earlier = DateTime.UtcNow; while (true) { while (((DateTime.UtcNow - earlier).TotalMilliseconds) < FS_interval) { } //Console.WriteLine((DateTime.UtcNow - earlier).TotalMilliseconds); earlier = DateTime.UtcNow; ArrayList list = new ArrayList(main_controls.FS_List); main_controls.FS_List.Clear(); //Processes the ArrayList and uses the FStarter_Writer to send the command //and receive a status, which will be then be processed by Process_FS. if (list.Count != 0) { foreach (String i in list) { if (Communication_Constants.OF_Stop_BF == i || Communication_Constants.OF_Start_BF == i) { try { Byte[] bfa = System.Text.Encoding.ASCII.GetBytes(i); FStarter.Write(bfa, 0, bfa.Length); } catch { } } else { String FO_status = FStarter_Writer(i); Process_FS(FO_status); } } } #region "Automatic Status Checks" //Automatic status checks. //String FO_status1 = FStarter_Writer(OF_Chamber_Check); //if (Chamber_Check != FO_status1) //{ // Process_FS(FO_status1); // Chamber_Check = FO_status1; //} //String FO_status2 = FStarter_Writer(OF_Ignite_C); //if (Ignitor_Check != FO_status2) //{ // Process_FS(FO_status2); // Ignitor_Check = FO_status2; //} //String FO_status3 = FStarter_Writer(OF_E_Reg_Check); //if (E_Regualator_Check != FO_status3) //{ // Process_FS(FO_status3); // E_Regualator_Check = FO_status3; //} #endregion try { //Reads Oxidizer Pressure Data Byte[] x = System.Text.Encoding.ASCII.GetBytes(Communication_Constants.OF_Oxidizer_P); FStarter.Write(x, 0, x.Length); int count = FStarter.BytesToRead; while (count < 4 && (DateTime.UtcNow - earlier).TotalMilliseconds < 500) { count = FStarter.BytesToRead; } byte[] ByteArray = new byte[count]; FStarter.Read(ByteArray, 0, count); //If the first byte is equal to O, then next three bytes are converted and then converted to //PSI using RawData_Converter. if (ByteArray[0] == Communication_Constants.FO_Oxidizer_P[0] && count >= 4) { int b = (ByteArray[1] << 16) + (ByteArray[2] << 8) + (ByteArray[3]); main_controls.D_Oxidizer_P = main_controls.RawData_Converter(b, 10); } else { Console.WriteLine("Lack Of Bytes for Oxidizer Pressure"); } //Reads Presurant Pressure Data Byte[] z = System.Text.Encoding.ASCII.GetBytes(Communication_Constants.OF_Pessurant_P); FStarter.Write(z, 0, z.Length); count = FStarter.BytesToRead; while (count < 4 && (DateTime.UtcNow - earlier).TotalMilliseconds < 500) { count = FStarter.BytesToRead; } byte[] ByteArray1 = new byte[count]; FStarter.Read(ByteArray1, 0, count); if (ByteArray1[0] == Communication_Constants.FO_Pessurant_P[0] && count >= 4) { int b = (ByteArray1[1] << 16) + (ByteArray1[2] << 8) + (ByteArray1[3]); main_controls.D_Pressurant_P = main_controls.RawData_Converter(b, 11); } else { Console.WriteLine("Lack Of Bytes for Pressurant Pressure"); } } catch (Exception e) { //If the serial port loses connection, the port is closed and then the thread. Console.WriteLine(e + "" + FStarter.IsOpen); if (FStarter.IsOpen == false) { main_controls.CSS_Writer_List.Add("S" + (char)"FSD".Length + "FSD"); FStarter.Close(); main_controls.FS_PORT = ""; FStarter = null; f.Abort(); } } } }