toanhoi bui

toanhoi bui

  • NA
  • 70
  • 206.6k

Delay in program with RS232

Mar 1 2011 12:10 PM
Hello everybody, I have a problem  when recieve data to  Com Port with RS232 communication . When I recieve data to Com port I must delay to conect to Database and process it . But I return to receive next the data , this data is lost data .Example my data transmit to PC is "1234567" . The first time , my data is recieved "1234567" .After , this data is processed and the second my data is recieved "234567" or "34567" .I don't understand? Can you help me,please .This is my code
using System.IO.Ports;
using System.Threading;
   public partial class Form1 : DevComponents.DotNetBar.Office2007RibbonForm
    {
        SerialPort serialPort = new SerialPort();
        public string data;
      
        public Form1()
        {
            InitializeComponent();
            serialPort.DataReceived+=new SerialDataReceivedEventHandler(serialPort_DataReceived);
         
        }

        void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            data = serialPort.ReadExisting();
            //textBoxX5.Text = "";
            Thread t = new Thread(new ThreadStart(this.RunThread));
            t.Start();
        }
        public string datare;
        void Settext(string str)
        {
           
            datare += str;
      
            textBoxX9.Text = datare;
         
            datare = "";
           

        }
        public delegate void delSettext(string str);
        void RunThread()
        {
            delSettext func = new delSettext(this.Settext);

            this.Invoke(func, new Object[1] { data });
        }
     



Answers (1)