[En-Nut-Discussion] Problems with rs232d-example (2nd try)

Bernd Faulstich bernd.faulstich at philips.com
Tue Nov 15 12:45:24 CET 2005


Hello Ethernut-User,

I have a Problem with the RS232-example.
If I send Data (20 Byte) over TCP in a Loop, I get them back over RS232 
without problems. Tried it for 16 h.
If I send the same Bytes over RS232, I get them back for various times. 
After 71sec/231sec/503sec it stops. 
In Etherreal there are only [unreassembled packet]s from the ethernut.
The last TCP-packets are:

Board -> PC: AX4000 3357>1741 [PSH,ACK] ... [unreassembled packet] + 
(Data)
Board -> PC: AX4000 3357>1741 [PSH,ACK] ... [unreassembled packet] + 
(Data)
PC -> Board: TCP 1741>3357 [ACK] ...

Then the Board sends nothing else until rebooting it.

If I disconnect the first TCP-Connection before it hangs and start the 
TCP-connection a second time, the Board reboots and waits for a new 
connection. 
Then i can connect again. The fourth time it reboots again. Fifth time I 
can connect, and so on.

I use OS "3.9.8.2" with a ethernut 2.1 Rev B -Board.
I modified rs232d-example because i don't use DHCP.

? Is there a Bug in the for-loop (following) with some TCP close- or 
open-commands or at th OS or ...?
? How i can ensure full Xmit-funktion for longer time?
? What can I do to fix it? 
? Older OS? Newer OS?
? Or is this problem in progress ?

I Think it's the original Example... but here is the code of the main 
funktion:

int main(void)
{
                TCPSOCKET *sock;
                CHANNEL cd;
        u_long baud = 115200;

            /*
             * Register our devices.
             */
        NutRegisterDevice(&devUart0, 0, 0);
        NutRegisterDevice(&DEV_ETHER, 0x8300, 5);

            /*
                 * Setup the uart device.
                 */
                cd.cd_rs232 = fopen("uart0", "r+b");
                _ioctl(_fileno(cd.cd_rs232), UART_SETSPEED, &baud);

                /* No valid EEPROM contents, use hard coded MAC. */
                u_char my_mac[] = { 0x00, 0x06, 0x98, 0x21, 0x09, 0x15 };

        /* Use hard coded IP address. */
        u_long ip_addr = inet_addr("192.168.0.169");
        u_long ip_mask = inet_addr("255.255.255.0");

        NutNetIfConfig("eth0", my_mac, ip_addr, ip_mask);
        /* If not in a local network, we must also call 
        NutIpRouteAdd() to configure the routing. */
 
                /*
                 * Start a RS232 receiver thread.
                 */
                 NutThreadCreate("xmit", Receiver, &cd, 512);

                cd.cd_connected = 0;

                /*
                 * Now loop endless for connections.
                 */
                for (;;) {

                        /*
                         * Create a socket and listen for a client.
                         */
                        sock = NutTcpCreateSocket();
                        NutTcpAccept(sock, TCPPORT);
 
                        /*
                         * Open a stdio stream assigned to the connected 
socket.
                         */
                        cd.cd_tcpip = _fdopen((int) sock, "r+b");
                        cd.cd_connected = 1;
 
                        /*
                         * Call RS232 transmit routine. On return we will 
be
                         * disconnected again.
                         */
                        StreamCopy(cd.cd_tcpip, cd.cd_rs232, 
&cd.cd_connected);

                        /*
                         * Close the stream.
                         */
                        fclose(cd.cd_tcpip);

                        /*
                         * Close our socket.
                         */
                        NutTcpCloseSocket(sock);

                }

}

Thanks for Ur help.
With kind regards, 

Bernd Faulstich


More information about the En-Nut-Discussion mailing list