void Form1::send_clicked()
{
int size;
int i,j,k;
QFile file("/sfiles/mxdrv.tgz");
if(!file.open( IO_ReadOnly ))
{
QMessageBox::information(0,
"Error",
"Error opening file");
}
else
{
cout<<"File opened successfully"<<endl;
}
cout<<"file opened...."<<endl;
unsigned char fname[]="mxdrv.tgz";
struct termios t;
char *device = "/dev/ttyS0";
int sPort, rbyte, status, sPortdest,length;
long count=0;
unsigned char send1[32];
t.c_cc[VMIN] = 1;
t.c_cc[VTIME]=0;
t.c_cc[VEOF]='\n';
t.c_iflag |= (ISIG);
t.c_iflag &= ~BRKINT;
t.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
sPort = open(device,O_RDWR|O_NOCTTY|O_NDELAY);
if(sPort != -1)
{
cout<<"open successfully\n";
status = ioctl(sPort,TCSETS,&t);
cout<<"Entering status"<<status<<endl;
if(status==0)
{
//for(count=0;count<20;count++)
cout<<"sending name"<<endl;
rbyte=write(sPort,fname,strlen((char *)fname));
cout<<rbyte<<endl;
//usleep(3000);
cout<<"name sent"<<endl;
cout<<"now sending file"<<endl;
usleep(3000);
while(!file.atEnd())
{
//cout<<"Enter :";
//cin>>send1;
//strcat((char *)send1,"{MSS TYPE-D DAMA}");
// write(sPort,"{012345678}",11);
cout<<"getting byte from file"<<endl;
i=file.getch();
GenerateByte(i,send);
//usleep(3000);
rbyte=TEMP_FAILURE_RETRY( write(sPort,send,qstrlen(send)));
cout<<rbyte<<"sent"<<endl;
//cout<<"w b:"<<rbyte<<"\t Time:"<<count<<"\t string:"<<send1<<"\n";
//usleep(1000);
}
}
close(sPort);
}
else
{
cout<<"Device could not be opened";
}
file.close();
}
void Form1
::GenerateByte(int i,
QString &ssend
) {
ssend.sprintf("%d",i);
}
void Form1::send_clicked()
{
int size;
int i,j,k;
QString send;
QFile file("/sfiles/mxdrv.tgz");
if(!file.open( IO_ReadOnly ))
{
QMessageBox::information(0,"Error","Error opening file");
}
else
{
cout<<"File opened successfully"<<endl;
}
cout<<"file opened...."<<endl;
unsigned char fname[]="mxdrv.tgz";
struct termios t;
char *device = "/dev/ttyS0";
int sPort, rbyte, status, sPortdest,length;
long count=0;
unsigned char send1[32];
t.c_cc[VMIN] = 1;
t.c_cc[VTIME]=0;
t.c_cc[VEOF]='\n';
t.c_iflag |= (ISIG);
t.c_iflag &= ~BRKINT;
t.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
sPort = open(device,O_RDWR|O_NOCTTY|O_NDELAY);
if(sPort != -1)
{
cout<<"open successfully\n";
status = ioctl(sPort,TCSETS,&t);
cout<<"Entering status"<<status<<endl;
if(status==0)
{
//for(count=0;count<20;count++)
cout<<"sending name"<<endl;
rbyte=write(sPort,fname,strlen((char *)fname));
cout<<rbyte<<endl;
QMessageBox::information(0,"sent","Name sent");
//usleep(3000);
cout<<"name sent"<<endl;
cout<<"now sending file"<<endl;
usleep(3000);
while(!file.atEnd())
{
//cout<<"Enter :";
//cin>>send1;
//strcat((char *)send1,"{MSS TYPE-D DAMA}");
// write(sPort,"{012345678}",11);
cout<<"getting byte from file"<<endl;
i=file.getch();
GenerateByte(i,send);
//usleep(3000);
rbyte=TEMP_FAILURE_RETRY( write(sPort,send,qstrlen(send)));
cout<<rbyte<<"sent"<<endl;
//cout<<"w b:"<<rbyte<<"\t Time:"<<count<<"\t string:"<<send1<<"\n";
//usleep(1000);
}
}
close(sPort);
}
else
{
cout<<"Device could not be opened";
}
file.close();
}
void Form1::GenerateByte(int i, QString &ssend)
{
ssend.sprintf("%d",i);
}
To copy to clipboard, switch view to plain text mode
and about using the QString object in write() function, i have checked it with the previous code of my project, and it is working fine. The only thing is instead of strlen() i have to use qstrlen().
Bookmarks