cant able to read serial Port
- From: Devesh Here <devu_devesh@xxxxxxxxxxx>
- Date: Sat, 22 Sep 2007 14:21:13 +0530 (IST)
hello All,
i am very new in Linux , and i made a small program in C that jst sends and tries to receive character from serial port.
it is working fine for sending, but not receiving character from other end .. on other end Windows Xp running. Read() function retuns error
no = 11, i m putting my small code,
plz help me ...
thank in advance
CODE:
#include <stdio.h> /* Standard input/output definitions */
#include <string.h> /* String function definitions */
#include <unistd.h> /* UNIX standard function definitions */
#include <fcntl.h> /* File control definitions */
#include <errno.h> /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
int readport(int fd, char *result)
{
int iIn = read(fd, result, 254);
result[iIn-1] = 0x00;
if (iIn < 0) {
printf("SERIAL EAGAIN ERROR\n");
printf("\nerro NO =%d\n",errno);
printf("SERIAL read error %d-----> %s\n", errno, strerror(errno));
return 0;
}
return 1;
}
main()
{
int fd;
int nread;
char c;
char bufptr[5];
char buffer[5];
buffer[0]= 'S';
buffer[1]= 'S';
buffer[2]= 'S';
buffer[3]= 'S';
buffer[4]= 'S';
int i;
char sResult[254];
struct termios options;
// buffer = "Sorry";
fd = open("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NDELAY);
if (fd == -1)
{
printf("\n\n\t\t Sorry Yaar Port Nahi Khul Raha \n\n\n");
return 1;
}
else
{
printf("\n\n\t\t Port Khul gaya.... \n\n\n");
fcntl(fd, F_SETFL, 0);
}
tcgetattr(fd, &options);
cfsetispeed(&options, B9600);
cfsetospeed(&options, B9600);
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
tcsetattr(fd, TCSANOW, &options);
write(fd,"devesh",6);
usleep(500000);
/*
fcntl(fd, F_SETFL, FNDELAY);
nread = read(fd,buffer,5);
//if (nread < 0)
//write(2,"ERROR in read\n",20);
printf("\nnread = %d\n",nread);
printf("tong = %s\n",buffer);
close(fd);
*/
fcntl(fd, F_SETFL, FNDELAY); // don't block serial read
if (!readport(fd,sResult)) {
printf("read failed\n");
close(fd);
return 1;
}
printf("readport=%s\n", sResult);
close(fd);
return 0;
}
[DEV'H]
Devesh Sharma
"Have A Nice Time"
Bollywood, fun, friendship, sports and more. You name it, we have it on http://in.promos.yahoo.com/groups --
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
- Follow-Ups:
- Re: cant able to read serial Port
- From: Alan Cox
- Re: cant able to read serial Port
- Prev by Date: Re: Resetting to default gnome setup
- Next by Date: Re: Single IP address + http + https +Virtual Host
- Previous by thread: Java in Firefox 2 on FC7
- Next by thread: Re: cant able to read serial Port
- Index(es):
Relevant Pages
|