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

  • SEARCH
  • Home
  • 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 7972469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:52:38+00:00 2026-06-04T07:52:38+00:00

My program is receiving data on a serial port, after the data is received

  • 0

My program is receiving data on a serial port, after the data is received it can be interpreted in one of eight different ways.

If I want to trigger an event after the data is received, should I use one event and use something like an enum in my custom event arg class, or should I create 8 separate events? Basically I am wondering what the convention is for creating events.

My assumption would be that a new event should be created when it is distinguishable from the current events, but I am not sure which way to go with my example.

Edit: To clarify the situation, the program predominantly will be communicating with a device over a serial port, the method that receives input is as follows:

Should I do this?

void receive(byte[] somebytes)
{
    // After checking to make sure all bytes expected are received
    switch(somecase)
    {
        case 0: TriggerEvent(SomeEventArgs);break;
        case 1: TriggerEvent(SomeEventArgs);break;
        case 2: TriggerEvent(SomeEventArgs);break;
        case 3: TriggerEvent(SomeEventArgs);break;
        case 4: TriggerEvent(SomeEventArgs);break;
        case 5: TriggerEvent(SomeEventArgs);break;
        case 6: TriggerEvent(SomeEventArgs);break;
        case 7: TriggerEvent(SomeEventArgs);break;
        case 8: TriggerEvent(SomeEventArgs);break;
    }
}

OR this:

void receive(byte[] somebytes)
{
    // After checking to make sure all bytes expected are received
    switch(somecase)
    {
        case 0: Event0(LessEventArgs);break;
        case 1: Event1(LessEventArgs);break;
        case 2: Event2(LessEventArgs);break;
        case 3: Event3(LessEventArgs);break;
        case 4: Event4(LessEventArgs);break;
        case 5: Event5(LessEventArgs);break;
        case 6: Event6(LessEventArgs);break;
        case 7: Event7(LessEventArgs);break;
        case 8: Event8(LessEventArgs);break;
    }
}
  • 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. Editorial Team
    Editorial Team
    2026-06-04T07:52:39+00:00Added an answer on June 4, 2026 at 7:52 am

    Both solutions will work, but I think it’s much easier to have a signle event.

    If you have a single event, you just have to define an unique EventArgs<T> publish a single event in your class, and handle a single event.

    All the logic to decide waht to do is in the “client class” that susbscribes to the event. This makes it easier to test and debug.

    So you’d need:

    • a class that publishes a single event
    • a method that handles that event and dispatches the execution to the right method, depending on the event arg
    • a method for handling each of the 8 cases.

    If you do it this way, it’s very easy to create a unit test to test the dispatcher method, and different unit tests to test each of the 8 methods.

    Your “server class”, which depends on external resoruces is simple. This is important becasue, it would be hard to debug an test the dispatcher that chose between eight events.

    Think of the other implementaion, using 8 events: you’d get a more confusing and hard to test and debug code.

    As a side note, I encourage you to read this thorough article on “C# Event Implementation Fundamentals, Best Practices and Conventions”

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

Sidebar

Related Questions

How to design a C/C++ program so that it can save some data after
I have a Java socket server program listening on a specific port. When receiving
In my program there is one thread (receiving thread) that is responsible for receiving
I am sending/receiving data over a serial line in Linux and I would like
I am receiving messages over serial port from a micro-controller. i am using a
Context: I am reading data from a serial port at 115.2 Kbaud. The read
I have a program whereby Data is being sent from one computer to another
I've developed a small program that listens to a serial port. My program is
is there any small working program for recieving from and sending data to client
I receiving a undefined reference error when try to compile an c++ program. I'm

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.