Thread: Linux ser comm file descriptor problem...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    3

    Linux ser comm file descriptor problem...

    Hi,
    I have a configuration consisting of:

    1. my Atmega168 MCU connected to some servo motors and sensors, and
    2. my Linksys WRT54GL router working under OpenWRT Linux WhiteRussian 9.
    3. they have a working and tested serial connection.

    Now my problem.
    I open a file descriptor to my serial port called /dev/tts/1, and read a sensor (the second sensor commented, as you see bellow). This works perfect. Then I uncomment the next sensor, but the code continues to behave as if I didn't uncomment it!

    If before the reading of the next sensor I first close my original file descriptor and reopen it, it starts to work right, but this is inefficient, as I have various sensors and it is not logical to open and close port for each of them!

    Reading Ultrasonic first, and then Digital encoders or vice versa makes no difference.

    The code in my MCU is fairly simple and tested. It does nothing but read/write as Linux commands.

    How can I approach to reveal where the problem is?

    Linux code:
    Code:
    //motorController opens "/dev/tts/1" serial port.
       bzero(buffer,256);
        
       while(1==1)
       {
         fprintf(motorController, "@sp\n" ); //s:sensor, p:ping.
         fscanf(motorController, "%s", buffer);
         printf("Ping: %s\n", buffer);
    
         bzero(buffer,256);
    
    /*
         fprintf(motorController, "@sel\n" ); //e: encoder, l:left.
         fscanf(motorController, "%s", buffer);
         printf("Left Encoder: %s\n", buffer);
    
         bzero(buffer,256);
    */
       }
        
       fclose(motorController);
       return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    See manpage of select(), which allows you to poll several peripherals and multiplex I/O from them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  5. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM