private static void WriteSerial(int port, string msg) { try { if (port == 1) { SerialPort1.WriteLine(msg); } if (port == 2) { SerialPort2.WriteLine(msg); } if (port == 3) { SerialPort3.WriteLine(msg); } if (port == 4) { SerialPort4.WriteLine(msg); } } catch { MarkErrorOnNMEA(port, "Cannot TX sentence"); } }
public void InitializeSerialPort4() { try { SerialPort4.PortName = Properties.Settings.Default.Port4; } catch (ArgumentException) { } SerialPort4.BaudRate = 4800; SerialPort4.Parity = Parity.None; SerialPort4.DataBits = 8; SerialPort4.StopBits = StopBits.One; SerialPort4.Handshake = Handshake.None; SerialPort4.RtsEnable = true; SerialPort4.ReadTimeout = 2000; SerialPort4.WriteTimeout = 2000; try { SerialPort4.Open(); } catch (Exception) { } }
public static void ReadSerial4() { string message = ""; while (!terminateThread4) { if (SerialPort4.IsOpen) { try { message = SerialPort4.ReadLine(); } catch (Exception) { message = ""; } ProcessNMEA(message, 3); } else { Thread.Sleep(1000); } } }
public void BuildNMEASentences() { string message; // #CommRework - All primitive NMEA sentences are relayed inmeditely //// Build HDG Sentence **************************************************************************************** //if (HDT.IsValid()) // Implies MVAR is valid too //{ // string mv; // if (MVAR.Val > 0) // mv = "E"; // else // mv = "W"; // double hdg = (HDT.Val - MVAR.Val + 360) % 360; // message = "IIHDG," + hdg.ToString("0.#") + ",,," + Math.Abs(MVAR.Val).ToString("0.#") + "," + mv; // int checksum = 0; // foreach (char c in message) // checksum ^= Convert.ToByte(c); // message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; // if (Properties.Settings.Default.HeadingSentence.OutPort1) // if (SerialPort1.IsOpen) // WriteSerial(1,message); // if (Properties.Settings.Default.HeadingSentence.OutPort2) // if (SerialPort2.IsOpen) // WriteSerial(2,message); // if (Properties.Settings.Default.HeadingSentence.OutPort3) // if (SerialPort3.IsOpen) // WriteSerial(3,message); // if (Properties.Settings.Default.HeadingSentence.OutPort4) // if (SerialPort4.IsOpen) // WriteSerial(4,message); //} //// Build MWV Sentence **************************************************************************************** //if (AWA.IsValid()) //{ // message = "IIMWV," + ((AWA.Val+360)%360).ToString("0") + ",R," + AWS.Val.ToString("0.#") + ",N,A"; // int checksum = 0; // foreach (char c in message) // checksum ^= Convert.ToByte(c); // message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; // if (Properties.Settings.Default.AppWindSentence.OutPort1) // if(SerialPort1.IsOpen) // WriteSerial(1,message); // if (Properties.Settings.Default.AppWindSentence.OutPort2) // if (SerialPort2.IsOpen) // WriteSerial(2,message); // if (Properties.Settings.Default.AppWindSentence.OutPort3) // if (SerialPort3.IsOpen) // WriteSerial(3,message); // if (Properties.Settings.Default.AppWindSentence.OutPort4) // if (SerialPort4.IsOpen) // WriteSerial(4,message); //} //// Build VHW Sentence **************************************************************************************** //if (SPD.IsValid()) //{ // string hdg; // if (HDT.IsValid()) // hdg = HDT.Val.ToString("0") + ",T,,M,"; // else // hdg = ",T,,M,"; // message = "IIVHW," + hdg + SPD.Val.ToString("0.##") + ",N,,K"; // int checksum = 0; // foreach (char c in message) // checksum ^= Convert.ToByte(c); // message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; // if (Properties.Settings.Default.HullSpeedSentence.OutPort1) // if (SerialPort1.IsOpen) // WriteSerial(1,message); // if (Properties.Settings.Default.HullSpeedSentence.OutPort2) // if (SerialPort2.IsOpen) // WriteSerial(2,message); // if (Properties.Settings.Default.HullSpeedSentence.OutPort3) // if (SerialPort3.IsOpen) // WriteSerial(3,message); // if (Properties.Settings.Default.HullSpeedSentence.OutPort4) // if (SerialPort4.IsOpen) // WriteSerial(4,message); //} //// Build DPT Sentence **************************************************************************************** //if (DPT.IsValid()) //{ // message = "IIDPT,"+DPT.Val.ToString("0.#")+",0"; // //message = "IIDPT,25.4,0"; // int checksum = 0; // foreach (char c in message) // checksum ^= Convert.ToByte(c); // message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; // if (Properties.Settings.Default.DepthSentence.OutPort1) // if (SerialPort1.IsOpen) // WriteSerial(1,message); // if (Properties.Settings.Default.DepthSentence.OutPort2) // if (SerialPort2.IsOpen) // WriteSerial(2,message); // if (Properties.Settings.Default.DepthSentence.OutPort3) // if (SerialPort3.IsOpen) // WriteSerial(3,message); // if (Properties.Settings.Default.DepthSentence.OutPort4) // if (SerialPort4.IsOpen) // WriteSerial(4,message); //} //// Build RMC Sentence **************************************************************************************** //if (COG.IsValid()) // Implies SOG, LAT and LON are also valid //{ // DateTime UTC = DateTime.UtcNow; // string hms = UTC.Hour.ToString("00") + UTC.Minute.ToString("00") + UTC.Second.ToString("00"); // string date = UTC.Date.Day.ToString("00") + UTC.Date.Month.ToString("00") + UTC.Date.Year.ToString().Substring(2, 2); // double deg, min; // string cd; // deg = Math.Abs(Math.Truncate(LAT.Val)); // min = (Math.Abs(LAT.Val) - deg) * 60; // if (LAT.Val > 0) // cd = "N"; // else // cd = "S"; // string lat = deg.ToString("#")+min.ToString("00.####")+","+cd; // deg = Math.Abs(Math.Truncate(LON.Val)); // min = (Math.Abs(LON.Val) - deg) * 60; // if (LON.Val > 0) // cd = "E"; // else // cd = "W"; // string lon = deg.ToString("#")+min.ToString("00.####")+","+cd; // if (MVAR.Val > 0) // cd = "E"; // else // cd = "W"; // double cog = (COG.Val + 360) % 360; // message = "IIRMC," + hms + ",A," + lat + "," + lon + "," + SOG.Val.ToString("#.##") + "," + cog.ToString("0.#") + "," // + date + "," + Math.Abs(MVAR.Val).ToString("0.#") + "," + cd + ",A"; // int checksum = 0; // foreach (char c in message) // checksum ^= Convert.ToByte(c); // message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; // //message = "$GPRMC,173933,A,3430.6759,S,05828.3633,W,000.1,173.3,291220,008.1,W*68\r\n"; // if (Properties.Settings.Default.NavSentence.OutPort1) // if (SerialPort1.IsOpen) // WriteSerial(1,message); // if (Properties.Settings.Default.NavSentence.OutPort2) // if (SerialPort2.IsOpen) // WriteSerial(2,message); // if (Properties.Settings.Default.NavSentence.OutPort3) // if (SerialPort3.IsOpen) // WriteSerial(3,message); // if (Properties.Settings.Default.NavSentence.OutPort4) // if (SerialPort4.IsOpen) // WriteSerial(4,message); //} //// Build MTW Sentence **************************************************************************************** //if (TEMP.IsValid()) //{ // message = "IIMTW," + TEMP.Val.ToString("0.#") + ",C"; // int checksum = 0; // foreach (char c in message) // checksum ^= Convert.ToByte(c); // message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; // if (Properties.Settings.Default.WaterTempSentence.OutPort1) // if (SerialPort1.IsOpen) // WriteSerial(1,message); // if (Properties.Settings.Default.WaterTempSentence.OutPort2) // if (SerialPort2.IsOpen) // WriteSerial(2,message); // if (Properties.Settings.Default.WaterTempSentence.OutPort3) // if (SerialPort3.IsOpen) // WriteSerial(3,message); // if (Properties.Settings.Default.WaterTempSentence.OutPort4) // if (SerialPort4.IsOpen) // WriteSerial(4,message); //} // Build RMB Sentence **************************************************************************************** if (WPT.IsValid()) // Implies BRG and DST are also valid { string xte = ",,"; string owpt = ","; if (XTE.IsValid()) { if (XTE.Val > 0) { xte = XTE.Val.ToString("0.##") + ",R,"; } else { xte = Math.Abs(XTE.Val).ToString("0.##") + ",L,"; } owpt = LWPT.FormattedValue + ","; } double brg = (BRG.Val + 360) % 360; message = "IIRMB,A," + xte + owpt + WPT.FormattedValue + ",,,,," + DST.Val.ToString("0.##") + "," + brg.ToString("0.#") + "," + VMGWPT.Val.ToString("0.##") + ",,A"; int checksum = 0; foreach (char c in message) { checksum ^= Convert.ToByte(c); } message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; rmb_sentence = message; rmb_sentence_available = true; } // Build PTAK4 Sentence **************************************************************************************** if (LINEDST.IsValid()) { string message4; message4 = "PTAK,FFD4," + LINEDST.Val.ToString("0"); int checksum = 0; foreach (char c in message4) { checksum ^= Convert.ToByte(c); } message4 = "$" + message4 + "*" + checksum.ToString("X2") + "\r\n"; if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort1) { if (SerialPort1.IsOpen) { SerialPort1.WriteLine(message4); } } if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort2) { if (SerialPort2.IsOpen) { SerialPort2.WriteLine(message4); } } if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort3) { if (SerialPort3.IsOpen) { SerialPort3.WriteLine(message4); } } if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort4) { if (SerialPort4.IsOpen) { SerialPort4.WriteLine(message4); } } } }
public void CloseSerialPort4() { terminateThread4 = true; readThread4.Join(); SerialPort4.Close(); }
public void SendPerformanceNMEA() { // Build PTAK Sentence **************************************************************************************** if (PERF.IsValid()) { string message1, message2, message3, message5, message6; message1 = "PTAK,FFD1," + TGTSPD.Average(Inst.BufFiveSec).ToString("0.0"); message2 = "PTAK,FFD2," + TGTTWA.Average(Inst.BufFiveSec).ToString("0") + "@"; double pf = PERF.Average(Inst.BufFiveSec) * 100; message3 = "PTAK,FFD3," + pf.ToString("0"); //message5 = "PTAK,FFD5," + TGTVMC.Average(Inst.BufFiveSec).ToString("0.0"); message5 = "PTAK,FFD5," + NTWA.FormattedValue + "@"; message6 = "PTAK,FFD6," + TGTCTS.Average(Inst.BufFiveSec).ToString("0") + "@"; int checksum = 0; checksum = 0; foreach (char c in message1) { checksum ^= Convert.ToByte(c); } message1 = "$" + message1 + "*" + checksum.ToString("X2") + "\r\n"; checksum = 0; foreach (char c in message2) { checksum ^= Convert.ToByte(c); } message2 = "$" + message2 + "*" + checksum.ToString("X2") + "\r\n"; checksum = 0; foreach (char c in message3) { checksum ^= Convert.ToByte(c); } message3 = "$" + message3 + "*" + checksum.ToString("X2") + "\r\n"; checksum = 0; foreach (char c in message5) { checksum ^= Convert.ToByte(c); } message5 = "$" + message5 + "*" + checksum.ToString("X2") + "\r\n"; checksum = 0; foreach (char c in message6) { checksum ^= Convert.ToByte(c); } message6 = "$" + message6 + "*" + checksum.ToString("X2") + "\r\n"; if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort1) { if (SerialPort1.IsOpen) { SerialPort1.WriteLine(message1); SerialPort1.WriteLine(message2); SerialPort1.WriteLine(message3); SerialPort1.WriteLine(message5); SerialPort1.WriteLine(message6); } } if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort2) { if (SerialPort2.IsOpen) { SerialPort2.WriteLine(message1); SerialPort2.WriteLine(message2); SerialPort2.WriteLine(message3); SerialPort2.WriteLine(message5); SerialPort2.WriteLine(message6); } } if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort3) { if (SerialPort3.IsOpen) { SerialPort3.WriteLine(message1); SerialPort3.WriteLine(message2); SerialPort3.WriteLine(message3); SerialPort3.WriteLine(message5); SerialPort3.WriteLine(message6); } } if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort4) { if (SerialPort4.IsOpen) { SerialPort4.WriteLine(message1); SerialPort4.WriteLine(message2); SerialPort4.WriteLine(message3); SerialPort4.WriteLine(message5); SerialPort4.WriteLine(message6); } } } }
public void SendNMEA() { string message; // Build HDG Sentence **************************************************************************************** if (HDT.IsValid()) // Implies MVAR is valid too { string mv; if (MVAR.Val > 0) { mv = "E"; } else { mv = "W"; } double hdg = (HDT.Val - MVAR.Val + 360) % 360; message = "IIHDG," + hdg.ToString("0.#") + ",,," + Math.Abs(MVAR.Val).ToString("0.#") + "," + mv; int checksum = 0; foreach (char c in message) { checksum ^= Convert.ToByte(c); } message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; if (Properties.Settings.Default.HeadingSentence.OutPort1) { if (SerialPort1.IsOpen) { SerialPort1.WriteLine(message); } } if (Properties.Settings.Default.HeadingSentence.OutPort2) { if (SerialPort2.IsOpen) { SerialPort2.WriteLine(message); } } if (Properties.Settings.Default.HeadingSentence.OutPort3) { if (SerialPort3.IsOpen) { SerialPort3.WriteLine(message); } } if (Properties.Settings.Default.HeadingSentence.OutPort4) { if (SerialPort4.IsOpen) { SerialPort4.WriteLine(message); } } } // Build MWV Sentence **************************************************************************************** if (AWA.IsValid()) { message = "IIMWV," + ((AWA.Val + 360) % 360).ToString("0") + ",R," + AWS.Val.ToString("0.#") + ",N,A"; int checksum = 0; foreach (char c in message) { checksum ^= Convert.ToByte(c); } message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; if (Properties.Settings.Default.AppWindSentence.OutPort1) { if (SerialPort1.IsOpen) { SerialPort1.WriteLine(message); } } if (Properties.Settings.Default.AppWindSentence.OutPort2) { if (SerialPort2.IsOpen) { SerialPort2.WriteLine(message); } } if (Properties.Settings.Default.AppWindSentence.OutPort3) { if (SerialPort3.IsOpen) { SerialPort3.WriteLine(message); } } if (Properties.Settings.Default.AppWindSentence.OutPort4) { if (SerialPort4.IsOpen) { SerialPort4.WriteLine(message); } } } // Build VHW Sentence **************************************************************************************** if (SPD.IsValid()) { string hdg; if (HDT.IsValid()) { hdg = HDT.Val.ToString("0") + ",T,,M,"; } else { hdg = ",T,,M,"; } message = "IIVHW," + hdg + SPD.Val.ToString("0.##") + ",N,,K"; int checksum = 0; foreach (char c in message) { checksum ^= Convert.ToByte(c); } message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; if (Properties.Settings.Default.HullSpeedSentence.OutPort1) { if (SerialPort1.IsOpen) { SerialPort1.WriteLine(message); } } if (Properties.Settings.Default.HullSpeedSentence.OutPort2) { if (SerialPort2.IsOpen) { SerialPort2.WriteLine(message); } } if (Properties.Settings.Default.HullSpeedSentence.OutPort3) { if (SerialPort3.IsOpen) { SerialPort3.WriteLine(message); } } if (Properties.Settings.Default.HullSpeedSentence.OutPort4) { if (SerialPort4.IsOpen) { SerialPort4.WriteLine(message); } } } // Build DPT Sentence **************************************************************************************** if (DPT.IsValid()) { message = "IIDPT," + DPT.Val.ToString("0.#") + ",0"; int checksum = 0; foreach (char c in message) { checksum ^= Convert.ToByte(c); } message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; if (Properties.Settings.Default.DepthSentence.OutPort1) { if (SerialPort1.IsOpen) { SerialPort1.WriteLine(message); } } if (Properties.Settings.Default.DepthSentence.OutPort2) { if (SerialPort2.IsOpen) { SerialPort2.WriteLine(message); } } if (Properties.Settings.Default.DepthSentence.OutPort3) { if (SerialPort3.IsOpen) { SerialPort3.WriteLine(message); } } if (Properties.Settings.Default.DepthSentence.OutPort4) { if (SerialPort4.IsOpen) { SerialPort4.WriteLine(message); } } } // Build RMC Sentence **************************************************************************************** if (COG.IsValid()) // Implies SOG, LAT and LON are also valid { DateTime UTC = DateTime.UtcNow; string hms = UTC.Hour.ToString("00") + UTC.Minute.ToString("00") + UTC.Second.ToString("00"); string date = UTC.Date.Day.ToString("00") + UTC.Date.Month.ToString("00") + UTC.Date.Year.ToString().Substring(2, 2); double deg, min; string cd; deg = Math.Abs(Math.Truncate(LAT.Val)); min = (Math.Abs(LAT.Val) - deg) * 60; if (LAT.Val > 0) { cd = "N"; } else { cd = "S"; } string lat = deg.ToString("000") + min.ToString("00.###") + "," + cd; deg = Math.Abs(Math.Truncate(LON.Val)); min = (Math.Abs(LON.Val) - deg) * 60; if (LON.Val > 0) { cd = "E"; } else { cd = "W"; } string lon = deg.ToString("000") + min.ToString("00.###") + "," + cd; if (MVAR.Val > 0) { cd = "E"; } else { cd = "W"; } double cog = (COG.Val + 360) % 360; message = "IIRMC," + hms + ",A," + lat + "," + lon + "," + SOG.Val.ToString("#.##") + "," + cog.ToString("0.#") + "," + date + "," + Math.Abs(MVAR.Val).ToString("0.#") + "," + cd + ",A"; int checksum = 0; foreach (char c in message) { checksum ^= Convert.ToByte(c); } message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; if (Properties.Settings.Default.NavSentence.OutPort1) { if (SerialPort1.IsOpen) { SerialPort1.WriteLine(message); } } if (Properties.Settings.Default.NavSentence.OutPort2) { if (SerialPort2.IsOpen) { SerialPort2.WriteLine(message); } } if (Properties.Settings.Default.NavSentence.OutPort3) { if (SerialPort3.IsOpen) { SerialPort3.WriteLine(message); } } if (Properties.Settings.Default.NavSentence.OutPort4) { if (SerialPort4.IsOpen) { SerialPort4.WriteLine(message); } } } // Build RMB Sentence **************************************************************************************** if (WPT.IsValid()) // Implies BRG and DST are also valid { string xte = ",,"; string owpt = ","; if (XTE.IsValid()) { if (XTE.Val > 0) { xte = XTE.Val.ToString("0.##") + ",R,"; } else { xte = Math.Abs(XTE.Val).ToString("0.##") + ",L,"; } owpt = LWPT.FormattedValue + ","; } double brg = (BRG.Val + 360) % 360; message = "IIRMB,A," + xte + owpt + WPT.FormattedValue + ",,,,," + DST.Val.ToString("0.##") + "," + brg.ToString("0.#") + "," + VMGWPT.Val.ToString("0.##") + ",,A"; int checksum = 0; foreach (char c in message) { checksum ^= Convert.ToByte(c); } message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; if (Properties.Settings.Default.RouteSentence.OutPort1) { if (SerialPort1.IsOpen) { SerialPort1.WriteLine(message); } } if (Properties.Settings.Default.RouteSentence.OutPort2) { if (SerialPort2.IsOpen) { SerialPort2.WriteLine(message); } } if (Properties.Settings.Default.RouteSentence.OutPort3) { if (SerialPort3.IsOpen) { SerialPort3.WriteLine(message); } } if (Properties.Settings.Default.RouteSentence.OutPort4) { if (SerialPort4.IsOpen) { SerialPort4.WriteLine(message); } } } // Build MTW Sentence **************************************************************************************** if (TEMP.IsValid()) { message = "IIMTW," + TEMP.Val.ToString("0.#") + ",C"; int checksum = 0; foreach (char c in message) { checksum ^= Convert.ToByte(c); } message = "$" + message + "*" + checksum.ToString("X2") + "\r\n"; if (Properties.Settings.Default.WaterTempSentence.OutPort1) { if (SerialPort1.IsOpen) { SerialPort1.WriteLine(message); } } if (Properties.Settings.Default.WaterTempSentence.OutPort2) { if (SerialPort2.IsOpen) { SerialPort2.WriteLine(message); } } if (Properties.Settings.Default.WaterTempSentence.OutPort3) { if (SerialPort3.IsOpen) { SerialPort3.WriteLine(message); } } if (Properties.Settings.Default.WaterTempSentence.OutPort4) { if (SerialPort4.IsOpen) { SerialPort4.WriteLine(message); } } } // Build PTAK4 Sentence **************************************************************************************** if (LINEDST.IsValid()) { string message4; message4 = "PTAK,FFD4," + LINEDST.Val.ToString("0"); int checksum = 0; foreach (char c in message4) { checksum ^= Convert.ToByte(c); } message4 = "$" + message4 + "*" + checksum.ToString("X2") + "\r\n"; if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort1) { if (SerialPort1.IsOpen) { SerialPort1.WriteLine(message4); } } if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort2) { if (SerialPort2.IsOpen) { SerialPort2.WriteLine(message4); } } if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort3) { if (SerialPort3.IsOpen) { SerialPort3.WriteLine(message4); } } if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort4) { if (SerialPort4.IsOpen) { SerialPort4.WriteLine(message4); } } } }
public void SendPTAKheaders() { string message1, message2, message3, message4, message5, message6; message1 = "PTAK,FFP1,TgtSPD, KNOTS"; message2 = "PTAK,FFP2,TgtTWA, TRUE"; message3 = "PTAK,FFP3,Perf, %"; message4 = "PTAK,FFP4,Toline,METRES"; //message5 = "PTAK,FFP5,TgtVMC, KNOTS"; message5 = "PTAK,FFP5,NxtTWA, "; message6 = "PTAK,FFP6,TgtCTS, TRUE"; int checksum = 0; foreach (char c in message1) { checksum ^= Convert.ToByte(c); } message1 = "$" + message1 + "*" + checksum.ToString("X2") + "\r\n"; checksum = 0; foreach (char c in message2) { checksum ^= Convert.ToByte(c); } message2 = "$" + message2 + "*" + checksum.ToString("X2") + "\r\n"; checksum = 0; foreach (char c in message3) { checksum ^= Convert.ToByte(c); } message3 = "$" + message3 + "*" + checksum.ToString("X2") + "\r\n"; checksum = 0; foreach (char c in message4) { checksum ^= Convert.ToByte(c); } message4 = "$" + message4 + "*" + checksum.ToString("X2") + "\r\n"; checksum = 0; foreach (char c in message5) { checksum ^= Convert.ToByte(c); } message5 = "$" + message5 + "*" + checksum.ToString("X2") + "\r\n"; checksum = 0; foreach (char c in message6) { checksum ^= Convert.ToByte(c); } message6 = "$" + message6 + "*" + checksum.ToString("X2") + "\r\n"; if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort1) { if (SerialPort1.IsOpen) { SerialPort1.WriteLine(message1); SerialPort1.WriteLine(message2); SerialPort1.WriteLine(message3); SerialPort1.WriteLine(message4); SerialPort1.WriteLine(message5); SerialPort1.WriteLine(message6); } } if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort2) { if (SerialPort2.IsOpen) { SerialPort2.WriteLine(message1); SerialPort2.WriteLine(message2); SerialPort2.WriteLine(message3); SerialPort2.WriteLine(message4); SerialPort2.WriteLine(message5); SerialPort2.WriteLine(message6); } } if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort3) { if (SerialPort3.IsOpen) { SerialPort3.WriteLine(message1); SerialPort3.WriteLine(message2); SerialPort3.WriteLine(message3); SerialPort3.WriteLine(message4); SerialPort3.WriteLine(message5); SerialPort3.WriteLine(message6); } } if (Properties.Settings.Default.TacktickPerformanceSentence.OutPort4) { if (SerialPort4.IsOpen) { SerialPort4.WriteLine(message1); SerialPort4.WriteLine(message2); SerialPort4.WriteLine(message3); SerialPort4.WriteLine(message4); SerialPort4.WriteLine(message5); SerialPort4.WriteLine(message6); } } }