saltus 德国电子扭力扳手 通讯程序源代码

通讯助手 用于测试与电子扳手的通讯功能
QT C++

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //串口
    serialPort=new QSerialPort;
    iniPort() ;
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    //ui->readTxt->setText("");
    serialPort->write("TWN?\x0d");

}

void MainWindow::iniPort()   //初始化
{


    //configini();
    /*ui->rAsciiRadio->setChecked(true);
    ui->sAsciiRadio->setChecked(true);
    ui->rLineCheck->setChecked(true);
    ui->readTxt->setReadOnly(true);*/
    QList<QSerialPortInfo> infos=QSerialPortInfo::availablePorts();
    if(infos.isEmpty())
    {
        ui->portCombo->addItem(tr("Empty"));
        return;
    }
    foreach (auto info, infos)
    {
        ui->portCombo->addItem(info.portName());
    }



}

void MainWindow::SerialreadData()
{
    QByteArray data=serialPort->readAll();//从串口中读取数据


    //str1 = str1+" " + data.toHex(' ').trimmed().toUpper();
    str1 =str1+ QString(data);
    ui->readTxt->setText(str1);
    ui->textEdit->setText(str1);


}

void MainWindow::on_pushButton_2_clicked()
{
       serialPort->write("ENB,A3580459\x0d");
}

void MainWindow::on_pushButton_3_clicked()
{
    ui->readTxt->setText("NULL");

   QString str2 = "OK";
   if(!(str2 == "OK"))
   {
       ui->readTxt->setText("OK1");

   }
   else
   {
       ui->readTxt->setText("NOK2");
   }
}

void MainWindow::on_pushButton_4_clicked()
{

    ui->readTxt->setText("NULL");

   QString str2 = "OK";
   if((str2 == "1OK"));
   ui->readTxt->setText("NULL2");

}

void MainWindow::on_pushButton_5_clicked()
{
     serialPort->write("RMM\x0d");
}

void MainWindow::on_pushButton_6_clicked()
{

     serialPort->write("MCR,1,070,330,0,0,200,R,*,1,0,2,30Nm?0%\x0d");
}

void MainWindow::on_pushButton_7_clicked()
{
     serialPort->write("LDM,1\x0d");
}

void MainWindow::on_pushButton_8_clicked()
{
    serialPort->write("MCR,1,050,330,0,0,200,R,*,1,0,2,30Nm?0%\x0d");
}




void MainWindow::on_pushButton_9_clicked()
{
    serialPort->write("TWN?\x0d");

}
void MainWindow::on_pushButton_11_clicked()
{
     serialPort->write("ENB,A3580461\x0d");
}

void MainWindow::on_pushButton_10_clicked()
{
     serialPort->write("RMM\x0d");
}
void MainWindow::on_pushButton_13_clicked()
{
    serialPort->write("LDM,1\x0d");
}


void MainWindow::on_pushButton_12_clicked()
{
     serialPort->write("MCR,1,070,330,0,0,200,R,*,1,0,2,7Nm?0%\x0d");
}



void MainWindow::on_pushButton_14_clicked()
{
     serialPort->write("MCR,1,050,330,0,0,200,R,*,1,0,2,5Nm?0%\x0d");
}

void MainWindow::on_portCombo_currentIndexChanged(const QString &arg1)
{

}

void MainWindow::on_pushButton_15_clicked()
{

    serialPort->setPortName(ui->portCombo->currentText());
    serialPort->setBaudRate(19200);
    serialPort->setDataBits(QSerialPort::Data8);
    serialPort->setParity(QSerialPort::NoParity);
    serialPort->setFlowControl(QSerialPort::NoFlowControl);
    serialPort->setStopBits(QSerialPort::OneStop);
    serialPort->open(QIODevice::ReadWrite);
    connect(serialPort,&QSerialPort::readyRead,this,&MainWindow::SerialreadData);
}

你可能感兴趣的:(硬件相关,c语言)