3 Replies - 563 Views - Last Post: 26 December 2015 - 09:14 AM Rate Topic: -----

#1 naouf10   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 15
  • Joined: 06-November 15

Why the event is not firing when COM port receives data?

Posted 26 December 2015 - 08:10 AM

I am using windows forms and I am trying to receive data from COM1 which is transmitted by external device.

I wanted to display received data in richTextBox but the problem is that the serialPort1_DataReceived Event is not firing when the data arrives to COM1. I have same settings in both COM1 and my C# application.

I looked for solution on the internet but no luck. Please help me. Thank you

Here is my code:


public partial class Form1 : Form

    {


    public SerialPort mySerialPort = new SerialPort("COM1", 1200, Parity.None, 8, StopBits.One);


    public Form1()
    {
        InitializeComponent();


        mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataR);
         mySerialPort.Open();
     }

    public void DataR(object sender, SerialDataReceivedEventArgs e)

    {

        if (richTextBox1.InvokeRequired)
         {
             richTextBox1.Invoke(new SerialDataReceivedEventHandler(DataR), sender, e);
         }
         else
         {


            richTextBox1.AppendText(mySerialPort.ReadExisting());

        }
      }



    }


Is This A Good Question/Topic? 0
  • +

Replies To: Why the event is not firing when COM port receives data?

#2 andrewsw   User is offline

  • quantum multiprover
  • member icon

Reputation: 6775
  • View blog
  • Posts: 27,938
  • Joined: 12-December 12

Re: Why the event is not firing when COM port receives data?

Posted 26 December 2015 - 08:43 AM

Are you sure the event isn't fired? Set a breakpoint on line 18 and see if it is ever reached (if you haven't done this already).
Was This Post Helpful? 1
  • +
  • -

#3 naouf10   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 15
  • Joined: 06-November 15

Re: Why the event is not firing when COM port receives data?

Posted 26 December 2015 - 09:05 AM

View Postandrewsw, on 26 December 2015 - 08:43 AM, said:

Are you sure the event isn't fired? Set a breakpoint on line 18 and see if it is ever reached (if you haven't done this already).


yes i am sure. i already sat a break point. I noticed the even is not fired. I really don't know why. any idea to try? thank you
Was This Post Helpful? 0
  • +
  • -

#4 naouf10   User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 15
  • Joined: 06-November 15

Re: Why the event is not firing when COM port receives data?

Posted 26 December 2015 - 09:14 AM

View Postandrewsw, on 26 December 2015 - 08:43 AM, said:

Are you sure the event isn't fired? Set a breakpoint on line 18 and see if it is ever reached (if you haven't done this already).


yes i am sure. i already sat a break point. I noticed the even is not fired. I really don't know why. any idea to try? thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1