예제 #1
0
        StringBuilder CommBuffer = new StringBuilder();        //"";				//holds incoming serial data from the port
        private void SerialRXEventHandler(object source, SerialRXEvent e)
        {
            CommBuffer.Append(e.buffer);                                                // put the data in the string
            if (parser != null)                                                         // is the parser instantiated
            {
                try
                {
                    Regex  rex = new Regex(".*?;");                                                                                             //accept any string ending in ;
                    string answer;
                    uint   result;

                    for (Match m = rex.Match(CommBuffer.ToString()); m.Success; m = m.NextMatch()) //loop thru the buffer and find matches
                    {
                        answer = parser.Get(m.Value);                                              //send the match to the parser

                        if (answer.Length > 0)
                        {
                            result = SIO.put(answer);                                                           //send the answer to the serial port
                        }
                        CommBuffer = CommBuffer.Replace(m.Value, "", 0, m.Length);                              //remove the match from the buffer
                    }
                }
                catch (Exception)
                {
                }
            }
        }
예제 #2
0
        StringBuilder CommBuffer = new StringBuilder();//"";				//holds incoming serial data from the port
        private void SerialRX2EventHandler(object sender, SerialRXEvent e)
        {
            //			SIOMonitor.Interval = 5000;		// set the timer for 5 seconds
            //			SIOMonitor.Enabled = true;		// start or restart the timer

            //double T0 = 0.00;
            //double T1 = 0.00;
            //int bufferLen = 0;
            // SerialPort spL = (SerialPort)sender;
            //   SDRSerialPort2 spL = (SDRSerialPort2)sender;
            // if (!SIO2.IsOpen || spL.BasePort.PortName != SIO2.BasePort.PortName) return;

            CommBuffer.Append(e.buffer);                                                // put the data in the string
            if (parser != null)                                                         // is the parser instantiated
            {
                //bufferLen = CommBuffer.Length;
                try
                {
                    Regex  rex = new Regex(".*?;");                                                                             //accept any string ending in ;
                    string answer;
                    uint   result;

                    for (Match m = rex.Match(CommBuffer.ToString()); m.Success; m = m.NextMatch())      //loop thru the buffer and find matches
                    {
                        //testTimer1.Start();
                        answer = parser.Get(m.Value);                                   //send the match to the parser
                        //testTimer1.Stop();
                        //T0 = testTimer1.DurationMsec;
                        //testTimer2.Start();
                        if (answer.Length > 0)
                        {
                            result = SIO2.put(answer);                                          //send the answer to the serial port
                        }
                        //testTimer2.Stop();
                        //T1 = testTimer2.DurationMsec;
                        CommBuffer = CommBuffer.Replace(m.Value, "", 0, m.Length);                   //remove the match from the buffer
                        //Debug.WriteLine("Parser decode time for "+m.Value.ToString()+":  "+T0.ToString()+ "ms");
                        //Debug.WriteLine("SIO2 send answer time:  " + T1.ToString() + "ms");
                        //Debug.WriteLine("CommBuffer Length:  " + bufferLen.ToString());
                        //if (bufferLen > 100)
                        //Debug.WriteLine("Buffer contents:  "+CommBuffer.ToString());
                    }
                }
                catch (Exception)
                {
                    //Add ex name to exception above to enable
                    //Debug.WriteLine("RX Event:  "+ex.Message);
                    //Debug.WriteLine("RX Event:  "+ex.StackTrace);
                }
            }
        }
예제 #3
0
        StringBuilder CommBuffer = new StringBuilder();        //"";				//holds incoming serial data from the port
        private void SerialRXEventHandler1(object source, SerialRXEvent e)
        {
            CommBuffer.Append(e.buffer);                                       // put the data in the string

            if (CommBuffer.Length >= 4)
            {
                try
                {
                    console.RotorAngle = CommBuffer.ToString().TrimStart(';');


                    //  Debug.WriteLine("COMBUFFER2: " + console.RotorAngle);

                    console.RotorAngleRdy = true;

                    CommBuffer.Clear();
                }
                catch (Exception)
                {
                }
            }
        } // SerialRXEventHandler1
예제 #4
0
		StringBuilder CommBuffer = new StringBuilder();//"";				//holds incoming serial data from the port
		private void SerialRXEventHandler(object source, SerialRXEvent e)
		{

            CommBuffer.Append(e.buffer);                                		// put the data in the string
			if(parser != null)													// is the parser instantiated
			{
				try
				{
					Regex rex = new Regex(".*?;");										//accept any string ending in ;
					string answer;
					uint result;

					for(Match m = rex.Match(CommBuffer.ToString()); m.Success; m = m.NextMatch())	//loop thru the buffer and find matches
					{
                        answer = parser.Get(m.Value);                                   //send the match to the parser

                        if(answer.Length > 0)
    						result = SIO.put(answer);                           		//send the answer to the serial port

						CommBuffer = CommBuffer.Replace(m.Value, "", 0, m.Length);                   //remove the match from the buffer
                    }
				}
				catch(Exception)
				{

				}
			}
		}