//Test reading barometer.
        public static void Main44()
        {
            double baseAltitudeFeet = 0.0;
            int counter2 = 0;

            double alpha = .15;

            double previousAltitudeFeet = 0.0;
            bool isReady = false;

            SerialPort port = new SerialPort("COM7", 9600, Parity.None, 8, StopBits.One);
            SerialPortInterface portInterface = new SerialPortInterface(port);
            portInterface.Open();

            GraphForm rawTemp = new GraphForm("RawTemp");
            GraphForm rawPress = new GraphForm("RawPress");
            GraphForm temp = new GraphForm("Temp");
            GraphForm press = new GraphForm("Pressure");
            GraphForm alt = new GraphForm("altitude");

            rawTemp.Visible = true;
            rawPress.Visible = true;
            temp.Visible = true;
            press.Visible = true;
            alt.Visible = true;

            while (true)
            {
                int var = 0;
                while (var != 'S')
                {
                    var = portInterface.ReadByte();
                }
                uint rwTemp = portInterface.ReadUInt();
                rawTemp.AddValueToGraph(rwTemp);

                uint rwPress = portInterface.ReadUInt();
                rawPress.AddValueToGraph(rwPress);
                int temperature = portInterface.ReadInt();
                temp.AddValueToGraph(temperature);
                int pressure = portInterface.ReadInt();
                //press.AddValueToGraph(pressure);

                float pressure2 = portInterface.ReadFloat();
                //press.AddValueToGraph(pressure2);

                float zned = portInterface.ReadFloat();
                press.AddValueToGraph(zned);

                Application.DoEvents();

                //altitude equation from: http://www.barnardmicrosystems.com/L4E_FMU_sensors.htm#Pressure
                double altitudemeters = (288.15 / (6.5 / 1000.0)) * (1 - (Math.Pow((pressure / 101325.0), (6.5 / 1000.0) * (287.052 / 9.78))));
                double altitudefeet = altitudemeters * 3.28084;

                //*******note the barometer appears to need more time to settle
                if (counter2 == 40)
                {
                    baseAltitudeFeet = altitudefeet;
                    counter2 = 80;
                }
                else if (counter2 == 80)
                {
                    //do nothing
                }
                else
                {
                    counter2++;
                }

                if (isReady)
                {
                    //Danger *** This algorithm drifts. Sometimes it takes like 10 seconds
                    //or more to stabalize. So you have to wait a long time before you should
                    //read the altitude and set it as the base altitude because of how long it takes.
                    //Also, as the barometer heats up, the altitude changes. This isn't good as the barometer's
                    //temperature will probably change throughout the flight
                    double altitudefeettemp = (double)(altitudefeet - baseAltitudeFeet);
                    altitudefeet = alpha * (altitudefeettemp) + (1 - alpha) * previousAltitudeFeet;
                    previousAltitudeFeet = altitudefeet;

                    alt.AddValueToGraph(altitudefeet);
                }
                else
                {
                    altitudefeet = (double)(altitudefeet - baseAltitudeFeet);
                }

                if (altitudefeet < 20 && altitudefeet != 0)
                {
                    isReady = true;
                }

            }
        }
        //public static void Main()
        public static void Main2()
        {
            SerialPort port = new SerialPort("COM7", 115200, Parity.None, 8, StopBits.One);
            SerialPortInterface portInterface = new SerialPortInterface(port);
            portInterface.Open();

            GraphForm yawG = new GraphForm("yaw");
            GraphForm pitchG = new GraphForm("pitch");
            GraphForm rollG = new GraphForm("roll");
            GraphForm lax = new GraphForm("lax");
            GraphForm lay = new GraphForm("lay");
            GraphForm laz = new GraphForm("laz");
            GraphForm velX = new GraphForm("velX");
            yawG.Visible = true;
            pitchG.Visible = true;
            rollG.Visible = true;
            lax.Visible = true;
            lay.Visible = true;
            laz.Visible = true;
            velX.Visible = true;

            /*
            GraphForm accxg = new GraphForm("accx");
            GraphForm accyg = new GraphForm("accy");
            GraphForm acczg = new GraphForm("accz");
            GraphForm gyroxg = new GraphForm("gyrox");
            GraphForm gyroyg = new GraphForm("gyroy");
            GraphForm gyrozg = new GraphForm("gyroz");
            GraphForm magxg = new GraphForm("magx");
            GraphForm magyg = new GraphForm("magy");
            GraphForm magzg = new GraphForm("magz");
            accxg.Visible = true;
            accyg.Visible = true;
            acczg.Visible = true;
            gyroxg.Visible = true;
            gyroyg.Visible = true;
            gyrozg.Visible = true;
            magxg.Visible = true;
            magyg.Visible = true;
            magzg.Visible = true;
            */

            port.DiscardInBuffer();
            while (true)
            {
                while (portInterface.ReadByte() != 'S')
                {

                }

                float yaw = portInterface.ReadFloat() * (float)(180.0f / Math.PI);
                float pitch = portInterface.ReadFloat() * (float)(180.0f / Math.PI);
                float roll = portInterface.ReadFloat() * (float)(180.0f / Math.PI);
                float lineX = portInterface.ReadFloat();
                float lineY = portInterface.ReadFloat();
                float lineZ = portInterface.ReadFloat();
                float velocityX = portInterface.ReadFloat();
                yawG.AddValueToGraph(yaw);
                pitchG.AddValueToGraph(pitch);
                rollG.AddValueToGraph(roll);
                lax.AddValueToGraph(lineX);
                lay.AddValueToGraph(lineY);
                laz.AddValueToGraph(lineZ);
                velX.AddValueToGraph(velocityX);

                /*
                float accx = portInterface.ReadFloat();
                float accy = portInterface.ReadFloat();
                float accz = portInterface.ReadFloat();
                float gyrox = portInterface.ReadFloat();
                float gyroy = portInterface.ReadFloat();
                float gyroz = portInterface.ReadFloat();
                float magx = portInterface.ReadFloat();
                float magy = portInterface.ReadFloat();
                float magz = portInterface.ReadFloat();
                accxg.AddValueToGraph(accx);
                accyg.AddValueToGraph(accy);
                acczg.AddValueToGraph(accz);
                gyroxg.AddValueToGraph(gyrox);
                gyroyg.AddValueToGraph(gyroy);
                gyrozg.AddValueToGraph(gyroz);
                magxg.AddValueToGraph(magx);
                magyg.AddValueToGraph(magy);
                magzg.AddValueToGraph(magz);
                */

                Application.DoEvents();
            }
        }
        public static void Main3()
        {
            SerialPort port = new SerialPort("COM7", 9600, Parity.None, 8, StopBits.One);
            SerialPortInterface portInterface = new SerialPortInterface(port);
            portInterface.Open();

            GraphForm magX = new GraphForm("MagX");
            GraphForm magZ = new GraphForm("MagZ");
            GraphForm magY = new GraphForm("MagY");
            GraphForm frdmagX = new GraphForm("FRDMagX");
            GraphForm frdmagZ = new GraphForm("FRDMagZ");
            GraphForm frdmagY = new GraphForm("FRDMagY");

            magX.Visible = true;
            magZ.Visible = true;
            magY.Visible = true;
            frdmagX.Visible = true;
            frdmagZ.Visible = true;
            frdmagY.Visible = true;

            while (true)
            {
                int var = 0;
                while (var != 'S')
                {
                    var = portInterface.ReadByte();
                }
                magX.AddValueToGraph(readShort(portInterface));
                magY.AddValueToGraph(readShort(portInterface));
                magZ.AddValueToGraph(readShort(portInterface));
                frdmagX.AddValueToGraph(readShort(portInterface));
                frdmagY.AddValueToGraph(readShort(portInterface));
                frdmagZ.AddValueToGraph(readShort(portInterface));

                Application.DoEvents();
            }
        }