diff --git a/Demo.WindowsForms/Forms/MainForm.cs b/Demo.WindowsForms/Forms/MainForm.cs --- a/Demo.WindowsForms/Forms/MainForm.cs +++ b/Demo.WindowsForms/Forms/MainForm.cs @@ -1265,39 +1265,6 @@ namespace Demo.WindowsForms objects.Markers.Add(m); } - int comPort = 0; - string callsign; - private void cboxCollectData_Click(object sender, EventArgs e) - { - //sets comPort and callsign, uncheck if parse does not work - if (int.TryParse(tboxCOMPort.Text, out comPort)) - { - callsign = tboxAPRSCallsign.Text; - } - else - { - cboxCollectData.Checked = false; - } - - //disable callsign and port edits while collecting transmissions - tboxAPRSCallsign.Enabled = !cboxCollectData.Checked; - tboxCOMPort.Enabled = !cboxCollectData.Checked; - } - - //sets and opens the COM port - delegate void SetSerialDelegate(int COM); - public void setSerialPort(int COM) - { - if (InvokeRequired) - { - Invoke(new SetSerialDelegate(setSerialPort), COM); - } - else - { - - } - } - //places text in the message box delegate void SetTextDelegate(string value); public void AddTextDelegate(string value) @@ -1702,6 +1669,70 @@ namespace Demo.WindowsForms #endregion + public SerialPort port;// = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One); + int comPort = 0; + string callsign; + + //click event for Collect Data checkbox + private void cboxCollectData_Click(object sender, EventArgs e) + { + //sets comPort and callsign, uncheck if parse does not work + if (int.TryParse(tboxCOMPort.Text, out comPort)) + { + callsign = tboxAPRSCallsign.Text; + if (cboxCollectData.Checked) + { + port = new SerialPort("COM" + comPort, 9600, Parity.None, 8, StopBits.One); + SerialInitialize(); + } + else + { + port.Close(); + } + + } + else + { + cboxCollectData.Checked = false; + } + + //disable callsign and port edits while collecting transmissions + tboxAPRSCallsign.Enabled = !cboxCollectData.Checked; + tboxCOMPort.Enabled = !cboxCollectData.Checked; + } + + //inits the serial port and event handler + public void SerialInitialize() + { + // http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx + // Attach a method to be called when there is data waiting in the port's buffer + port.DataReceived += new SerialDataReceivedEventHandler(ReceiveData); + + // Open the port for communications + port.Open(); + } + + //process received data + public void ReceiveData(object sender, SerialDataReceivedEventArgs e) + { + // Show all the incoming data in the port's buffer + string testChk = port.ReadLine(); + ParseIncomingData(testChk); + } + + //sets and opens the COM port + delegate void SetSerialDelegate(int COM); + public void setSerialPort(int COM) + { + if (InvokeRequired) + { + Invoke(new SetSerialDelegate(setSerialPort), COM); + } + else + { + + } + } } } diff --git a/Demo.WindowsForms/Source/Program.cs b/Demo.WindowsForms/Source/Program.cs --- a/Demo.WindowsForms/Source/Program.cs +++ b/Demo.WindowsForms/Source/Program.cs @@ -20,7 +20,6 @@ namespace Demo.WindowsForms /// /// // Instantiate the communications port - public SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One); static MainForm windowGUI; [STAThread] @@ -29,31 +28,11 @@ namespace Demo.WindowsForms Application.SetCompatibleTextRenderingDefault(false); var program = new Program(); windowGUI = new MainForm(); - program.SerialInitialize(); Application.EnableVisualStyles(); Application.Run(windowGUI); } - //inits the serial port and event handler - public void SerialInitialize() - { - // http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx - // Attach a method to be called when there is data waiting in the port's buffer - port.DataReceived += new SerialDataReceivedEventHandler(ReceiveData); - - // Open the port for communications - port.Open(); - - } - - //process received data - public void ReceiveData(object sender, SerialDataReceivedEventArgs e) - { - // Show all the incoming data in the port's buffer - string testChk = port.ReadLine(); - windowGUI.ParseIncomingData(testChk); - } } //public class Dummy diff --git a/update.bat b/update.bat new file mode 100644 --- /dev/null +++ b/update.bat @@ -0,0 +1,1 @@ +hg pull -u \ No newline at end of file