0
votes

I know this has probably been asked before but for my problem I cannot find a solution. I need a function receive(int recv) that I call in a loop and that receives one Byte. I have set up my serial port so far (termios.h) and am able to receive using read() However I can only receive the whole buffer of the port. So read(fd, recv, 255); always returns multiple bytes. What I would need is a Buffer in which I receive bytes and when receive(int recv) is called it always gives the first byte of this buffer. How would such a buffer look like? I would gladly appreciate any help on this one! Thanks!

1
From your code, I /think/ you're trying to read an integer from the serial port - is this correct? At the moment, it looks like you're calling ssize_t read(int fd, void *buf, size_t count) with int recv as the second parameter, which is badly wrong. - Philip Kendall

1 Answers

2
votes

This should be enough:

// ...
char buf[1];
read(fd, &buf, 1);
// ...