can write on serial port but not read
Hi,
please I want to read from serial port, I can write but not read, here is my program. thanks for
help
regards
bela
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h>
int main(){
int fd, n; char rr[10];
fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
n = write(fd, "ATZ\r", 4);
if (n < 0) puts("write() of 4 bytes failed!\n");
else puts("4 bytes success!\n");
// fcntl(fd, F_SETFL, 0);
// with the previous it waits ... for ever
// with next no thing read : fails
fcntl(fd, F_SETFL, FNDELAY);
n = read(fd, rr,2 );
if (n < 0) puts("\nread 4 bytes failed!\n");
else printf("\nMessage read is %s\n", rr);
close(fd);
}
Reply to: