Changeset - e2a1895cae7c
[Not reviewed]
default
0 2 1
mkanning@CL-ENS241-10.cedarville.edu - 13 years ago 2013-04-15 15:44:25
mkanning@CL-ENS241-10.cedarville.edu
dynamic COM ports!
3 files changed with 65 insertions and 54 deletions:
0 comments (0 inline, 0 general)
Demo.WindowsForms/Forms/MainForm.cs
Show inline comments
 
@@ -1256,57 +1256,24 @@ namespace Demo.WindowsForms
 
            double latitude = double.Parse(lat), longitude = double.Parse(lng);
 
            PointLatLng APRSloc = new PointLatLng();
 
            APRSloc.Lat = conv_coords((float)latitude);
 
            APRSloc.Lng = conv_coords((float)longitude)*-1;
 
 
            GMarkerGoogle m = new GMarkerGoogle(APRSloc, GMarkerGoogleType.blue_small);
 
 
            m.ToolTipText = "Tracker";
 
            m.ToolTipMode = MarkerTooltipMode.OnMouseOver;
 
            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)
 
        {
 
            if (InvokeRequired)
 
            {
 
                Invoke(new SetTextDelegate(AddTextDelegate), value);
 
            }
 
            else
 
            {
 
                tboxMessageBox.AppendText(value);// += value;
 
                textBoxMarkerCount.Text = objects.Markers.Count.ToString();
 
@@ -1693,17 +1660,81 @@ namespace Demo.WindowsForms
 
            }
 
            testIteration++;
 
        }
 
 
        public double GetRandomNumber(double minimum, double maximum)
 
        {
 
            Random random = new Random();
 
            return random.NextDouble() * (maximum - minimum) + minimum;
 
        }
 
 
        #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
 
            {
 
 
            }
 
        }
 
 
    }
 
}
 
 
                  
 
\ No newline at end of file
Demo.WindowsForms/Source/Program.cs
Show inline comments
 
@@ -11,58 +11,37 @@ using System.IO;
 
using System.IO.Ports;
 
using System.Threading;
 
 
namespace Demo.WindowsForms
 
{
 
    class Program
 
    {
 
        /// <summary>
 
        /// The main entry point for the application.
 
        /// </summary>
 
        /// 
 
        // Instantiate the communications port 
 
        public SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
 
        static MainForm windowGUI;
 
 
        [STAThread]
 
        static void Main()
 
        {
 
            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
 
    //{
 
 
    //} - removed 4-15
 
 
    class IpInfo
 
    {
 
        public string Ip;
 
        //public int Port;
 
        //public TcpState State;
update.bat
Show inline comments
 
new file 100644
 
hg pull -u
 
\ No newline at end of file
0 comments (0 inline, 0 general)