SerialReadString() How does it work with String name[7]={"abc", "def"}

It looks simple, but I spent a lot of time to screeching and by trying to combine and recombine things together.

I want to compare String name={"abc", "def"} to Serial.readString(); and if "abc"(from Serial.readString)=="abc" (from String name[7]) so statement 1.

and if and if "def"(from Serial.readString)=="def" (from String name[7]) so statement 2.

String ReadVoltCar[14]={"MEAS:DC?","*TST?"} ;

long  NombreRand;                  //Configuration de NombreRand par défaut
float MultipleVal=0.1000;  
float NouvelleVal;

void setup() {
Serial.begin (9600);               //   9600bits/sec
}

void loop(){ 
  
  if(Serial.available()>0){
 
  ReadVoltCar[14]=Serial.readString();
  }
  
if(Serial.readString()==ReadVoltCar[9]  && Serial.readString()=="MEAS:DC?"){
 NombreRand=random(0,1000); 
 NouvelleVal=MultipleVal*NombreRand;
 Serial.print(NouvelleVal,4);
 ReadVoltCar[14]=Serial.readString();
delay(20);
}

  if (Serial.readString()==ReadVoltCar[6] && Serial.readString()=="*TST?"){
  Serial.print("OK");
  ReadVoltCar[14]=Serial.readString();
  delay(20);
}

else{
    Serial.readString()==0; 
}

delay(500);
}

Use char * instead of String in "String name={"abc", "def"}". Also you are missing the brackets [] in that line too.

It should be char * name[2] = {"abc", "def"}; now when you collects the chars from Serial.read(), you should store them in an empty buffer first and once you have your string, add a NULL character ( '\0' ) at the end .

If you receive 3 characters from Serial.read() (buffer[0] = 'a', buffer[1] = 'b', buffer[2] = 'c') then the forth index ( buffer[3]) must be set to NULL or '\0'

Once you have done these above, and you were able to get your sent data, now you can use strcmp() to compare them.

Example:

if( !strcmp(buffer, "abc") )  // if they are the same, then this IF statement will be true.
{
  // The strings match, do something here
}

Ok. I just tried that and it says <invalid conversion from 'char' to 'const char*'>.

#define memory1 9
#define memory2 6

char* ReadVoltCar[2]={"MEAS:DC?","*TST?"};

String  buffer1[memory1];//{'M','E','A','S',':','D','C','?','\0'};
String  buffer2[memory2];//{'*','T','S', 'T','?','\0'};

long  NombreRand;                  //Configuration de NombreRand par défaut
float MultipleVal=0.1000;  
float NouvelleVal;

void setup() {
  
  Serial.begin (9600);               //   9600bits/sec

  buffer1[0]='M', buffer1[1]='E', buffer1[2]='A', buffer1[3]='S', buffer1[4]=':',
  buffer1[5]='D', buffer1[6]='C', buffer1[7]='?', buffer1[8]='\0';

  buffer2[0]='*', buffer2[1]='T', buffer2[2]='S', buffer2[3]='T', buffer2[4]='?',
  buffer2[5]='\0';
}

void loop(){
  
  
  if(!strcmp( buffer1[memory1]), "MEAS:DC?"){

  }

  if(!strcmpbuffer2[memory2], "*TST?")){

  }
delay(100);
}

Not sure what your code is supposed to do, but below is some very simple serial capture and compare code.

// zoomkat 8-6-10 serial I/O string test
// type a string in serial monitor. then send or enter
// for IDE 0019 and later

int ledPin = 13;
String readString;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT); 
  Serial.println("serial on/off test 0021"); // so I can keep track
}

void loop() {

  while (Serial.available()) {
    delay(3);  
    char c = Serial.read();
    readString += c; 
  }

  if (readString.length() >0) {
    Serial.println(readString);

    if (readString == "on")     
    {
      digitalWrite(ledPin, HIGH);
      Serial.println("LED ON");
    }
    if (readString == "off")
    {
      digitalWrite(ledPin, LOW);
      Serial.println("LED OFF");
    }
    readString="";
  } 
}

