[En-Nut-Discussion] Thanx for Help Harald,i have one more question

saime aley saime.aley at gmail.com
Fri Mar 3 20:56:35 CET 2006


Hi Harald,

Thanx for nice tip, i studied that, and it is really nice,

But actually i didnt connect the network cable, i just wanted to check with the
serial cable, i mean with RS232, and UART is also connected with that,

But i can not get any output,, i didnt any network cable just simple
serial cable
and started , Terminal Emulation Software,,,

as in this example , stdout is being put at the UART..

Could you tell me the behaviour of program and also, can you also give me
link of some code which i only can use for the Terminal output not at LAN output
as a biggining to check the things,

I am really grateful to you for this help, it is really helping,
I look forward to hearing from you.

at bottom i am copying the code where it is putting stdout to UART.
and after that ,,it is putting all the thing at stream and to the ethernet..

Saime

int main(void)
{
    TCPSOCKET <http://www.ethernut.de/api/structtcp__socket.html> *sock;
    FILE *stream;
    u_long <http://www.ethernut.de/api/group__xgNutOS.html#ga3> baud = 115200;
    u_char <http://www.ethernut.de/api/group__xgNutOS.html#ga0> mac[6]
= { 0x00, 0x06, 0x98, 0x00, 0x00, 0x55 };

    /*
     * Register all devices used in our application.
     */
    NutRegisterDevice
<http://www.ethernut.de/api/group__xgDevice.html#ga6>(&DEV_DEBUG, 0,
0);
    NutRegisterDevice
<http://www.ethernut.de/api/group__xgDevice.html#ga6>(&DEV_ETHER,
0x8300, 5);

    /*
     * Assign stdout to the UART device.
     */
    freopen <http://www.ethernut.de/api/group__xgCrtStdio.html#ga25>(DEV_DEBUG_NAME,
"w", stdout);
    _ioctl <http://www.ethernut.de/api/group__xgCrtLowio.html#ga2>(_fileno
<http://www.ethernut.de/api/group__xgCrtStdio.html#ga14>(stdout),
UART_SETSPEED, &baud);
    printf_P <http://www.ethernut.de/api/group__xgCrtStdio.html#ga37>(vbanner_P,
NutVersionString
<http://www.ethernut.de/api/group__xgNutVersion.html#ga1>());
#ifdef NUTDEBUG    NutTraceTcp(stdout, 1);
    NutTraceOs(stdout, 0);
    NutTraceHeap(stdout, 0);
    NutTracePPP(stdout, 0);
#endif
    NutNetLoadConfig
<http://www.ethernut.de/api/if__var_8h.html#a8>(DEV_ETHER_NAME);
    memcpy(confnet.cdn_mac
<http://www.ethernut.de/api/struct__CONFNET.html#o2>, mac, 6);
    NutNetSaveConfig <http://www.ethernut.de/api/if__var_8h.html#a9>();

    /*
     * Setup the ethernet device. Try DHCP first. If this is
     * the first time boot with empty EEPROM and no DHCP server
     * was found, use hardcoded values.
     */
    printf <http://www.ethernut.de/api/group__xgCrtStdio.html#ga36>("Configure
eth0...");
    if (NutDhcpIfConfig
<http://www.ethernut.de/api/group__xgDHCPC.html#ga28>("eth0", 0,
60000)) {
        printf <http://www.ethernut.de/api/group__xgCrtStdio.html#ga36>("initial
boot...");
        if (NutDhcpIfConfig
<http://www.ethernut.de/api/group__xgDHCPC.html#ga28>("eth0", mac,
60000)) {
            u_long
<http://www.ethernut.de/api/group__xgNutOS.html#ga3> ip_addr =
inet_addr <http://www.ethernut.de/api/group__xgIP.html#ga7>("192.168.192.100");
            u_long
<http://www.ethernut.de/api/group__xgNutOS.html#ga3> ip_mask =
inet_addr <http://www.ethernut.de/api/group__xgIP.html#ga7>("255.255.255.0");

            printf
<http://www.ethernut.de/api/group__xgCrtStdio.html#ga36>("no
DHCP...");
            NutNetIfConfig
<http://www.ethernut.de/api/group__xgIP.html#ga5>("eth0", mac,
ip_addr, ip_mask);
            /* If not in a local network, we must also call
               NutIpRouteAdd() to configure the routing. */
        }
    }
    puts <http://www.ethernut.de/api/group__xgCrtStdio.html#ga42>("OK");
    printf <http://www.ethernut.de/api/group__xgCrtStdio.html#ga36>("IP:
%s\n", inet_ntoa
<http://www.ethernut.de/api/group__xgIP.html#ga8>(confnet.cdn_ip_addr
<http://www.ethernut.de/api/struct__CONFNET.html#o3>));

    /*
     * Now loop endless for connections.
     */
    for (;;) {
        /*
         * Create a socket.
         */
        if ((sock = NutTcpCreateSocket
<http://www.ethernut.de/api/group__xgTcpSocket.html#ga7>()) != 0) {
            /*
             * Listen on port 23. If we return, we got a client.
             */
            printf
<http://www.ethernut.de/api/group__xgCrtStdio.html#ga36>("Waiting for
a telnet client...");
            if (NutTcpAccept
<http://www.ethernut.de/api/group__xgTcpSocket.html#ga11>(sock, 23) ==
0) {
                puts
<http://www.ethernut.de/api/group__xgCrtStdio.html#ga42>("connected");

                /*
                 * Open a stream and associate it with the socket, so
                 * we can use standard I/O. Note, that socket streams
                 * currently do support text mode.
                 */
                if ((stream = _fdopen
<http://www.ethernut.de/api/group__xgCrtStdio.html#ga8>((int) sock,
"r+b")) != 0) {
                    /*
                     * Process client requests.



More information about the En-Nut-Discussion mailing list