Function 1:
void debug_printf(const char *degmsg, ... ) { int old = dup(STDOUT); int ttyfd ; int ret; va_list ap; char msg[512]; ttyfd = open("/dev/ttyS0", O_RDWR); va_start(ap,degmsg); ret = vsprintf(msg,degmsg,ap); va_end(ap); dup2(ttyfd, STDOUT); close(ttyfd); printf("%s",msg); dup2(old, STDOUT); }
Function 2:
void debug_printf(const char *degmsg, ... ){ va_list ap; int ret; FILE *con_ptr; char msg[512]; va_start(ap,degmsg); ret = vsprintf(msg,degmsg,ap); va_end(ap); con_ptr = fopen("/dev/ttyS1","w+");; if (!con_ptr) { perror("fopen"); } fprintf(con_ptr,"%s",msg); fflush(con_ptr); fclose(con_ptr); }