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
 
@@ -1220,129 +1220,96 @@ namespace Demo.WindowsForms
 
        {
 
            //TODO: add inserts for all charts. altitude is finished and is a template
 
            ///data types organized by listing in google doc
 
            //MASTER MODULE DATA VALUES
 
            ChartDelegate(dataType, data);
 
 
        }
 
 
        //write the data to CSV file -- usually seniordesign-ui\Demo.WindowsForms\bin\Debug
 
        private void WriteToCSV(string data)
 
        {
 
            string path = Directory.GetCurrentDirectory();
 
            string filename = path+"\\TransmissionData" + unixTime.Milliseconds + ".csv";
 
            using (StreamWriter writer = new StreamWriter(filename, true))
 
            {
 
                writer.WriteLine(data);
 
            }
 
        }
 
        
 
        //must change lat/long coords to properly place map marker
 
        float conv_coords(float in_coords)
 
        {
 
            //Initialize the location.
 
            float f = in_coords;
 
            // Get the first two digits by turning f into an integer, then doing an integer divide by 100;
 
            // firsttowdigits should be 77 at this point.
 
            int firsttwodigits = ((int)f) / 100;                               //This assumes that f < 10000.
 
            float nexttwodigits = f - (float)(firsttwodigits * 100);
 
            float theFinalAnswer = (float)(firsttwodigits + nexttwodigits / 60.0);
 
            return theFinalAnswer;
 
        }
 
 
        // add marker from an APRS transmission - MDKEdit
 
        private void addTrackerMarker(string lat, string lng)
 
        {
 
 
            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();
 
            }
 
        }
 
 
        //this is where most of the transmission processing is done
 
        delegate void ChartDataDelegate(string dataType, string data);
 
        public void ChartDelegate(string dataType, string data)
 
        {
 
            if (InvokeRequired)
 
            {
 
                Invoke(new ChartDataDelegate(ChartDelegate), dataType, data);
 
            }
 
            else
 
            {
 
                if (firstTransmissionDatum)
 
                {
 
                    ClearTboxColor();
 
                }
 
                ///UNIVERSAL DATA TYPES
 
                if (dataType.Equals("t"))  //board temperature
 
                {
 
                    string dataString = data.ToString();
 
                    if (dataString.StartsWith("9")) //Master Module
 
                    {
 
                        tboxMasterBoardTemp.Text = dataString.Substring(1);
 
                        tboxMasterBoardTemp.BackColor = Color.Chartreuse;
 
                    }
 
                    else if (dataString.StartsWith("0")) //Atmo Module
 
                    {
 
                        tboxAtmoBoardTemp.Text = dataString.Substring(1);
 
                        tboxAtmoBoardTemp.BackColor = Color.Chartreuse;
 
                    }
 
                    else if (dataString.StartsWith("1")) //Geiger Module
 
                    {
 
                        tboxGeigerBoardTemp.Text = dataString.Substring(1);
 
                        tboxGeigerBoardTemp.BackColor = Color.Chartreuse;
 
                    }
 
@@ -1657,53 +1624,117 @@ namespace Demo.WindowsForms
 
                    ParseIncomingData(testData);
 
                    break;
 
                case 39:
 
                    testData = "KD8TDF-11>APRS,WIDE2-1:/051950z3913.22N/08334.46WO163.22/57.953 ~v57.953~_077~|680~t915~s09~h0.89~t011~l056~t16~l10~P40480~C0~H999~A23294";
 
                    ParseIncomingData(testData);
 
                    break;
 
                case 40:
 
                    testData = "KD8TDF-11>APRS,WIDE2-1:/051951z3912.62N/08334.20WO162.48/62.928 ~v62.928~_018~|886";
 
                    ParseIncomingData(testData);
 
                    break;
 
                case 41:
 
                    testData = "KD8TDF-11>APRS,WIDE2-1:/051952z3912.09N/08333.98WO158.93/62.192 ~v62.192~_550~|711~t913~s09~h0.90~t010~l056~t14~l10~P43509~C0~H999~A21607";
 
                    ParseIncomingData(testData);
 
                    break;
 
                case 42:
 
                    testData = "KD8TDF-11>APRS,WIDE2-1:/051952z3911.55N/08333.74WO160.42/53.084 ~v53.084~_827~|212";
 
                    ParseIncomingData(testData);
 
                    break;
 
                case 43:
 
                    testData = "KD8TDF-11>APRS,WIDE2-1:/051953z3911.02N/08333.46WO157.50/60.661 ~v60.661~_647~|296~t913~s09~h0.90~t010~l056~t12~l10~P46544~C0~H999~A20007";
 
                    ParseIncomingData(testData);
 
                    break;
 
                case 44:
 
                    testData = "KD8TDF-11>APRS,WIDE2-1:/051953z3910.49N/08333.21WO150.50/52.105 ~v52.105~_520~|688";
 
                    ParseIncomingData(testData);
 
                    break;
 
                case 45:
 
                    testData = "KD8TDF-11>APRS,WIDE2-1:/051954z3910.04N/08332.97WO146.63/42.412 ~v42.412~_652~|898~t911~s09~h0.99~t010~l056~t12~l10~P49829~C0~H999~A18370";
 
                    ParseIncomingData(testData);
 
                    break;
 
                case 46:
 
                    testData = "KD8TDF-11>APRS,WIDE2-1:/051955z3909.67N/08332.70WO147.20/47.361 ~v47.361~_446~|617";
 
                    ParseIncomingData(testData);
 
                    break;
 
                default:
 
                    break;
 
            }
 
            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
 
using System;
 
using System.Collections;
 
using System.Collections.Generic;
 
using System.Diagnostics;
 
using System.Net;
 
using System.Net.NetworkInformation;
 
using System.Runtime.InteropServices;
 
using System.Text;
 
using System.Windows.Forms;
 
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;
 
        //public string ProcessName;
 
 
        public string CountryName;
 
        public string RegionName;
 
        public string City;
 
        public double Latitude;
 
        public double Longitude;
 
        public DateTime CacheTime;
 
 
        //public DateTime StatusTime;
 
        //public bool TracePoint;
 
    }
 
 
    struct IpStatus
 
    {
 
        private string countryName;
 
        public string CountryName
 
        {
 
            get
 
            {
 
                return countryName;
 
            }
 
            set
 
            {
 
                countryName = value;
 
            }
 
        }
 
 
        private int connectionsCount;
 
        public int ConnectionsCount
 
        {
 
            get
 
            {
 
                return connectionsCount;
 
            }
 
            set
update.bat
Show inline comments
 
new file 100644
 
hg pull -u
 
\ No newline at end of file
0 comments (0 inline, 0 general)