Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

SerialPort.ReadExisting() reads data multiple times

$
0
0

Hello,

I need to read serial port data sent by a device. The device sends me "I AM COM4" only once but my application reads and displays me "I AM COM4I AM COM4I AM COM4I AM COM4I AM COM4I AM COM4I AM COM4I AM COM4I AM COM4I AM COM4I AM COM4" on text box.

my code is as under:


               

        public static SerialPort COMPORT = new System.IO.Ports.SerialPort("COM1", 9800, Parity.None, 8, StopBits.One);


private void MainScreen_Load(object sender, EventArgs e)
        {
            COMPORT.DataReceived+=new System.IO.Ports.SerialDataReceivedEventHandler(COMPORT_DataReceived);
            COMPORT.Open();
           COMPORT.Write("Hello");
            Thread.Sleep(20);      
        }

        private void COMPORT_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            ReceivedString += COMMON.COMPORT.ReadExisting();
            this.MScrTextB_ComReceived.Text += ReceivedString;

        }

I have checked incoming data from the device on hyperterminal and I am getting proper output. but in my application I am getting DATA multiple times.

Please suggest me where i am doing wrong.

Thanks in advance


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>