This is the code given by http://www.gravitech.us/7segmentshield.html.
void SerialMonitorPrint (byte Temperature_H, int Decimal, bool IsPositive)
{
Serial.print("The temperature is ");
if (!IsPositive)
{
Serial.print("-");
}
Serial.print(Temperature_H, DEC);
Serial.print(".");
Serial.print(Decimal, DEC);
Serial.print(" degree C");
Serial.print("\n\n");
}
But when I try to read data from serial port, I found that I read data character by character.
UPDATE
while(1)
{
char buffer[100];
int chars_read = read(fd, &buffer, sizeof(buffer));
buffer[chars_read] = '\0';
printf("%s", buffer);
}
So how can I read line by line?
read()
which is going to tell you how many bytes were read successfully into thebuffer
and need not always be the size of the buffer. And before printing you would want to add a '\0` character in thebuffer
after this size. Also what kind of data you expect to read over the serial port - just text or hexadecimal values ? – Tuxdudefgets
or similar? You'd need to set up a file stream tofd
for that. – teppicfgets
to replaceread
? – Cacheingfgets
. Also if there is any EOF character from the serial port -fgets
will get confused and will stop reading data. – Tuxdude