I can't use readbytes() to byte* buffer

Here is my code:

byte recData[4];
void setup() 
{ 
  Serial.begin(9600);
} 
  
void loop() 
{ 
  if( Serial.available() > 0){
    Serial.readBytes(recData, 2);

  }
}

and sketch can not compile

 In function 'void loop()':
:25: error: invalid conversion from 'unsigned char*' to 'char*'
:25: error: initializing argument 1 of 'size_t Stream::readBytes(char*, size_t)'

Am I wrong or something?

byte and char are not the same type.

Thank for ur fast answer, but in the reference page of Arduino said that we can use both type of variable??

Syntax

Serial.readBytes(buffer, length)

Parameters

buffer: the buffer to store the bytes in (char[] or byte[])
length : the number of bytes to read (int)

Returns

byte

Well you are both right, and wrong.

It should work, but it doesn't.

Just humour it, and make the array an array of char.

Or you could try putting a cast on the argument of the function, like this

Serial.readBytes( (char*)recData, 2);

It may, or may not work.

The reference page is buggy - they should always provide tested example code!!

Lol thank you! I think that so ridiculous when "readbyte()" cannot read Byte. Because I have to work with range 0 to 255. And michinyon's solution may work but forcing to char* will change the value in range -128 to 127. I ve just figued out myseft this way, but little bit quite not fun :(

  if( Serial.available() > 1){
    recData[0] = Serial.read();
    recData[1] = Serial.read();

And michinyon’s solution may work but forcing to char* will change the value in range -128 to 127.

It doesn’t change any values. The binary value remains the same, but it is up to you how to interpret it.

0xff == 25510 == -1