ts-7000
[Top] [All Lists]

Re: [ts-7000] COM2 serial problem on TS-7260

To:
Subject: Re: [ts-7000] COM2 serial problem on TS-7260
From: Jim Jackson <>
Date: Wed, 13 Oct 2010 19:55:23 +0100 (BST)


On Tue, 12 Oct 2010, yetanotherdjmorris wrote:

> I have a TS-7260 trying to communicate with an RS232 device (a motor).
> I can open my port, set my baud, send data to the device, the motor moves, 
> sends a response back, which I can read.
> Then I start a polling loop where I continually call
> iReturn = ioctl(fd, FIONREAD, &iBytesAvail)

waste of time - just do a read on the device. If there is data you will 
read it, if there is not you will get an error with errno = EAGAIN
when you can wait for your 20ms. This works. I interface to several serial 
devices for gathering weather data.

> and then sleep for 20ms.
> Eventually (like after 100 iterations), this returns -1
> with an errno = EIO  (input/output error).
> I can close the port and reopen and it works, but again, only for a few 
> seconds before I get that error again.
> 
> Any thoughts?
> 
> source code:
> int fd = open("/dev/ttyAM1", O_RDWR | O_NOCTTY | O_NDELAY);
>       if (fd == -1)
>       {
>               printf("fail opening\n");
>               return -1;
>       }
> 
>     struct termios port_settings;
>     
>     cfsetispeed ( &port_settings, B9600 ) ;
>     cfsetospeed ( &port_settings, B9600 ) ;
> 
>     port_settings.c_cc[VMIN] = 0 ;
>     port_settings.c_cc[VTIME] = 0 ;
> 
>       port_settings.c_iflag=0;  // no input processing
>       port_settings.c_oflag=0;  // no output processing
>       port_settings.c_lflag=0;  
>       port_settings.c_cflag=189; //8N1, 9600 baud
>       
> 
>     tcflush( fd, TCIOFLUSH ) ;
>       tcsetattr ( fd, TCSANOW, &port_settings ) ;
>       tcgetattr (fd, &port_settings);  // make sure that the settings were 
> accepted
> 
>       printf("%d %d %d %d\n", port_settings.c_cflag, port_settings.c_lflag, 
> port_settings.c_iflag, port_settings.c_oflag);
>       
>         int iCount=0;
>       int iBytesAvail, iReturn;
> 
>       unsigned char command[6]={0,2,0,0,0,0};  //packet to tell my motor to 
> return home
> 
>       
>       //command[0]=1;
>       //command[1]=55; //echo
>       //command[2]=254;
> 
>       iReturn=write(fd, command, 6);
>       printf("written\n");
>       sleep(2);
>       iReturn = ioctl(fd, FIONREAD, &iBytesAvail);  //checks the file 
> described by iFileDescriptor to see how many bytes are available, stores in 
> iBytesAvail
>       printf("%d bytes avail\n", iBytesAvail);
>       if (iBytesAvail >=6) {
>               iReturn = read(fd, &command, 6);
>               printf("%d bytes read\n", iReturn);
>       }
> 
>       while (iCount<1000) {
>               usleep(20000);
>               iReturn = ioctl(fd, FIONREAD, &iBytesAvail);  
>               if (iReturn==-1) {
>                       printf("Error: %d. %s\n", errno, strerror(errno));
>                       return -1;
>               }
>               printf("%d\n", ++iCount);
>       }
>       close(fd);
>       return 0;
> }
> 
> output:
> ------------------------
> yes?
> 189 0 0 0
> 189 0 0 0    <--- settings are  as expected
> written      <--------wrote the data
> 12 bytes avail  <----response is available
> 6 bytes read    <----- read the first half of it
> 6 bytes read    <----- read the second half of it
> 1 
> 2             <-----------waiting for more data
> 3
> ...
> 284
> 285
> Error: 5. Input/output error      <------- EIO
> 
> 
> 


------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ts-7000/join
    (Yahoo! ID required)

<*> To change settings via email:
     
    

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/

<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU