Arduino Micro serial communication with C#

in my thesis project I'm using an ATMega32u4 as an Arduino Micro. I have programmed it with the bootloader and I can upload sketches via USB. When I try to establish a serial connection, the Serial Monitor of the IDE perfectly shows all the data I've send. This is the sketch I use:

void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:
  // I also tried it using

Very simple, for testing. The monitor shows:
et cetera.

When I try to read this data with a C# program with the following code:

serialPort1 = new System.IO.Ports.SerialPort();
                    serialPort1.PortName = "COM4"; //Com Port Name                
                    serialPort1.BaudRate = 9600; //COM Port Speed
                    serialPort1.WriteTimeout = 1000;
                    serialPort1.ReadTimeout = 5000;

                    if (!serialPort1.IsOpen)

                            string read = serialPort1.ReadExisting(); 
                            read = serialPort1.ReadLine();
                            //some methode to give out "read"
                            MessageBox.Show("There was an error. Please make sure that the correct port was selected, and the device, plugged in.");

I get a ReadTimeout (I know that because it always takes the amount of time that I set in ReadTimeout). The Arduino Micro is at port COM4. Windows Device Manager shows it as connected.

If I try the same sketch with my Arduino Uno (different port, of course), it works, the C# program puts out: 123456789. The ports are identical in their baud rate, parity, etc.

What can I try to make this work or to figure out the problem?
Thank you for your help!

You may need to set DTR and RTS in your C# program when it opens the serial port.


Opening the serial port resets the Arduino. Do that ONCE in your C# code, NOT every time you want to collect data from it.

You can, and should, use the fact that serial data arrives asynchronously, to trigger a callback on another thread, to handle the serial data.

@Robin2: Tank you very much, it worked!

@PaulS: I guess I should do that, but it is not a big problem, so I won't :wink: Maybe later... Thanks, though!