Error closing serial port in C #

1

I'm new to C #. I made a program, which is continuously reading the serial port data and showing in a textBox.

So far, everything works fine. The problem occurs when I try to close the port, it gives the following error

  

The I / O operation has been aborted due to an thread output or an application request;

I have read several threads on the same subject, but I have not solved it yet.

Below is part of the code.

public FormRelatorio()
{
    InitializeComponent();
    FormPrincipal.SerialPortCommunicator.SerialPort.DataReceived += 
          new SerialDataReceivedEventHandler(SerialPort_DataReceived_RL);
}
 
private void SerialPort_DataReceived_RL(object sender, SerialDataReceivedEventArgs e)
{
    rxSerialRL = FormPrincipal.SerialPortCommunicator.SerialPort.ReadLine();
    BeginInvoke(new Fdelegate(recebeSerial), new object[] { rxSerialRL });    
}
public void recebeSerial(string a)
{
    textBoxTesteMSG.Text = a; 
}
    
asked by anonymous 30.06.2017 / 18:10

1 answer

0

Try this and instead of CommPort put the name of your class that addresses the Serial Port.

void CloseComPort()
{

CommPort com=CommPort.Instance;
com.Close();
}

I hope this is the beginning of the solution of your need.

    
10.12.2017 / 14:45