ts-7000
[Top] [All Lists]

[ts-7000] Re: not able to read data through com2 in TS7200

To:
Subject: [ts-7000] Re: not able to read data through com2 in TS7200
From: "soniathakur3" <>
Date: Sat, 18 Nov 2006 22:05:45 -0000




--- In  "Alvaro Aguirre" <>
wrote:
>
> Sonia:
> I don't mean to be rude but unless you know what you are doing we
can't help
> you fixing your code every time because you are the only person who
knows
> what you really need. I can send you code to open the serial port
and read
> it but if you need to read the serial port do you know where to
stop? at a
> new line? at a specific number of characters? blocking? nonblocking?
> 
> You must understand and code what do you really need. You can use:
> -Google
> -The Linux Documentation Project
> -Language C from K&R
> -
>
http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/pdf/Serial-Programming-HOWTO.pdf
> -http://www.easysw.com/~mike/serial/serial.html
> 
> In the case of the code you send you are checking the amount of data
waiting
> on the serial port with ioctl, and you code EXPLICITLY
> 
> ioctl(fd,FIONREAD, &count);
> if(count <= 0) return 0;
> 
> And that's why you are getting: "the error is : 0"... as you code.
> If you need further guidance you can write me directly to my email
and I'll
> do everything I can.

Thank you for your website link.It has the info that i needed.
I think i can do it now.
thanks
sonia


> 
> 
> On 11/18/06, soniathakur3 <> wrote:
> >
> >
> > hi,
> >
> > I have a gps module which i am interfacing with the com2 on TS7200.The
> > code i am using is :
> >
> > #include <unistd.h>
> > #include <sys/types.h>
> > #include <stdio.h>
> > #include <fcntl.h>
> > #include <sys/ioctl.h>
> > #include <termios.h>
> > #include <stdlib.h>
> > #include <string.h>
> > #include <sys/stat.h>
> > #include <sys/uio.h>
> > #include <errno.h>
> >
> > int open_port(char* device_name)
> > {
> > int fd;
> > fd = open(device_name, O_RDWR | O_NOCTTY| O_NDELAY);
> > if(fd == -1)
> > {
> > printf("Failed to open device \n");
> > }
> > return fd;
> > }
> >
> > int read_port(int fd)
> > {
> > char buffer[512];
> > int count = 0;
> > int lines;
> > while (lines < 80)
> > {
> > ioctl(fd,FIONREAD, &count);
> > if(count <= 0) return 0;
> > count =read(fd, buffer,512);
> >
> > printf("the count is: %d\n",count);
> > lines = lines + 1;
> > /* Add terminator and print if non-zero */
> > if(count > 0)
> > {
> > buffer[count] = '0\n';
> > printf("%s\n",buffer);
> > }
> > else
> > {
> > printf("Zero characters read\n");
> > }
> > }
> > }
> > void port_configuration(int fd)
> > {
> > struct termios options;
> > fcntl(fd, F_SETFL, FNDELAY);
> > tcgetattr(fd, &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);
> >
> > options.c_cflag |=(CLOCAL|CREAD);
> > options.c_cflag &= ~PARENB;
> > options.c_cflag &= ~CSTOPB;
> > options.c_cflag |= CS8;
> > options.c_cflag &= ~CRTSCTS;
> > cfsetispeed(&options,B4800);
> > cfsetospeed(&options,B4800);
> >
> > /* Enable data to be processed */
> > options.c_lflag &= ~(ICANON | ECHO | ECHOE |ISIG);
> > options.c_iflag &= ~(IXON | IXOFF | IXANY);
> > options.c_oflag &= ~ OPOST;
> > tcsetattr(fd, TCSANOW, &options);
> > }
> >
> > int main(int argc, char*argv[])
> > {
> > extern int errno;
> > int fd;
> > /* check the command */
> > if(argc < 2)
> > {
> > printf("serial_tester<device>\n");
> > return 0;
> > }
> > /* Open the port */
> > printf("Opening device %s\n", argv[1]);
> > fd = open_port(argv[1]);
> > printf("the fd id is : %d\n",fd);
> > /* Get port configuration */
> > port_configuration(fd);
> >
> > /* Set the port to non blocking and read the port */
> > read_port(fd);
> > printf("the error is : %d\n",errno);
> >
> > close((fd));
> > return 0;
> > }
> > and the result that i get is :
> > $ ./test /dev/ttyAM1
> > Opening device /dev/ttyAM1
> > the fd id is : 3
> > speed in 717120476 out 35296
> > mode in 256 out 4
> > control flag 3260
> > local flag 35360
> > the error is : 0
> >
> > could someone help me and tell me what the problem is? I am a novice
> > and have very less knowledge of linux.
> >
> > thanks
> > sonia
> >
> >  
> >
>





 
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