Hi Rob,
Apart from any issues that you may have with "getty" processes
running on the COM that you are trying to talk to the GPS with,
there are problems with your code.
In the function below...
> int read_port(int file_id)
> {
> char buffer[512];
> int count=0;
> int lines = 0;
>
> while(lines < 50)
> {
> read(file_id, buffer, count);
> lines++;
> /* Add terminator and print if non-zero */
> if(count > 0)
> {
> buffer[count] = '\0';
> printf("Line %d has %d characters\n", lines,
count);
> printf("%s\n", buffer);
> }
> else
> {
> printf("Zero characters read\n");
> }
> }
> }
You are using the "read()" function incorrectly. What you would
probably be after is more this...
> count = read(file_id, buffer, 512);
In your code you were actually asking for 0 (the value in 'count')
bytes to be read from the com port so that was what it was giving
you. Plus the value in count would never have changed anyway,
because that 3rd parameter to read() is just an input.
Also, you probably need to make some changes to your port
initialisation code below...
> void port_configuration(int file_id)
> {
> struct termios options;
> int x;
>
> tcgetattr (file_id, &options);
> printf("speed in %d out %d\n", options.c_ispeed,
options.c_ospeed);
> printf("mode in %d out %d\n", options.c_iflag,
options.c_oflag);
> printf("control flag %d\n", options.c_cflag);
> printf("local flag %d\n", options.c_lflag);
>
> cfsetispeed(&options, B4800);
> cfsetospeed(&options, B4800);
> options.c_cflag = 2096;
> options.c_lflag = 4;
> options.c_oflag = 0;
> options.c_cflag |= (CLOCAL | CREAD);
> options.c_cflag &= ~PARENB;
> options.c_cflag &= ~CSTOPB;
> options.c_cflag &= ~CSIZE;
> options.c_cflag |= CS8;
> options.c_cflag &= ~CRTSCTS;
> tcsetattr (file_id, TCSANOW, &options);
> }
Most implementations, including the TS boards as far as I know,
store the baud rate setting in the 'cflag' member. So in your code
above, the baud rate setting gets wiped straight away by setting
cflag. Also, with setting the flags to values (like 2096 and 4) and
then doing & and | operations makes it a bit hard to understand. And
it appears that the port would be in 'non-canonical' mode, which
means you wont get the input in a line-by-line form. Maybe try
something like the following.
> options.c_cflag = CLOCAL | CREAD | CS8;
> options.c_lflag = ICANON;
> options.c_iflag = 0;
> options.c_oflag = 0;
> cfsetispeed(&options, B4800);
> cfsetospeed(&options, B4800);
> tcsetattr (file_id, TCSANOW, &options);
Depending on the actual output of the GPS (eg. whether it terminates
lines with CR or LF) you may need to adjust the above or some other
members of the termios structure.
Google for 'man termios' (if you haven't already) for information on
the above functions and structures.
Hope this helps!!
Cheers
Phil
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/
|