0

I would like to read the serial data with a C# Windows Forms Application. The data is send with an ESP32 C3 Super Mini. When I use the Serial Monitor from the Arduino IDE everything works fine.

If I'm reading the serial data with my C# Application (serialPort1.ReadLine(); or serialPort1.ReadExisting();) I will get the data only once and then the ESP resets with this reason: rst:0x15 (USB_UART_CHIP_RESET),boot:0xc (SPI_FAST_FLASH_BOOT)

C# Code

private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
    lblState1.Invoke(new MethodInvoker(ProcessData1));
}

private async void ProcessData1()
{
    //MessageBox.Show(serialPort1.ReadLine());
    MessageBox.Show(serialPort1.ReadExisting());
}

Arduino Code

unsigned long last_time = 0;

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    // Print a heartbeat
    if (millis() > last_time + 2000)
    {
        Serial.println("Arduino is alive!!");
        last_time = millis();
    }
}

A few days ago the application worked fine. After I upload a new programm to the ESP32 I got this problem and can't fix it.

Edit

DtrEnable and RtsEnable are set to false.

13
  • You might want to avoid doing Serial I/O on the GUI thread. Other than that, there surely is mor tto tthe serial connection than that, right? Where do you open it? Why don't you catch exceptions? Commented May 29, 2024 at 14:02
  • @Fildor The C# code is about 430 lines long and everything else worked so I reduced the code to the lines above and still got the same error. I open the serial port with the Form Shown event. In my code i am catching exceptions but I don't get any exception an the C# side. Commented May 29, 2024 at 14:12
  • If the source code you provided is correct, then perhaps it's because a message box is being displayed? The processing is probably stopped there, waiting for the operator to act. Wouldn't it be better to add the content to be displayed using a text box control? Commented May 29, 2024 at 14:31
  • @kunif I used the message box for debugging only since i got the Problem. Even if I do nothing with the data and just call serialPort1.ReadExisting(); I got the same error. Commented May 29, 2024 at 14:44
  • If I use your example I get this error from the catch inside the void Read(): The connection is closed Commented May 29, 2024 at 15:08

1 Answer 1

0

Problem got solved over night by just leaving the Arduino unpluged. Thanks to @kunif for your help.

Sign up to request clarification or add additional context in comments.

1 Comment

It will be better to leave it as a comment. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.