1 Reply Latest reply on Jun 15, 2015 12:33 AM by keerthi.gowda

    for use w/_write(), how to create new FILE object for use with fprintf

    content.librarian

      I've over-ridden the _write() function so that printf output is directed to a device (one of several UARTs) of my choosing.  The _write() method takes a file descriptor int which is used to specific which device the output is bound for.  

         

      However, I have several 'devices' that I'd like to send output to with fprintf, thus think I need to create a FILE object and set the file descriptor.  Unfortunately, calling fprintf with my own FILE objects is resulting in a call to _write().  I've even tried to copy stderr as follows without success.

         

      Any ideas?

         

      Thanks,

         

      Chris

         

      main() {

         

      FILE fobj;

         

      memcpy(&fobj, stderr, sizeof(FILE))

         

      fobj._file = FD_UART_2;

         

      fprintf(&fobj,"something\n");

         

       } // main

         

       

         

      int _write(int file, char *ptr, int len) {

         

        LED_Y_Write(~LED_Y_Read()); // how I know its not getting called w/fprintf

         

       

         

      switch(file) {

         

        case stdout: 

         

        case stderr :

         

        UART_1_PutArray(ptr, len); 

         

        break;

         

      case FD_UART_2 : 

         

        UART_2_PutArray(ptr, len);

         

      break;

         

        } // switch
       

         

      } // _write