Arduino pro micro serial communication only works on serial monitor

Hello. First of all sorry for my english.

I wrote a code for my arduino pro micro to communicate with c# application.

The arduino code:

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

void loop()
{
   Serial.println("Test message.");
  delay(400);
}

The c# code:

static void Main(string[] args)
        {
            SerialPort serialPort = new SerialPort();
            serialPort.BaudRate = 9600;
            serialPort.PortName = "COM7";
            serialPort.Open();

            while (true)
            {
                string data = serialPort.ReadExisting();
                Console.WriteLine(data);
            }
        }

The problem is i cant take the messages from c# application. When i use the arduino serial monitor it works very well but on c# its not work. can anyone help please.

Oh i fixed it with this code:

serialPort.DtrEnable = true;

I added this code to c#.

Welcome to the forum

There is nothing in your Arduino sketch that reads the Serial input. Did you post the correct sketch ?

I was trying to create communication that send and receive data. But when i got this problem i just tried to send data from arduino to c#. This is the correct sketch. (Sorry for my english.)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.