Hello,
I've been working on reading incoming serial data.
My approach is to read packets into a local buffer.
This is working so long as my local buffer is of data type CHAR.
However, if I try to declare my buffer array as a BYTE, I get a compliation error:
SerialInvest_1.ino : In function 'void loop()':
SerialInvest_1.ino : 34: error: invalid conversion from 'byte*' to 'char*'
SerialInvest_1.ino : 34: error: initializing argument 2 of 'size_t Stream::readBytesUntil(char, char*, size_t)'
Yet, accroding to the Arduino documentation, the buffer 'should' be legitimate as a BYTE:
[http://arduino.cc/en/Serial/ReadBytesUntil]
Syntax
Serial.readBytesUntil(character, buffer, length)
Parameters
character : the character to search for (char)
buffer: the buffer to store the bytes in (char[] or byte[])
length : the number of bytes to read (int)
Can anyone throw any insight/guidance on this please ?
I know a work around would be just to -127 from the values being sent .... but i'd prefer a clean solution than a workaround if possible.
Many Thanks
Simon
Code below shows the successful implimentation (it compiles)
However, changing either array (trash or buffer) to a BYTE data type, casuses compilation to fail
void loop() {
char trash[64]; // local buffer to collect any erroneous data before SOP
char buffer[2]; // local buffer to collect Packet data
int flag = 0; // miscellaneous int for debug purpose
if(Serial.available()==0){ // Do nothing if there is no data to read
goto esc;
}
memset(buffer,0,sizeof(buffer)); // Ensure no old data remains from previous loop
memset(trash,0,sizeof(trash));
flag = Serial.readBytesUntil('>', trash, 64); // get to start of packet (SOP) :: NB: Termination Char is not put into local buffer(trash), but IS removed from serial buffer.
flag = Serial.readBytesUntil('<', buffer, 2); // read until end of packet (EOP)
while(Serial.available()){ // clear serial buffer of any remaining values
Serial.read();
}
esc:
delay(20);
}