[Resolved]- Serial.readBytes() invalid conversion of types

Hi there!
I’m working on porting an Andruino code, and I need some help.

My ported code doesn’t compiles right now with the error:
invalid conversion from 'uint8_t (aka unsigned char) to ‘char*’**

The error is apparently caused by:

  Serial1.readBytes(_rx_buffer, frameSize);

The Buffer is defined:

uint8_t  _rx_buffer[BUFFER_SIZE];

What puzzles me, is that Arduino and Photon uses the same definition for readBytes:

  size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer

and the Arduino documentation about readBytes says:

buffer: the buffer to store the bytes in (char[] or byte[])

So, in theory is possible to use both char or byte, and then, the buffer array is OK.
Obviously the code works perfectly on Arduino.

I always appreciate any help.

I can’t say whether the compiler used by Particle treats char as signed or unsigned (probably signed based on the error) but you have at least two possibilities.

Change the declaration of the buffer to char.

char   _rx_buffer[BUFFER_SIZE];

or cast the parameter in the call

Serial1.readBytes((char *)_rx_buffer, frameSize);

Either should work unless you have conversions elsewhere in your code that could be affected by the sign.


Dear @Muskie. Thank you very much for your message.

I went with the cast option since _rx_buffer is used on other parts
of the code.

It compiled OK.
Thank you!