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/
|