#include<termios.h>
#include<fcntl.h>
#include<errno.h>
#include<sys/ioctl.h>
#include<stdio.h>
#include<sys/time.h>
#include<iostream.h>
#include<sys/types.h>
#include<unistd.h>
#include<string.h>
#include <qfile.h>
#include <qdatastream.h>
#include <qstring.h>
#include <qmessagebox.h>
#include <qapplication.h>
#include <qtextstream.h>
main ()
{
struct termios t;
char *devicedest = "/dev/ttyr00";
unsigned char recvbuf[2];
int rbyte, status, sPortdest,r,i,c=0;
long count=0;
int inp_check=0;
int ifirst=0;
QFile ff
("/root/ss.txt");
ff.open( IO_WriteOnly );
struct timeval timeout;
fd_set testfds,readfds;
t.c_cc[VMIN] = 1;
t.c_cc[VTIME]=0;
// t.c_cc[VEOF]='\n';
/* t.c_iflag &= ~(BRKINT|IGNPAR|PARMRK|INPCK|INLCR|IGNCR|ICRNL|IXON);
t.c_iflag |= (IGNBRK|ISTRIP|IXOFF);
t.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP);
t.c_cflag &= (CSIZE|CSTOPB|HUPCL|PARENB);
t.c_cflag |= (CLOCAL|CREAD|CS8);*/
// t.c_iflag |= (ISIG);
// t.c_iflag &= ~(IUCLC);
// t.c_iflag &= ~BRKINT;
t.c_iflag = (ISIG | IUCLC) ;
t.c_cflag = B9600 | CS8 | CREAD | CLOCAL| HUPCL;
sPortdest= open(devicedest,O_RDONLY|O_NOCTTY|O_NDELAY);
if(tcsetattr(sPortdest,TCSANOW,&t) != 0 )
{
cout<<"\n attribute not set";
}
FD_ZERO(&readfds);
FD_SET(sPortdest,&readfds);
if(sPortdest!=-1)
{
cout<<"Open successfully\n";
do
{
testfds = readfds;
timeout.tv_sec=0;
timeout.tv_usec=1000;
r=select(FD_SETSIZE,&testfds,(fd_set *)0,(fd_set *)0,&timeout);
if(r == -1)
cout<<"Error in select";
//Activity happen on some ports
if(r > 0)
{
//check all
for(i=0;i<FD_SETSIZE;i++)
{
if(FD_ISSET(i,&testfds))
{
//Activity on serial port
if(i == sPortdest)
{
if(ifirst == 0) //Set all attribute when first start
{
status = ioctl(sPortdest,TCSETS,t);
ifirst = 1;
}
rbyte= read(sPortdest,recvbuf,1);
if(rbyte > 0)
{
recvbuf[1]='\0';
cout<<recvbuf;
stream<<recvbuf;
count++;
if((count%11)==0)
{
// cout<<"";
}
usleep(1000);
}
}
}
}
}
//Activity not happen on SP
if(r == 0)
{
//cout<<"\nwaiting\n";
usleep(1000);
ff.close();
}
}while(1);
}
else
{
cout<<"Device could not be oepn successfully";
}
}
#include<termios.h>
#include<fcntl.h>
#include<errno.h>
#include<sys/ioctl.h>
#include<stdio.h>
#include<sys/time.h>
#include<iostream.h>
#include<sys/types.h>
#include<unistd.h>
#include<string.h>
#include <qfile.h>
#include <qdatastream.h>
#include <qstring.h>
#include <qmessagebox.h>
#include <qapplication.h>
#include <qtextstream.h>
main ()
{
struct termios t;
char *devicedest = "/dev/ttyr00";
unsigned char recvbuf[2];
int rbyte, status, sPortdest,r,i,c=0;
long count=0;
int inp_check=0;
int ifirst=0;
QFile ff("/root/ss.txt");
ff.open( IO_WriteOnly );
QTextStream stream(&ff);
QString buff = "";
struct timeval timeout;
fd_set testfds,readfds;
t.c_cc[VMIN] = 1;
t.c_cc[VTIME]=0;
// t.c_cc[VEOF]='\n';
/* t.c_iflag &= ~(BRKINT|IGNPAR|PARMRK|INPCK|INLCR|IGNCR|ICRNL|IXON);
t.c_iflag |= (IGNBRK|ISTRIP|IXOFF);
t.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP);
t.c_cflag &= (CSIZE|CSTOPB|HUPCL|PARENB);
t.c_cflag |= (CLOCAL|CREAD|CS8);*/
// t.c_iflag |= (ISIG);
// t.c_iflag &= ~(IUCLC);
// t.c_iflag &= ~BRKINT;
t.c_iflag = (ISIG | IUCLC) ;
t.c_cflag = B9600 | CS8 | CREAD | CLOCAL| HUPCL;
sPortdest= open(devicedest,O_RDONLY|O_NOCTTY|O_NDELAY);
if(tcsetattr(sPortdest,TCSANOW,&t) != 0 )
{
cout<<"\n attribute not set";
}
FD_ZERO(&readfds);
FD_SET(sPortdest,&readfds);
if(sPortdest!=-1)
{
cout<<"Open successfully\n";
do
{
testfds = readfds;
timeout.tv_sec=0;
timeout.tv_usec=1000;
r=select(FD_SETSIZE,&testfds,(fd_set *)0,(fd_set *)0,&timeout);
if(r == -1)
cout<<"Error in select";
//Activity happen on some ports
if(r > 0)
{
//check all
for(i=0;i<FD_SETSIZE;i++)
{
if(FD_ISSET(i,&testfds))
{
//Activity on serial port
if(i == sPortdest)
{
if(ifirst == 0) //Set all attribute when first start
{
status = ioctl(sPortdest,TCSETS,t);
ifirst = 1;
}
rbyte= read(sPortdest,recvbuf,1);
if(rbyte > 0)
{
recvbuf[1]='\0';
cout<<recvbuf;
stream<<recvbuf;
count++;
if((count%11)==0)
{
// cout<<"";
}
usleep(1000);
}
}
}
}
}
//Activity not happen on SP
if(r == 0)
{
//cout<<"\nwaiting\n";
usleep(1000);
ff.close();
}
}while(1);
}
else
{
cout<<"Device could not be oepn successfully";
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks