Page 1 of 1

puts vs iprintf

Posted: Mon Nov 12, 2012 7:02 pm
by greengene
i have done the 3 ReplaceStdio.
the output from "iprintf' comes out the serial port.
the output from "puts" does not.
using MOD5270 and NNDK2.53
any ideas?

Re: puts vs iprintf

Posted: Mon Nov 12, 2012 9:24 pm
by Ridgeglider
I think the recommended procedure is to call SerialClose() to shut down the default polled serial IO. Then call OpenSerial() on the same com port (0, 1, or 2) to get an fd for an interrupt-driven port. Then, using the fd, call ReplaceStdio. If you don't close down the default polled port before getting the fd, ReplaceStdio() acts unpredictably. I think the SerialClose() call happens automatically during ReplaceStdio() in later releases.

That said, in the example below, puts() seems to work for at least the first time whether or not SerialClose() is called.
This works on the latest release:

Code: Select all

#include "predef.h"
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <stdio.h>
#include <serial.h>		// OpenSerial, SerialClose, ReplaceStdio

extern "C" {
void UserMain(void * pd);
}

const char * AppName="5270_AppWiz";

void UserMain(void * pd) {
    InitializeStack();
    if (EthernetIP == 0) GetDHCPAddress();
    OSChangePrio(MAIN_PRIO);
    EnableAutoUpdate();
    StartHTTP();

    SerialClose(0);

    int fd = OpenSerial(0, 115200, 1, 8, eParityNone );
    ReplaceStdio(0, fd);   
    ReplaceStdio(1, fd);
    ReplaceStdio(2, fd);


    iprintf("Application started: %s\n", AppName);
    puts("Hi there\r\n");

    while (1) {
    	OSTimeDly( 20 );
    }
}

Re: puts vs iprintf

Posted: Tue Nov 13, 2012 5:14 am
by greengene
thanks for the reply.
i have puts elsewhere that work fine - for years. i've recently added some new puts in place of iprintfs since there wasn't any formatting (and it looks purtier) when i encountered this problem. i'm running 2.5.3+.

here's the snippet of code that i've used for years:
// use interrupt rather than polling for the debug/serial port [24sep08]
SerialClose( 0 ); // close UART 0
fdSerial = OpenSerial( 0, 115200, 1, 8, eParityNone );
ReplaceStdio( 0, fdSerial ); // stdin
ReplaceStdio( 1, fdSerial ); // stdout
ReplaceStdio( 2, fdSerial ); // stderr

Re: puts vs iprintf

Posted: Tue Nov 13, 2012 9:14 am
by pbreed
puts should work fine... you aren't in a USER_ENTER_CRITICAL or interrupt block are you?

Just note... we added a function a few releases ago to make this switch easier....

//Automatically open the system default serial port in interrupt mode
//using the system default baudrate
//And assign this serial port to stdin, stdout and stderr.

void IrqStdio();

Re: puts vs iprintf

Posted: Wed Nov 14, 2012 5:43 pm
by greengene
i didn't know that puts and iprintf would work differently in a USER_ENTER_CRITICAL or interrupt block. i'm not using them there, but maybe whatever those difference are would be germane to what i'm seeing.

regardless, i replaced those particular "puts" with "iprintf" and all is fine. that just seemed odd.

maybe someone else has seen it or would just like to 'should' on me :D

Re: puts vs iprintf

Posted: Thu Nov 15, 2012 8:04 am
by pbreed
very strange, puts and iprintf have the same USER_ENTER_CRITICAL and interrupt restrictions.

I can't recreate this, very bizare....