Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
try
{
    start_text = serialPort1.ReadByte();
}
catch (Exception err)
{
    MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}


What I have tried:

The I/O operation has been aborted because of either a thread exit or an application request.
Posted
Updated 4-Sep-20 10:57am
v2
Comments
CHill60 4-Sep-20 7:34am    
Posting guideline #2 "Have you searched or Googled for a solution?" Have you tried this search[^]
Richard MacCutchan 4-Sep-20 8:29am    
Probably something in the code that you do not show us.
Luc Pattyn 4-Sep-20 19:08pm    
Thanks for your code. Do you have a question?

I do: If you happen to get such an exception, what is it your program is doing at that point? Are you killing a thread, closing the port, exiting the program, or what?

1 solution

Quote:
start_text = serialPort1.ReadByte();

The error mostly will occur if you are trying to read the data when the port is closed. (forgot to open or accidentally got closed)

Make sure you open it in the start (if not doing already):
C#
serialPort1.Open()

Before reading the data, check for the port status:
C#
serialPort1.IsOpen

Look at the example provided here on how to use it: SerialPort Class (System.IO.Ports) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900