ts-7000
[Top] [All Lists]

[ts-7000] Re: Failure to read serial comm on TS-7300

To:
Subject: [ts-7000] Re: Failure to read serial comm on TS-7300
From: "shusshinchi" <>
Date: Wed, 13 Oct 2010 04:44:35 -0000


Yes, this is C++. But nevermind the language and syntax, it`s not important at all. The code here is not production code. It`s just a testing program to make sure I`m able to communicate over the serial ports before I do anything for the production code. Ok, actually I`ve tried several variations of the code I posted while trying to get it to work. I do get EAGAIN. And yes, I`ve tried issuing read again after doing sleep, and of course I get nothing. I`ve also tried to use blocking mode, to which I also get nothing. The last variation I tried (and optimistic to say, with partial success) is where I perform a write and read repeatly, and then closing and opening the port again after each write and read. Doing this, I managed get the correct and expected data with every other read. Wonder why...

int main ( int argc, char** argv )
{
    for ( ; ; )
    {
        int fd = open ( argv[1], O_RDWR | O_NOCTTY | O_NDELAY ) ;
        termios port_settings ;

        cout << "fd = " << fd << endl ;

        memset ( &port_settings, 0, sizeof port_settings ) ;
        cfsetispeed ( &port_settings, B9600 ) ;
        cfsetospeed ( &port_settings, B9600 ) ;

        port_settings.c_cc[VMIN] = 0 ;
        port_settings.c_cc[VTIME] = 10 ;

        port_settings.c_iflag &= ~ICRNL ;
        port_settings.c_cflag &= ~PARENB ;
        port_settings.c_cflag &= ~CSTOPB ;
        port_settings.c_cflag &= ~CSIZE ;
        port_settings.c_cflag |= CRTSCTS ;
        port_settings.c_cflag |= CS8 ;
        port_settings.c_cflag |= CREAD ;
        port_settings.c_cflag |= CLOCAL ;

        tcsetattr ( fd, TCSANOW, &port_settings ) ;
        tcflush ( fd, TCIOFLUSH ) ;

        char output[ ] = { 0x06, 0x01, 0x00, 0x00, 0x00, 0x10, 0x3c, 0x71 } ;
        int wResult ;
        char cA[8] ;
        int r ;

        memset ( cA, 0, 8 ) ;

        cA[7] = '\0' ;
        wResult = write ( fd, output, 8 ) ;

        cout << "Bytes written = " << wResult << endl ;

        if ( wResult == -1 )
        {
            switch ( errno )
            {
                case EAGAIN : cout << "eagain" << endl ; sleep ( 1 ) ; break ;
                case EBADF : cout << "ebadf" << endl ; break ;
                case EFAULT : cout << "efault" << endl ; break ;
                case EINTR : cout << "eintr" << endl ; break ;
                case EINVAL : cout << "einval" << endl ; break ;
                case EIO : cout << "eio" << endl ; break ;
                case ENOSPC : cout << "enospc" << endl ; break ;
                case EISDIR : cout << "eisdir" << endl ; break ;
                case EPIPE : cout << "epipe" << endl ; break ;
                default : cout << "errno = " << errno ;
            }
        }

        cout << "Zzzzzzzz.........." << endl ;

        usleep ( 500000 ) ;

        cout << "Awaken..." << endl ;
        cout << "Bytes read = " << ( r = read ( fd, cA, 7 ) ) << endl ;

        if ( r == -1 )
        {
            switch ( errno )
            {
                case EAGAIN : cout << "eagain" << endl ; sleep ( 1 ) ; break ;
                case EBADF : cout << "ebadf" << endl ; break ;
                case EFAULT : cout << "efault" << endl ; break ;
                case EINTR : cout << "eintr" << endl ; break ;
                case EINVAL : cout << "einval" << endl ; break ;
                case EIO : cout << "eio" << endl ; break ;
                case EISDIR : cout << "eisdir" << endl ; break ;
                default : cout << "errno = " << errno ;
            }
        }

        for ( int x = 0 ; x < 8 ; ++x )
        {
            cout << dec << static_cast<short>( cA[x] ) << "\t"
                << hex << static_cast<short>( cA[x] ) << "\t"
                << cA[x] << endl ;
        }

        cout << "\n---END---" << endl ;

        sleep ( 1 ) ;
    }
}

 
Not sure if it`s worth noting, but this is the first time I`m using anything from Technologic Systems. So I`m not farmiliar with the stuff yet. Is there anything specific to TS-7300 that must be done to use the serial ports? 


__._,_.___


Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: =Email Delivery: Digest | m("yahoogroups.com?subject","ts-7000-fullfeatured");=Change Delivery Format: Fully Featured">Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | =Unsubscribe

__,_._,___
<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