Page 1 of 1

Formatted I/O

Posted: Thu Mar 23, 2017 11:31 am
by addonray
Hi,

Is there any way (other than dealing with putchar() replacement directly) to do formatted output (via fdprintf, etc.) through a low level function of my own? I'm moving an older UART based project to use an FTDI async FIFO (8 bit bus) USB IC. There is a ton of formatted output code already in play. With the Rabbit Softools compiler, there was an Fassign function that let you point a file descriptor at any function, avoiding putchar() completely for any given descriptor. I remember with the Keil tools, I had to directly manipulate putchar(). How would I best address this with the NB tools?
:?
Thanks,

Ray

Re: Formatted I/O

Posted: Thu Mar 23, 2017 12:02 pm
by sulliwk06
If I understand correctly, I think you can accomplish what you want by creating your own file descriptor GetExtraFD (in iointernal.h). You create an IoExpandStruct and define your own read, write, and close functions for that file descriptor. I used this method for creating file descriptors for an external quad uart chip.

Re: Formatted I/O

Posted: Thu Mar 23, 2017 12:44 pm
by addonray
That looks like it's exactly what I need! There was nothing in the docs about it. Do you recall if they had any example code anywhere?

Thanks!

Ray

Re: Formatted I/O

Posted: Fri Mar 24, 2017 5:03 am
by sulliwk06
No I don't think I ever found any examples, I just used the system library as a reference, there were a few places where they used that.

Re: Formatted I/O

Posted: Fri Mar 24, 2017 6:00 am
by addonray
Thank you! I'll search by function names there.