redirecting stdout and stdin to device otherthan a UART

Discussion to talk about software related topics only.
Post Reply
xenon68
Posts: 4
Joined: Tue May 12, 2009 3:12 pm

redirecting stdout and stdin to device otherthan a UART

Post by xenon68 »

i am looking for a way to redirect the standard I/O to use something other than the netburner serial ports. I have found the examples of:

int fdserial_debug=OpenSerial(DEBUG_SERIAL_PORT,
DEBUG_BAUDRATE,
DEBUG_STOP_BITS,
DEBUG_DATA_BITS,
eParityNone);

ReplaceStdio(1,fdserial_debug); // 0=stdin, 1=stdout, 2=stderr
printf("No we're using printf()!\r\n");

But, I don't see an example if I want to use a device otherthan a Uart. In my case, i want the stdout to go my own function that will put the output into a memory device.
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: redirecting stdout and stdin to device otherthan a UART

Post by rnixon »

There is a section on this in the network programmers guide, including custom fd implementations:

File Descriptors
16.1
Overview
A file descriptor is a handle to a network socket, serial port or other system peripheral. May of the API functions pass a file descriptor to your application functions, such as the web server MyGet function example in this guide.
There are a maximum of 64 file descriptors:
•0 – 2 for stdin, stdout and stderr
•3 – 4 for the first two UART serial ports, 0 and 1.
•5 – 37 for TCP (32 in total)
•38 – 63 for expansion (additional UARTs, TCP sockets, or custom)

16.2
Creating Custom I/O Drivers Using File Descriptors
The header file in \nburn\include\iointernal.h defines the programming interface functions to create a custom file descriptor.

etc etc ........
xenon68
Posts: 4
Joined: Tue May 12, 2009 3:12 pm

Re: redirecting stdout and stdin to device otherthan a UART

Post by xenon68 »

I am missing something then. I have seen this in the manual before, but I don't see how to replace the first 3 file descriptors, stdin, stdout, stderr. With my own file descriptor... Do I use the ReplaceStdio function to then reassign the current stdout with my custom file descriptor?

I basically would like to use printf, putchar, getchar to use my own device not the serial port...
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: redirecting stdout and stdin to device otherthan a UART

Post by rnixon »

yes
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: redirecting stdout and stdin to device otherthan a UART

Post by tod »

Did you see the fdprintf example in the Nburn/examples folder? You may have a good reason to change the behavior of printf but if not pity the poor maintenance programmer who comes after and see if using calls to fdprintf() wouldn't work just as well.
Post Reply