ts-7000
[Top] [All Lists]

Re: [ts-7000] Re: Help connecting to GPS on com2

To:
Subject: Re: [ts-7000] Re: Help connecting to GPS on com2
From:
Date: Mon, 26 Feb 2007 22:52:49 -0500
>> I am a newbie to the 7250 as well as to linux. I need to read a rs232 
>> signal from my com2 port and have tried lots of code from online 
>> guides with no sucess so I turned to this group and found this post 
>> and have used the code displayed below. I have even commented out the 

The program is not a good example because it is fundamentally broken.
The most serious problem is here:

>>>> int read_port(int file_id)
>>>> {
>>>>    char            buffer[512];
>>>>    int             count=0;
>>>>    int             lines = 0;
>>>>
>>>>    while(lines < 50)
>>>>    {
>>>>            read(file_id, buffer, count);

Here, count=0 so it is asking to read zero bytes from the serial port.
Of course, if you ask for nothing, you will get nothing.

read() returns the number of bytes actually read, which is ignored
by this program.

It should say something like:
        count = read( file_id, buffer, sizeof(buffer)-1 );
        if (count < 0)
                { /* look at errno to see what error occured */ }
        if (count == 0)
                { /* there were no bytes to read */ }
        if (count > 0)
                { /* you can use the bytes in buffer */ }

I say sizeof(buffer)-1 so it asks for at most 511 bytes.  That
way buffer[count]='\0' does not overflow the array if you get as
many bytes as you asked for.

It might be helpful to read some of the serial port tutorials on the web.
A brief search found a couple that don't look too bad:
http://www.faqs.org/docs/Linux-HOWTO/Serial-Programming-HOWTO.html
http://www.easysw.com/~mike/index.php?serial/serial.html+printable

Linux is POSIX compliant.  If you need help with Linux programming,
just about any book about programming in C for POSIX, Unix or Linux
systems can be useful.



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Great things are happening at Yahoo! Groups.  See the new email design.
http://us.click.yahoo.com/lOt0.A/hOaOAA/yQLSAA/CFFolB/TM
--------------------------------------------------------------------~-> 

 
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