Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

vs2013 C# serial data received event handler

Status
Not open for further replies.

fawadbutt

Member level 3
Member level 3
Joined
Oct 29, 2010
Messages
61
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Location
Lahore, Pakistan, Pakistan
Visit site
Activity points
1,754
hi i need help in serial data receiving . i using vs2013 and code write in c#. i call serial data received event handler but its not in working this is my code:
Code:
public partial class Form1 : Form
    {

        string rxdata;
        public Form1()
        {
            InitializeComponent();
            ///////////////////////Serial port Setting//////////////////////////////////
            SerialPort SerialPort1 = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
            SerialPort1.Handshake = Handshake.None;
            SerialPort1.ReadTimeout = 500;
            SerialPort1.WriteTimeout = 500;
            ///////////////////////////-Receiving event handler-/////////////////////////////
            SerialPort1.DataReceived += new SerialDataReceivedEventHandler(SerialPort1_DataReceived);
            //////////////////////////////////////////////////////////////////////////////
        }
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (SerialPort1.IsOpen)
            {
                SerialPort1.Close();
            }
        }
        private void SerialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            MessageBox.Show("Data Received");
            SerialPort1 = (SerialPort)sender;
            rxdata = SerialPort1.ReadExisting();
            this.Invoke(new EventHandler(displaytext));
        }
        private void displaytext(object sender, EventArgs e)
        {
         //   textBox1.AppendText(rxdata); 
            richTextBox1.AppendText(rxdata);
        }

my data port open and sending code is working fine.
plz i need help.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top