void MyComTool::manualCom_Sent()
{
QString user_input;
char *to_sent = new QChar[10240];
char sent_buf[2];
QChar *to_sent_tmp = new QChar[10240];
int b;
qint64 char_count;
user_input = comSentTextEdit->toPlainText();
to_sent = user_input.toAscii().data();
to_sent_tmp = user_input.data();
char_count = 0;
already_sent_times++;
if(!sent_hex_model)
{
sent_byte_counter +=myCom->write(to_sent);
myCom->waitForBytesWritten(-1);
comReceiveLabel->setNum (sent_byte_counter);
}
else
{
while (!to_sent_tmp->isNull())
{
b= (int)*to_sent;
sprintf(sent_buf, "%x", b);
hex_to_sent[char_count] = sent_buf[0];
hex_to_sent[char_count + 1] = sent_buf[1];
++to_sent_tmp;
++to_sent;
++char_count;
++char_count;
if(char_count >= 10240)
{
char_count = 0;
QMessageBox warningBox(this);
QString mypix;
mypix = ":/erroring.png";
QPixmap img(mypix);
warningBox.setIconPixmap(mypix);
warningBox.setWindowTitle(tr("错误"));
warningBox.setText(tr("发送数据过长!"));
warningBox.exec();
break;
}
}
sent_byte_counter += myCom->write(hex_to_sent, char_count);
myCom->waitForBytesWritten(-1);
comReceiveLabel->setNum (sent_byte_counter);
}
sentTimesClearLabel->setNum(already_sent_times);
delete [] to_sent_tmp;
delete []to_sent;
}
该槽函数是相应发送按钮的,向串口发送数据。
谢谢了!