Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 114711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:54:15+00:00 2026-05-11T02:54:15+00:00

I am attempting to create a small application to collect data received from an

  • 0

I am attempting to create a small application to collect data received from an external sensor attached to COM10. I have successfully created a small C# console object and application that opens the port and streams data to a file for a fixed period of time using a for-loop.

I would like to convert this application to use the dataReceived event to stream instead. After reading the Top 5 SerialPort Tips, I still can’t seem to get this to work and don’t know what I am missing. I rewrote the console application so that all the code is in Main and is pasted below. Can someone please help enlighten me as to why the event handler port_OnReceiveDatazz is not being called even though I know that there is data being sent to the port by the hardware?

Thanks

Thanks to @Gabe, @Jason Down, and @abatishchev for all the suggestions. I am stumped and can’t seem to get the event handler to work. Perhaps it has something to do with the device. I can live with just reading the port in a thread and streaming the data straight to file.


Code


namespace serialPortCollection {   class Program     {         static void Main(string[] args)         {                          const int bufSize = 2048;             Byte[] buf = new Byte[bufSize]; //To store the received data.              SerialPort sp = new SerialPort("COM10", 115200);             sp.DataReceived += port_OnReceiveDatazz; // Add DataReceived Event Handler              sp.Open();             sp.WriteLine("$"); //Command to start Data Stream              // Wait for data or user input to continue.             Console.ReadLine();                         sp.WriteLine("!"); //Stop Data Stream Command             sp.Close();         }                 // My Event Handler Method         private static void port_OnReceiveDatazz(object sender,                                     SerialDataReceivedEventArgs e)         {             SerialPort spL = (SerialPort) sender;             const int bufSize = 12;             Byte[] buf = new Byte[bufSize];             Console.WriteLine("DATA RECEIVED!");             Console.WriteLine(spL.Read(buf, 0, bufSize));         }     } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:54:16+00:00Added an answer on May 11, 2026 at 2:54 am

    I think your issue is the line:**

    sp.DataReceived += port_OnReceiveDatazz;

    Shouldn’t it be:

    sp.DataReceived += new SerialDataReceivedEventHandler (port_OnReceiveDatazz);

    **Nevermind, the syntax is fine (didn’t realize the shortcut at the time I originally answered this question).

    I’ve also seen suggestions that you should turn the following options on for your serial port:

    sp.DtrEnable = true;    // Data-terminal-ready sp.RtsEnable = true;    // Request-to-send 

    You may also have to set the handshake to RequestToSend (via the handshake enumeration).


    UPDATE:

    Found a suggestion that says you should open your port first, then assign the event handler. Maybe it’s a bug?

    So instead of this:

    sp.DataReceived += new SerialDataReceivedEventHandler (port_OnReceiveDatazz); sp.Open(); 

    Do this:

    sp.Open(); sp.DataReceived += new SerialDataReceivedEventHandler (port_OnReceiveDatazz); 

    Let me know how that goes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 58k
  • Answers 58k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer m_ServiceHost.Description.Behaviors.Add(New ServiceMetadataBehavior()) m_ServiceHost.AddServiceEndpoint( GetType(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), 'net.tcp://localhost:6595') May 11, 2026 at 8:37 am
  • added an answer hide-ifdef-mode should do something like that. I have not used… May 11, 2026 at 8:37 am
  • added an answer since nobody provided a satisfactory answer to my question, i… May 11, 2026 at 8:37 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.

      Related Questions

      No related questions found