串口通信程序写到次线程中对应串口终端无响应是什么原因啊?未加到线程中时可正常通信
注:有个warning提示串口文件描述符 fd 未初始化
补充代码: 是子线程run()调用的一个函数
void MyMainWindow::MessageBox_1()
{
// int fd;
int nwrite, j;
char buf[] = "hello!Good morning everyone!";
char buf1[24];
MThread thread;
QMessageBox msgBox;
msgBox.setText(tr("MAKE SURE"));
msgBox.setIconPixmap(QPixmap("./456.jpg"));
msgBox.setStandardButtons(QMessageBox::Ok|QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
int ret = msgBox.exec();
/* if((fd = open_port(fd, 1))<0)
{
perror("open_port error");
return -1;
}
if((j = set_opt(fd, 9600, 8, 'N', 1))<0)
{
perror("set_opt error");
return -1;
}
*/
switch(ret)
{
case QMessageBox::Ok:
if((thread.fd = thread.open_port(thread.fd, 1)) < 0)
{
perror("open_port error");
return;
}
if((j = thread.set_opt(thread.fd, 9600, 8, 'N', 1)) <0)
{
perror("set_opt error");
return;
}
printf("fd = %d\n",thread.fd);
nwrite = write(thread.fd, buf, sizeof(buf));
printf("nwrite = %d\n", nwrite);
bzero(buf1, sizeof(buf1));
while( !read(thread.fd, buf1, sizeof(buf1)));
label -> setText(tr(buf1));
// MThread::close(fd);
break;
case QMessageBox::Cancel:
label -> setText("Cancel");
break;
default:
break;
}
}
还有个问题就是close()函数怎么调用到子线程中
[ 此帖被butcherty在2010-05-11 11:37重新编辑 ]