Esempio n. 1
0
        void _spManager_NewSerialDataRecieved(object sender, SerialDataEventArgs e)
        {
            if (this.InvokeRequired)
            {
                // Using this.Invoke causes deadlock when closing serial port, and BeginInvoke is good practice anyway.
                this.BeginInvoke(new EventHandler<SerialDataEventArgs>(_spManager_NewSerialDataRecieved), new object[] { sender, e });
                return;
            }

            something_new = true;
            int maxTextLength = 1000; // maximum text length in text box
            if (tbData.TextLength > maxTextLength)
                tbData.Text = tbData.Text.Remove(0, tbData.TextLength - maxTextLength);

            // This application is connected to a GPS sending ASCCI characters, so data is converted to text
            string str = Encoding.ASCII.GetString(e.Data);

            byte[] ascii = Encoding.ASCII.GetBytes(str);

            foreach (byte b in ascii)
            {
                j.Add(b);
                tbData.AppendText((char)(b) + " ");
            }
        }
Esempio n. 2
0
        void _spManager_NewSerialDataRecieved(object sender, SerialDataEventArgs e)
        {
            if (this.InvokeRequired)
            {
                // Using this.Invoke causes deadlock when closing serial port, and BeginInvoke is good practice anyway.
                this.BeginInvoke(new EventHandler<SerialDataEventArgs>(_spManager_NewSerialDataRecieved), new object[] { sender, e });
                return;
            }

            something_new = true;
            int maxTextLength = 1000; // maximum text length in text box
            if (tbData.TextLength > maxTextLength)
                tbData.Text = tbData.Text.Remove(0, tbData.TextLength - maxTextLength);

            // This application is connected to a GPS sending ASCCI characters, so data is converted to text
            string str = Encoding.ASCII.GetString(e.Data);

            byte[] ascii = Encoding.ASCII.GetBytes(str);

            foreach (byte b in ascii)
            {
                j.Add(b);

                if (j.Count >= 3)
                {
                    if (j.ToArray<Byte>()[j.Count - 1] == 0x14 &&
                        j.ToArray<Byte>()[j.Count - 1] == 0x13 &&
                        j.ToArray<Byte>()[j.Count - 1] == 0x12)
                    {
                        //byte[] k = { returnvalue };
                        //_spManager.Write(k,0,1);
                        //System.Diagnostics.Debug.WriteLine("Writing " + (int)returnvalue);
                        //_spManager.StartListening();
                    }
                }

                tbData.AppendText(b.ToString() + " ");
                if (FindDataFromBuffer(j.ToList<Byte>(), 42, 19) == 1)
                {
                }
            }
        }
Esempio n. 3
0
        void _spManager_NewSerialDataRecieved(object sender, SerialDataEventArgs e)
        {
            if (this.InvokeRequired)
            {
                // Using this.Invoke causes deadlock when closing serial port, and BeginInvoke is good practice anyway.
                this.BeginInvoke(new EventHandler<SerialDataEventArgs>(_spManager_NewSerialDataRecieved), new object[] { sender, e });
                return;
            }

            //           int maxTextLength = 1000; // maximum text length in text box
            //           if (tbData.TextLength > maxTextLength)
            //           tbData.Text = tbData.Text.Remove(0, tbData.TextLength - maxTextLength);

            // This application is connected to a GPS sending ASCCI characters, so data is converted to text

            string str = Encoding.ASCII.GetString(e.Data);

            tbData.AppendText(str);

            tbStats.AppendText("\r\nRecieved: " + str.Length + "[" + str + "]");
               //         tbStats.AppendText("Test: " + e.Data);
            tbData.ScrollToCaret();
        }