0
votes

I have a C# dll in which I want to read my Arduino's serial port. For this test, I'm just sending out "1 1". I can't get C# to read this, I always get a timeout error. I tried various baud rates, various combinations of port.ReadLine, port.ReadByte (in C#) and Serial.print and Serial.println (in Arduino). The Arduino is a Teensy USB CDC (if that matters). The port settings in the Device Manager seem OK, as in a serial port monitor, I can see the Arduino output (seemingly) fine:

enter image description here

C# code.

int interval = 25;
using (SerialPort port = new SerialPort("COM9", 57600, Parity.None, 8, StopBits.One)) {
                    port.ReadTimeout = 7000;
                    port.NewLine = "\r";
                    try {
                        string output = null;
                        port.Open();
                        while (output == null && loopCnt < (timeOut / interval)) {
                            output = port.ReadLine();
                            Thread.Sleep(interval);
                            loopCnt++;
                        }
                        MessageBox.Show("output: [" + output+"]");

Arduino code:

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

void loop() {
    Serial.print("1 1");
    Serial.print('\r');
    delay(5000);
}
1
Have you tried to connect with the arduino via arduino software?Aldert
If you mean the Serial Monitor in the Arduino IDE, it shows "1 1 1 1 1 1 ....", ie. the correct outputMrSparkly
I have not tried this myself, I have done a project over bluetooth with successful communication with an Arduino pro. I found a link what might be interesting for you medium.com/@sawetefe/…Aldert
Thanks, I'll keep it for future reference. Meanwhile, I've solved it (see my answer below): had to set port.RtsEnable = true;MrSparkly
Great you got it working, success with the project!Aldert

1 Answers

0
votes

Solved: the port settings need port.RtsEnable = true;