ts-7000
[Top] [All Lists]

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

To:
Subject: Re: [ts-7000] not able to read data through com2 in TS7200
From: "Alvaro Aguirre" <>
Date: Sat, 18 Nov 2006 16:38:27 -0300
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.

Cheers,
Alvaro


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


__._,_.___


SPONSORED LINKS
Single board computer Hardware Computer running slow
Linux os Single board

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