Originally Posted By: tfabris
The corresponding version of that for coding on the empeg itself would be that any characters received from /dev/ttyS1 would be echoed to ...


Standard Output (stdout). Aka. File Descriptor number 1. Aka. The default destination of printf() or putchar(). This is open and available on program startup, without the need to explicitly open() it, and normally maps to whatever "terminal" (tty) session (serial, ssh, telnet, an xterm window, etc..) from which the program was launched.

So, like this:
Code:

int read_and_echo (void)
{
        char c;
        int fd = open("/dev/ttyS1", O_RDWR);

        if (fd == -1) {
                perror("/dev/ttyS1");
                exit(1);
        }

        while (1 == read(fd, &c, 1)) {
                putchar(c);  /* stdout: could be anything, and we don't care! */
                fflush(stdout);
        }
        close(fd);
}


Edited by mlord (04/11/2017 17:38)