Strings used to cause memory corruptions when freed, however now they just take up more memory than needed.

Use char and char * from here on in.

#define memory1 9
#define memory2 6

char* ReadVoltCar[2]={"MEAS:DC?","*TST?"};

char buffer1[memory1] = "MEAS:DC?"; // when done like this, "MEAS:DC?" is the exact same as {'M', 'E', 'A', 'S' ... '\0'}
char buffer2[memory2] = "*TST?";

long  NombreRand;                  //Configuration de NombreRand par défaut
float MultipleVal=0.1000;  
float NouvelleVal;

void setup() {
  
  Serial.begin (9600);               //   9600bits/sec
}

void loop(){
  
  
  if(!strcmp( buffer1, "MEAS:DC?")){
    
  }

  if(!strcmp(buffer2, "*TST?")){

  }
delay(100);
}

Yeah, but my serial monitor is running continuously through the loop displaying characters "MEAS:DC?" and "*TST?". The thing I did, I just compared bytes of the characters displayed on serial monitor and compared to min and max val of byte I should get. It works great not really as I expected to but ok. Thanks a lot I will save your sketch as the same.

   void loop(){
  
  if(Serial.available()>0){
    
    int ByteVolt=Serial.readBytesUntil('\0', buffer1, 8);
    
    int ByteTest=Serial.readBytesUntil('\0', buffer2, 5);
    
    if(5<ByteVolt>=8){
    //if(!strcmp(buffer1,"MEAS:DC?"))  
    NombreRand=random(0,1000); 
    NouvelleVal=MultipleVal*NombreRand;
    Serial.print(NouvelleVal,4);
//  ReadVoltCar[14]=Serial.readString();
    delay(20);
    }
   
    if( ByteTest>=5){
//    if(!strcmp(buffer2,"*TST?"))
    Serial.print("OK");
//  ReadVoltCar[14]=Serial.readString();
    delay(20);
}
  }
  delay(100);
    }

Do you own a chicken? If so, then tell it to stop scratching your keyboard. Actually have it post the full code and then tell it.

if(5=8){

This is probably not doing what you are expecting.

Perhaps this maybe

if((5<ByteVolt) || (ByteVolt <= 8)){

Oh no problem cooked it in microwave...
Here is my full sketch (more adequate behaviour after correction):

#define memory1 9
#define memory2 6

#include <String.h>

char* ReadChar[2]={"MEAS:DC?","*TST?"};

char  buffer1[memory1]={'M','E','A','S',':','D','C','?','\0'};
char  buffer2[memory2]={'*','T','S','T','?','\0'};

int ByteIn=0;

const int LEDpin=8; 

long  NombreRand;                  //Configuration de NombreRand par défaut
float MultipleVal=0.1000;  
float NouvelleVal;

void setup() {
  Serial.begin (9600);               //   9600bits/sec
  Serial.flush();
  pinMode(LEDpin, OUTPUT);
}

void loop(){
  
  if(Serial.available()>0){
    
    int ByteVolt=Serial.readBytesUntil('\0', buffer1, 8);
    int ByteTest=Serial.readBytesUntil('\0', buffer2, 5);

delay(100);

    if((8<ByteVolt)||(ByteVolt<=9)){
     if(!strcmp(buffer1,"MEAS:DC?")){  
    NombreRand=random(0,1000); 
    NouvelleVal=MultipleVal*NombreRand;
    Serial.print(NouvelleVal,4);
    delay(20);
    }
    }
   
    if(( 5<ByteTest)||(ByteTest<=6)){
    if(!strcmp(buffer2,"*TST?")){
    Serial.print("OK");
    delay(20);
}
    }
  }
  delay(20);
    }

Why not just have ByteVolt == 9 and ByteTest == 6?

Also see this link.

I don't have any argument to debate... it's a good idea