Problems with readStringUntil

Hello folks, having some trouble with some code here and wondering if anyone had any advice. First of all I would like to say the code itself is just fine, it works pretty well on my serial monitor for Arduino, I'm using serial inputs to trigger some chains of events for my RFID reader I've got, here is the meat of the code, none too spectacular I'm afraid:

void loop() {
  if(Serial.available()){ 
    command = Serial.readStringUntil('\r'); 
    if(command.equals("rfid:dev.ver\r")){ 
    Init(); } 
    else if(command.equals("rfid:qid.id\r")){
    GetID(); 
  }
  else{ 
      Serial.print(command);
      }
}
}

My problem is I've been trying to set up the input string to come from a separate terminal down the comms line for a user and my problem is on the "readStringUntil" line, I've added the else statement to show me exactly what the Arduino is "seeing" as it were and it comes out with a load of jumbled characters (note these characters are the exact same every time).

I've tried adding delays, tried reading individual characters from the input string and storing them in an array so I didn't need the readString commands, tried adjusting baud rates and such but to no avail.

If anyone has any ideas on this that would be excellent, my first thoughts are to do with the speed the inputString is coming in and that the Arduino can't read it quick enough and its jumbling its characters but I can't seem to fix it.

Make sure the baud rate matches between the two devices.

That was one of my first thoughts for the read problems, they're both at 9600.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).

When using Cstrings you must use strcmp() to compare text values rather than ==

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

what is "a separate terminal down the comms line"?

Juraj:
what is "a separate terminal down the comms line"?

That would be a separate input terminal communicating with the Arduino through the same communications line, at its most basic I'm sending the inputString from somewhere else rather than the serial monitor for a different user.

Robin2:
It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).

When using Cstrings you must use strcmp() to compare text values rather than ==

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

Yepp, not gonna lie I am not massively fond of the string class either, I will give the strcmp function a try and see what that yields. I did use a char array system for the serial.read section rather than readStringUntil, that didn't work either.

Juraj:

something like this? Computer terminal - Wikipedia

or only a terminal program running on the computer were the Arduion is connected with virtual com port over USB?

Sorry, I was a bit unclear on what’s sending data to my Arduino. It comes from a terminal program like TeraTerm (but not TeraTerm). You simply write out the command on this and as long as the code is uploaded onto the Arduino and the comms port is open the set up is the same as using the Serial monitor (or supposed to be).

danchan1:
You simply write out the command on this and as long as the code is uploaded onto the Arduino and the comms port is open the set up is the same as using the Serial monitor (or supposed to be).

So it is not "down the comms line" - it is just an alternative to the Serial Monitor program?

In general you can use any terminal emulator program to communicate with an Arduino. If your system works with the Serial Monitor and not with your other mystery program then the fault must lie in the settings for this mystery program.

I presume you know that you cannot use the Serial Montor and another program at the same time on the same PC serial port.

...R

Robin2:
So it is not "down the comms line" - it is just an alternative to the Serial Monitor program?

In general you can use any terminal emulator program to communicate with an Arduino. If your system works with the Serial Monitor and not with your other mystery program then the fault must lie in the settings for this mystery program.

I presume you know that you cannot use the Serial Montor and another program at the same time on the same PC serial port.

...R

I say again, it prints garbled messages. If i had the comms line open through the serial monitor it wouldn't connect at all because of course they use the same port, you misunderstand the reference to comms line in this context. I have a separate terminal emulator that writes a string to the Arduino, that's about it, it then reads the response as a string. The problem arises from the data being received by the Arduino, the Serial.read does not read the incoming data correctly, there is no issue going from the Arduino to the terminal emulator with the response.

The

danchan1:
I have a separate terminal emulator that writes a string to the Arduino, that's about it, it then reads the response as a string. The problem arises from the data being received by the Arduino,

As I said earlier, if you can do that without error using the Serial Monitor then the problem lies with the settings of your terminal emulator.

...R