-
UID:176460
-
- 注册时间2016-10-26
- 最后登录2017-06-12
- 在线时间324小时
-
- 发帖50
- 搜Ta的帖子
- 精华0
- 金钱520
- 威望62
- 贡献值0
- 好评度52
-
访问TA的空间加好友用道具
|
—
本帖被 XChinux 从 休闲娱乐 移动到本区(2016-12-23)
—
小弟之前其实从事的是业务销售 学生的时候因为是读工科所以有接触过编程,也对编程有些兴趣 只是后来一直没继续坚持发展下去 直到实在没办法习惯业务销售的生态决定转业 现在刚到一家公司从业,老板要培训我学习QT为公司设计UI 对我来说实在压力山大,因为我同时要学会QT又要学会 C++而且重点是整个公司只有我会QT 老板也不会 所以我每天都是抱著书本在公司边做边想边查 资料 无人可问 编程对于已经脱离学生时代有5年的我来说基本上就是从0开始学习 然后老板之前都会出个题目让我1个星期交作业给他 我都勉强交卷成功 而这次出的作业虽然时间有2个星期但是做到让我整个人对自己都没啥信心了 已經做超過2个星期了.... 因为几乎都是每步必卡 步步维艰... 老板说我这样做的速度实在太慢(顺便酸我还自称在学还是资优生) 要我多加油点 但我已经尽力了 我对自己的编程状况也很不满意 进入公司已经有1个多月了 但是还是觉得自己学的速度有夠渣 顺便附上我现在做的作业给大家观赏我做的有多烂 window.open('http://www.qtcn.org/bbs/attachment/Mon_1612/24_176460_b39bac377437fd4.jpg?392');" style="max-width:700px;max-height:700px;" onload="if(is_ie6&&this.offsetWidth>700)this.width=700;" > - #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QtSerialPort/QSerialPort>
- #include <QSerialPortInfo>
- #include <QDebug>
- #include <QString>
- #include <QTimer>
- QByteArray Rx;
- QSerialPort *Txserialport;
- QSerialPort *Rxserialport;
- QTimer *runTime=new QTimer();
- int DspPoint=0;
- int DataValue[24]={0};
- int DataPoint=0;
- int Product = 0x3F;
- int Link_No = 0x1F;
- int Write_Read =0x1;
- int DSP_ID =0xF;
- int Length =0xF;
- int Pack_ON =0x7F;
- int Dsp[]={
- Gain_Dsp, //00
- Level_Dsp, //01
- Aux_Send_Dsp, //02
- Rev_Send_Dsp, //03
- Pan_Dsp, //04
- Eq_Hi_Dsp, //05
- Eq_Hi_Freq_Dsp, //06
- Eq_Mid_Dsp, //07
- Eq_Mid_Freq_Dsp, //08
- Eq_Mid_Q_Dsp, //09
- Eq_Lo_Dsp, //10
- Eq_Lo_Freq_Dsp, //11
- Gate_Dsp, //12
- Gate_Threshold_Dsp, //13
- Gate_Release_Dsp, //14
- Comp_Dsp, //15
- Comp_Threshold_Dsp, //16
- Comp_Ratio_Dsp, //17
- Comp_Attack_Dsp, //18
- Comp_Release_Dsp, //19
- Delay_Dsp, //20
- Aux_Delay_Dsp, //21
- Solo_Dsp, //22
- Mute_Dsp, //23
- };
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- Rxserialport=new QSerialPort(this);//讀取串口設置
- Txserialport=new QSerialPort(this);//傳送串口設置
- Rxserialport->setPortName("COM4");//接收串口名稱
- Txserialport->setPortName("COM5");//讀取串口名稱
- //傳輸環境設置
- Rxserialport->open(QIODevice::ReadOnly);//唯獨
- Txserialport->open(QIODevice::WriteOnly);//唯寫
- Rxserialport->setBaudRate(QSerialPort::Baud115200);
- Txserialport->setBaudRate(QSerialPort::Baud115200);
- Rxserialport->setDataBits(QSerialPort::Data8);
- Txserialport->setDataBits(QSerialPort::Data8);
- Rxserialport->setParity(QSerialPort::SpaceParity);
- Txserialport->setParity(QSerialPort::SpaceParity);
- Rxserialport->setStopBits(QSerialPort::OneStop);
- Txserialport->setStopBits(QSerialPort::OneStop);
- runTime->start(2000);//定時器時脈 ms
- //定時器連結槽
- connect(runTime,SIGNAL(timeout()),this,SLOT(TimeDeary()));
- //RX信號槽 只要RX收到信號就立即跳到RxReaddate副程式
- connect(Rxserialport,SIGNAL(readyRead()),
- this,SLOT(Rxreaddate()));
- //控件發送信號槽 每當控件數值出現變化就發送值到對應的函式
- connect(ui->Gain_spinBox,SIGNAL(valueChanged(int)),
- this,SLOT(Gainwrite()));
- ui->Eq_Hi_frame->setVisible(false);
- ui->Eq_Mid_frame->setVisible(false);
- ui->Eq_Lo_frame->setVisible(false);
- ui->Comp_frame->setVisible(false);
- ui->Gate_frame->setVisible(false);
- //setVisible(true)
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- Rxserialport->close();
- Txserialport->close();
- }
- void MainWindow::TimeDeary()//定時器
- {
- WidthRead(Dsp[DspPoint]);
- DspPoint+=1;
- if(DspPoint>23)
- {
- DspPoint=0;
- }
- }
- void MainWindow::WriteWidth(int DspAddress,int value)//將UI的值編碼後發射寫入硬體
- {
- int DsPP[4];
- DsPP[0]=(DspAddress&0xF000)>>12;//Dsp位址位元初始化
- DsPP[1]=(DspAddress&0x0F00)>>8;
- DsPP[2]=(DspAddress&0x00F0)>>4;
- DsPP[3]= DspAddress&0x000F;
- int Val[4];
- Val[0]=(value&0xF000)>>12;//值位元初始化
- Val[1]=(value&0x0F00)>>8;
- Val[2]=(value&0x00F0)>>4;
- Val[3]= value&0x000F;
- int Ex1;
- int Ex2;
- int Ex3;
- QString Strcode[8];
- int WidthCode[8];
- qDebug()<<"DspAddress:"<<DspAddress;
- qDebug()<<"Value:"<<value;
- //編碼程序
- Ex1=Product<<2;
- Ex2=Link_No>>3;
- WidthCode[0]=(Ex1|Ex2)&0xFE;
- qDebug()<<"Byte1:"<<WidthCode[0];
- Ex1=(Link_No&0xF)<<4;
- Ex2=Write_Read<<3;
- Ex3=DSP_ID>>2;
- WidthCode[1]=(Ex1|Ex2|Ex3)&0xFE;
- qDebug()<<"Byte2:"<<WidthCode[1];
- Ex1=(DSP_ID&0x7)<<5;
- Ex2=DsPP[0]<<1;
- WidthCode[2]=(Ex1|Ex2)&0xFE; //E0
- qDebug()<<"Byte3:"<<WidthCode[2];
- Ex1=DsPP[1]<<4;
- Ex2=DsPP[2];
- WidthCode[3]=(Ex1|Ex2)&0xFE; //0
- qDebug()<<"Byte4:"<<WidthCode[3];
- Ex1=(DsPP[2]&0x01)<<7;
- Ex2=DsPP[3]<<3;
- Ex3=Val[0]>>1;
- WidthCode[4]=(Ex1|Ex2|Ex3)&0xFE; //e
- qDebug()<<"Byte5:"<<WidthCode[4];
- Ex1=(Val[0]&0x3)<<6;
- Ex2=Val[1]<<2;
- Ex3=Val[2]>>2;
- WidthCode[5]=(Ex1|Ex2|Ex3)&0xFE;
- qDebug()<<"Byte6:"<<WidthCode[5];
- Ex1=(Val[2]&0x07)<<5;
- Ex2=Val[3]<<1;
- WidthCode[6]=(Ex1|Ex2)&0xFE;
- qDebug()<<"Byte7:"<<WidthCode[6];
- WidthCode[7]=(WidthCode[0]^WidthCode[1]^WidthCode[2]^WidthCode[3]^WidthCode[4]^WidthCode[5]^WidthCode[6]) | 0x01;
- qDebug()<<"Byte8:"<<WidthCode[7];
- for(int i=0;i<8;i++)
- {
- Strcode[i]=QString::number(WidthCode[i],16);
- if((WidthCode[i]&0xF0)==0){
- Strcode[i]="0"+Strcode[i];
- }
- qDebug()<<"Strcode:"<<i<<Strcode[i];
- Txserialport->write(HexStrToByteArray(Strcode[i]));
- }
- }
- void MainWindow::WidthRead(int DspAddress)//發送讀取請求
- {
- int DsPP[4];
- DsPP[0]=(DspAddress&0xF000)>>12;
- DsPP[1]=(DspAddress&0x0F00)>>8;
- DsPP[2]=(DspAddress&0x00F0)>>4;
- DsPP[3]=DspAddress&0x000F;
- int Ex1;
- int Ex2;
- int Ex3;
- QString Strcode[8];
- int WidthCode[8];
- qDebug()<<"DspAddress:"<<DspAddress;
- Ex1=Product<<2;
- Ex2=Link_No>>3;
- WidthCode[0]=(Ex1|Ex2)&0xFE; //FE
- qDebug()<<"Byte1:"<<WidthCode[0];
- Ex1=(Link_No&0xF)<<4;
- Ex2=Write_Read<<3;
- Ex3=DSP_ID>>2;
- WidthCode[1]=(Ex1|Ex2|Ex3)&0xFE; //FA
- qDebug()<<"Byte2:"<<WidthCode[1];
- Ex1=(DSP_ID&0x7)<<5;
- Ex2=DsPP[0]<<1;
- WidthCode[2]=(Ex1|Ex2)&0xFE; //E0
- qDebug()<<"Byte3:"<<WidthCode[2];
- Ex1=DsPP[1]<<4;
- Ex2=DsPP[2];
- WidthCode[3]=(Ex1|Ex2)&0xFE; //0
- qDebug()<<"Byte4:"<<WidthCode[3];
- Ex1=(DsPP[2]&0x01)<<7;
- Ex2=DsPP[3]<<3;
- Ex3=Length>>1;
- WidthCode[4]=(Ex1|Ex2|Ex3)&0xFE; //e
- qDebug()<<"Byte5:"<<WidthCode[4];
- Ex1=(Length&0x03)<<6;
- WidthCode[5]=Ex1&0xFE; //c0
- qDebug()<<"Byte6:"<<WidthCode[5];
- Ex1=Pack_ON<<1;
- WidthCode[6]=Ex1&0xFE; //Fe
- qDebug()<<"Byte7:"<<WidthCode[6];
- WidthCode[7]=(WidthCode[0]^WidthCode[1]^WidthCode[2]^WidthCode[3]^WidthCode[4]^WidthCode[5]^WidthCode[6]) | 0x01;
- qDebug()<<"Byte8:"<<WidthCode[7];
- for(int i=0;i<8;i++)
- {
- Strcode[i]=QString::number(WidthCode[i],16);
- if((WidthCode[i]&0xF0)==0){
- Strcode[i]="0"+Strcode[i];
- }
- qDebug()<<"Strcode:"<<i<<Strcode[i];
- Txserialport->write(HexStrToByteArray(Strcode[i]));
- }
- }
- void MainWindow::Rxreaddate()//解码將值與發送編號取出並呼叫副程式
- {
- bool ok;
- int Read_Data[4];
- QString Strcode[256];
- int Rxlength=0;
- //if(Rx.isEmpty())
- //{
- Rx=Rxserialport->readAll();
- Rxlength=Rx.length();
- // }
- // else if(Rx.length()<5&&Rx.length()>0){
- // Rx+=Rxserialport->readAll();
- // Rxlength=Rx.length();
- // }
- // else if(Rx.length()>5){
- // runTime->stop();
- // }
- for(int i=0;i<Rxlength;i++)
- {
- Strcode[i]=Rx.mid(0+i,1).toHex();
- qDebug()<<"Strcode"<<i<<":"<<Strcode[i];
- }
- //int Read_Pack_No=Strcode[0].toInt(&ok,16)>>1;
- int Read_CRC=Strcode[4].toInt(&ok,16);
- qDebug()<<"Read_CRC"<<Read_CRC;
- Read_Data[0]=Strcode[1].toInt(&ok,16)>>4;
- Read_Data[1]=(Strcode[1].toInt(&ok,16)&0xF)|(Strcode[2].toInt(&ok,16)>>7);
- Read_Data[2]=(Strcode[2].toInt(&ok,16)&0x7F)>>3;
- Read_Data[3]=((Strcode[2].toInt(&ok,16)&0x6)<<1)|(Strcode[3].toInt(&ok,16)>>6);
- int tex_CRC=(Strcode[0].toInt(&ok,16)^Strcode[1].toInt(&ok,16)^Strcode[2].toInt(&ok,16)^Strcode[3].toInt(&ok,16))|0x01;
- qDebug()<<"Tex_CRC"<<tex_CRC;
- if(Read_CRC==tex_CRC)//比對CRC 正確才將值解碼
- {
- int Value=(Read_Data[0]<<12)|
- (Read_Data[1]<<8)|
- (Read_Data[2]<<4)|
- (Read_Data[3]);
- qDebug()<<"RX"<<Rx;
- qDebug()<<Value;
- RxDatatoWiget(Value);
- }
- }
- void MainWindow::RxDatatoWiget(int Value)//獲得的值放入控件內
- {
- qDebug()<<"DataValue:"<<DataValue[DataPoint];
- qDebug()<<"DataPoint:"<<DataPoint;
- DataValue[DataPoint]=Value;
- ui->Gain_spinBox->setValue(DataValue[0]);
- ui->Level_spinBox->setValue(DataValue[1]);
- ui->Aux_Send_spinBox->setValue(DataValue[2]);
- ui->Rev_Send_spinBox->setValue(DataValue[3]);
- ui->Pan_comboBox->setCurrentIndex(DataValue[4]);
- ui->Eq_Hi_spinBox->setValue(DataValue[5]);
- ui->Eq_Hi_Freq_combBox->setCurrentIndex(DataValue[6]);
- ui->Eq_Mid_spinBox->setValue(DataValue[7]);
- ui->Eq_Mid_Freq_comboBox->setCurrentIndex(DataValue[8]);
- ui->Eq_Mid_Q_comboBox->setCurrentIndex(DataValue[9]);
- ui->Eq_Lo_spinBox->setValue(DataValue[10]);
- ui->Eq_Lo_Freq_comboBox->setCurrentIndex(DataValue[11]);
- ui->Gate_comboBox->setCurrentIndex(DataValue[12]);
- ui->Gate_Threshold_spinBox->setValue(DataValue[13]);
- ui->Gate_Reslease_spinBox->setValue(DataValue[14]);
- ui->Comp_comboBox->setCurrentIndex(DataValue[15]);
- ui->Comp_Threshold_spinBox->setValue(DataValue[16]);
- ui->Comp_Ratio_comboBox->setCurrentIndex(DataValue[17]);
- ui->Comp_Attack_comboBox->setCurrentIndex(DataValue[18]);
- ui->Comp_Reslease_spinBox->setValue(DataValue[19]);
- ui->Delay_doubleSpinBox->setValue(DataValue[20]);
- ui->Aux_Delay_doubleSpinBox->setValue(DataValue[21]);
- //ui->Solo_pushButton
- //ui->Mute_pushButton
- DataPoint+=1;
- if(DataPoint>23)
- {
- DataPoint=0;
- }
- }
- //控件區 每當數值出現變化 就立即呼叫程式寫入硬體
- void MainWindow::on_Gain_spinBox_valueChanged(int arg1)
- {
- WriteWidth(Gain_Dsp,ui->Gain_spinBox->value());
- }
- void MainWindow::on_Level_spinBox_valueChanged(int arg1)
- {
- WriteWidth(Level_Dsp,ui->Level_spinBox->value());
- }
- void MainWindow::on_Aux_Send_spinBox_valueChanged(int arg1)
- {
- WriteWidth(Aux_Send_Dsp,ui->Aux_Send_spinBox->value());
- }
- void MainWindow::on_Rev_Send_spinBox_valueChanged(int arg1)
- {
- WriteWidth(Rev_Send_Dsp,ui->Rev_Send_spinBox->value());
- }
- void MainWindow::on_Pan_comboBox_currentIndexChanged(int index)
- {
- WriteWidth(Pan_Dsp,ui->Pan_comboBox->currentIndex());
- }
- void MainWindow::on_Eq_Hi_spinBox_valueChanged(int arg1)
- {
- WriteWidth(Eq_Hi_Dsp,ui->Eq_Hi_spinBox->value());
- }
- void MainWindow::on_Eq_Hi_Freq_combBox_currentIndexChanged(int index)
- {
- WriteWidth(Eq_Hi_Freq_Dsp,ui->Eq_Hi_Freq_combBox->currentIndex());
- }
- void MainWindow::on_Eq_Mid_spinBox_valueChanged(int arg1)
- {
- WriteWidth(Eq_Mid_Dsp,ui->Eq_Mid_spinBox->value());
- }
- void MainWindow::on_Eq_Mid_Freq_comboBox_currentIndexChanged(int index)
- {
- WriteWidth(Eq_Mid_Freq_Dsp,ui->Eq_Mid_Freq_comboBox->currentIndex());
- }
- void MainWindow::on_Eq_Mid_Q_comboBox_currentIndexChanged(int index)
- {
- WriteWidth(Eq_Mid_Q_Dsp,ui->Eq_Mid_Q_comboBox->currentIndex());
- }
- void MainWindow::on_Eq_Lo_spinBox_valueChanged(int arg1)
- {
- WriteWidth(Eq_Lo_Dsp,ui->Eq_Lo_spinBox->value());
- }
- void MainWindow::on_Eq_Lo_Freq_comboBox_currentIndexChanged(int index)
- {
- WriteWidth(Eq_Lo_Freq_Dsp,ui->Eq_Lo_Freq_comboBox->currentIndex());
- }
- void MainWindow::on_Gate_comboBox_currentIndexChanged(int index)
- {
- WriteWidth(Gate_Dsp,ui->Gate_comboBox->currentIndex());
- }
- void MainWindow::on_Gate_Threshold_spinBox_valueChanged(int arg1)
- {
- WriteWidth(Gate_Threshold_Dsp,ui->Gate_Threshold_spinBox->value());
- }
- void MainWindow::on_Gate_Reslease_spinBox_valueChanged(int arg1)
- {
- WriteWidth(Gate_Release_Dsp,ui->Gate_Reslease_spinBox->value());
- }
- void MainWindow::on_Comp_comboBox_currentIndexChanged(int index)
- {
- WriteWidth(Comp_Dsp,ui->Comp_comboBox->currentIndex());
- }
- void MainWindow::on_Comp_Threshold_spinBox_valueChanged(int arg1)
- {
- WriteWidth(Comp_Threshold_Dsp,ui->Comp_Threshold_spinBox->value());
- }
- void MainWindow::on_Comp_Ratio_comboBox_currentIndexChanged(int index)
- {
- WriteWidth(Comp_Ratio_Dsp,ui->Comp_Ratio_comboBox->currentIndex());
- }
- void MainWindow::on_Comp_Attack_comboBox_currentIndexChanged(int index)
- {
- WriteWidth(Comp_Attack_Dsp,ui->Comp_Attack_comboBox->currentIndex());
- }
- void MainWindow::on_Comp_Reslease_spinBox_valueChanged(int arg1)
- {
- WriteWidth(Comp_Release_Dsp,ui->Comp_Reslease_spinBox->value());
- }
- void MainWindow::on_Delay_doubleSpinBox_valueChanged(double arg1)
- {
- int value=arg1;
- ui->Delay_dial->setValue(value);
- WriteWidth(Delay_Dsp,DoubleToInt_IEEE(arg1));
- }
- void MainWindow::on_Delay_dial_valueChanged(int value)
- {
- double Ex=value;
- ui->Delay_doubleSpinBox->setValue(Ex);
- }
- void MainWindow::on_Aux_Delay_doubleSpinBox_valueChanged(double arg1)
- {
- int value=arg1;
- ui->Aux_Delay_dial->setValue(value);
- WriteWidth(Aux_Delay_Dsp,DoubleToInt_IEEE(arg1));
- }
- void MainWindow::on_Aux_Delay_dial_valueChanged(int value)
- {
- double Ex=value;
- ui->Aux_Delay_doubleSpinBox->setValue(Ex);
- }
|