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 9193615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:12:33+00:00 2026-06-17T21:12:33+00:00

I am working on a project for a physics class and would like to

  • 0

I am working on a project for a physics class and would like to try and get an app together to perform the following. The test unit has a serial port on it that is outputting data at 1 Hz. I would like to have an app that will read the serial port data and save it to a file. I have created this in a Console app and it works fine. Now, I would like a GUI. On the main screen of the GUI I would like a couple of check boxes. One where the user can add a timestamp to the incoming data stream, one to output the data to a text file, and may be one to send the data to my graphite graphing server.

So, I am looking for some pointers here. Right now, I have a connect button. When pressed, it opens the serial port and performs a serial.readline() But if no data is currently being pushed across the link, the app is locked up. So I am assuming I need to use threading. Does this sound correct?

And last, how do I handle the check boxes? I would like 4 total buttons. Connect/Disconnect Record/Pause. At least these is my thoughts.

  • 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-17T21:12:35+00:00Added an answer on June 17, 2026 at 9:12 pm

    Instead of creating a thread for the serial port just hook into the DataReceived event.

    As for the checkboxes hook into the CheckedChanged event.

    So it would look something like:

    private bool paused;
    private SerialPort sp;
    
    public Form1()
    {
        InitializeComponent();
    
        sp = new SerialPort();
        sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
    }
    
    private void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
    {
        if (!paused)
        {
            string indata = sp.ReadExisting();
    
            //Display the data
            //To avoid cross thread problems do something like this
            Invoke(new Action(() =>
            {
                textBox1.Text += indata;
            }));
    
            //Or if you are just writing to the console 
            Console.WriteLine(indata); //Thread safe
    
            //Timestamp checkbox
            if (checkBox3.Checked)
            {
                //Display timestamp using DateTime.Now  
            }
    
        //Write to file checkbox
        if (checkBox4.Checked)
        {
            using (StreamWriter file = new StreamWriter(path, true))
            {
                file.WriteLine(indata);
            } 
        }
    }
    }
    
    //Pause/Resume Checkbox
    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        paused = checkBox1.Checked;
    }
    
    //Connect/Disconnect checkbox
    private void checkBox2_CheckedChanged(object sender, EventArgs e)
    {
        if (checkBox2.Checked)
        {
            sp.Open();
        }
        else
        {
            sp.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on a computational physics project (plotting related rates of chemical reactants
I am working on a project where I have a C# class library which
I'll try to be concise this time around! I'm still working Project Euler, this
I am working on a physics engine related project. In the C++ code below:
Using following code i can store program.txt in a working project folder, but how
I'm working on a educational physics project and I've chosen Box2D as my main
I'm copying some objective c++ files over from another (working) project. I get no
I have a working project on Linux (Ubuntu 11.04), but when i try to
I have a working project that Im amending, it crashes after trying to use
I'm curious if it is possible to move the written and fully working project

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.