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?
puts vs iprintf
-
- Posts: 513
- Joined: Sat Apr 26, 2008 7:14 am
Re: puts vs iprintf
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:
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
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
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
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();
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
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
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

Re: puts vs iprintf
very strange, puts and iprintf have the same USER_ENTER_CRITICAL and interrupt restrictions.
I can't recreate this, very bizare....
I can't recreate this, very bizare....