-
UID:176460
-
- 注册时间2016-10-26
- 最后登录2017-06-12
- 在线时间324小时
-
- 发帖50
- 搜Ta的帖子
- 精华0
- 金钱520
- 威望62
- 贡献值0
- 好评度52
-
访问TA的空间加好友用道具
|
不好意思小弟又来请教了 这次想实现的功能是开启程式后透过廻圈传递Define的值给程式 然后程式将值透过位元运算 编译成我想要的资料 格式 8个Byte的资料 然后再转成16进制的资料格式发送给机器 编译之后 没有提示语法 错误,小弟苦思费解还是找不出 问题所在
报错 window.open('http://www.qtcn.org/bbs/attachment/Mon_1611/17_176460_4841afc9ac3d638.jpg?300');" style="max-width:700px;max-height:700px;" onload="if(is_ie6&&this.offsetWidth>700)this.width=700;" >
头 文件资料转换部份我是copy刘大师的调试工具内的代码来用 头文件- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
- #include <QMainWindow>
- #include <QString>
- #include <ctype.h>
- #define Gain_Dsp 0x0001
- #define Level_Dsp 0x0002
- #define Aux_Send_Dsp 0x0003
- #define Rev_Send_Dsp 0x0004
- #define Pan_Dsp 0x0005
- #define Eq_Hi_Dsp 0x0006
- #define Eq_Hi_Freq_Dsp 0x0007
- #define Eq_Mid_Dsp 0x0008
- #define Eq_Mid_Freq_Dsp 0x0009
- #define Eq_Mid_Q_Dsp 0x000A
- #define Eq_Lo_Dsp 0x000B
- #define Eq_Lo_Freq_Dsp 0x000C
- #define Gate_Dsp 0x000D
- #define Gate_Threshold_Dsp 0x000E
- #define Gate_Release_Dsp 0x000F
- #define Comp_Dsp 0x0010
- #define Comp_Threshold_Dsp 0x0011
- #define Comp_Ratio_Dsp 0x0012
- #define Comp_Attack_Dsp 0x0013
- #define Comp_Release_Dsp 0x0014
- #define Delay_Dsp 0x0015
- #define Aux_Delay_Dsp 0x0016
- #define Solo_Dsp 0x0017
- #define Mute_Dsp 0x0018
- namespace Ui {
- class MainWindow;
- }
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
- public:
- explicit MainWindow(QWidget *parent = 0);
- ~MainWindow();
- public slots:
- void Rxreaddate();//接收判別
- void Gainwrite();//控件函式
- WidthRead(int DspAddress);
- //發送讀取請求編碼組成
- static QString ChrtoHex(QString Dsp)
- {
- bool ok;
- QString str;
- int num=Dsp.toInt(&ok,16);
- return str.setNum(num,16);
- }
- //16进制字符串转字节数组
- static QByteArray HexStrToByteArray(QString str)
- {
- QByteArray senddata;
- int hexdata,lowhexdata;
- int hexdatalen = 0;
- int len = str.length();
- senddata.resize(len/2);
- char lstr,hstr;
- for(int i=0; i<len; )
- {
- hstr=str[i].toLatin1();
- if(hstr == ' ')
- {
- i++;
- continue;
- }
- i++;
- if(i >= len)
- break;
- lstr = str[i].toLatin1();
- hexdata = ConvertHexChar(hstr);
- lowhexdata = ConvertHexChar(lstr);
- if((hexdata == 16) || (lowhexdata == 16))
- break;
- else
- hexdata = hexdata*16+lowhexdata;
- i++;
- senddata[hexdatalen] = (char)hexdata;
- hexdatalen++;
- }
- senddata.resize(hexdatalen);
- return senddata;
- }
- static char ConvertHexChar(char ch)
- {
- if((ch >= '0') && (ch <= '9'))
- return ch-0x30;
- else if((ch >= 'A') && (ch <= 'F'))
- return ch-'A'+10;
- else if((ch >= 'a') && (ch <= 'f'))
- return ch-'a'+10;
- else return (-1);
- }
- //字节数组转16进制字符串
- static QString ByteArrayToHexStr(QByteArray data)
- {
- QString temp="";
- QString hex=data.toHex();
- for (int i=0;i<hex.length();i=i+2)
- {
- temp+=hex.mid(i,2)+" ";
- }
- return temp.trimmed().toUpper();
- }
- //16进制字符串转10进制
- static int StrHexToDecimal(QString strHex)
- {
- bool ok;
- return strHex.toInt(&ok,16);
- }
- //10进制字符串转10进制
- static int StrDecimalToDecimal(QString strDecimal)
- {
- bool ok;
- return strDecimal.toInt(&ok,10);
- }
- //2进制字符串转10进制
- static int StrBinToDecimal(QString strBin)
- {
- bool ok;
- return strBin.toInt(&ok,2);
- }
- //16进制字符串转2进制字符串
- static QString StrHexToStrBin(QString strHex)
- {
- uchar decimal=StrHexToDecimal(strHex);
- QString bin=QString::number(decimal,2);
- uchar len=bin.length();
- if (len<8)
- {
- for (int i=0;i<8-len;i++)
- {
- bin="0"+bin;
- }
- }
- return bin;
- }
- //10进制转2进制字符串一个字节
- static QString DecimalToStrBin1(int decimal)
- {
- QString bin=QString::number(decimal,2);
- uchar len=bin.length();
- if (len<=8)
- {
- for (int i=0;i<8-len;i++)
- {
- bin="0"+bin;
- }
- }
- return bin;
- }
- //10进制转2进制字符串两个字节
- static QString DecimalToStrBin2(int decimal)
- {
- QString bin=QString::number(decimal,2);
- uchar len=bin.length();
- if (len<=16)
- {
- for (int i=0;i<16-len;i++)
- {
- bin="0"+bin;
- }
- }
- return bin;
- }
- //计算校验码
- static uchar GetCheckCode(uchar data[],uchar len)
- {
- uchar temp=0;
- for (uchar i=0;i<len;i++)
- {
- temp+=data[i];
- }
- return temp%256;
- }
- //将溢出的char转为正确的uchar
- /*static uchar GetUChar(char data)
- {
- uchar temp;
- if (data>127)
- {
- temp=data+256;
- }
- else
- {
- temp=data;
- }
- return temp;
- }*/
- private:
- Ui::MainWindow *ui;
- };
- #endif // MAINWINDOW_H
主文件 - #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QtSerialPort/QSerialPort>
- #include <QSerialPortInfo>
- #include <QDebug>
- QSerialPort *Txserialport;
- QSerialPort *Rxserialport;
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- Rxserialport=new QSerialPort(this);//讀取串口設置
- Txserialport=new QSerialPort(this);//傳送串口設置
- Rxserialport->setPortName("COM5");//接收串口名稱
- Txserialport->setPortName("COM3");//讀取串口名稱
- //傳輸環境設置
- 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);
- //RX信號槽 只要RX收到信號就立即跳到RxReaddate副程式
- connect(Rxserialport,SIGNAL(readyRead()),
- this,SLOT(Rxreaddate()));
- int Dsp[]={
- Gain_Dsp,
- Level_Dsp,
- Aux_Send_Dsp,
- Rev_Send_Dsp,
- Pan_Dsp,
- Eq_Hi_Dsp,
- Eq_Hi_Freq_Dsp,
- Eq_Mid_Dsp,
- Eq_Mid_Freq_Dsp,
- Eq_Mid_Q_Dsp,
- Eq_Lo_Dsp,
- Eq_Lo_Freq_Dsp,
- Gate_Dsp,
- Gate_Threshold_Dsp,
- Gate_Release_Dsp,
- Comp_Dsp,
- Comp_Threshold_Dsp,
- Comp_Ratio_Dsp,
- Comp_Attack_Dsp,
- Comp_Release_Dsp,
- Delay_Dsp,
- Aux_Delay_Dsp,
- Solo_Dsp,
- Mute_Dsp,
- };
- //開啟程式即發射請求訊號
- for(int i=0;i<24;i++)
- {
- WidthRead(Dsp[i]);
- }
- //控件發送信號槽 每當控件數值出現變化就發送值到對應的函式
- connect(ui->Gain_spinBox,SIGNAL(valueChanged(int)),
- this,SLOT(Gainwrite()));
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- Rxserialport->close();
- Txserialport->close();
- }
- MainWindow::WidthRead(int DspAddress)
- {
- int Product = 0x3F;
- int Link_No = 0x1F;
- int Write_Read =0x1;
- int DSP_ID =0xF;
- int Length=0xF;
- int Pack_No=0x7F;
- int DsPP[3];
- DsPP[0]=DspAddress&0xF000;
- DsPP[1]=DspAddress&0x0F00;
- DsPP[2]=DspAddress&0x00F0;
- DsPP[3]=DspAddress&0x000F;
- int Ex1;
- int Ex2;
- int Ex3;
- QString Strcode[7];
- int WidthCode[7];
- Ex1=Product<<2;
- Ex2=Link_No>>3;
- WidthCode[0]=(Ex1|Ex2)&0xFE;
- Ex1=(Link_No&0xF)<<4;
- Ex2=Write_Read<<3;
- Ex3=DSP_ID>>2;
- WidthCode[1]=(Ex1|Ex2|Ex3)&0xFE;
- Ex1=(DSP_ID&0x7)<<5;
- Ex2=DsPP[0]<<1;
- WidthCode[2]=(Ex1|Ex2)&0xFE;
- Ex1=DsPP[1]<<4;
- WidthCode[3]=(Ex1|DsPP[2])&0xFE;
- Ex1=(DsPP[2]&0x01)<<7;
- Ex2=DsPP[3]<<3;
- Ex3=Length>>1;
- WidthCode[4]=(Ex1|Ex2|Ex3)&0xFE;
- Ex1=(Length&0x3)<<6;
- WidthCode[5]=Ex1&0xFE;
- WidthCode[6]=Pack_No<<1;
- WidthCode[7]=(WidthCode[0]^WidthCode[1]^WidthCode[2]^WidthCode[3]^WidthCode[4]^WidthCode[5]^WidthCode[6]^WidthCode[7])|0x01;
- for(int i=0;i<8;i++){
- Strcode[i]=QString::number(WidthCode[i]);
- qDebug()<<Strcode[i];
- Txserialport->write(HexStrToByteArray(Strcode[i]));
- qDebug()<<HexStrToByteArray(Strcode[i]);
- }
- }
- void MainWindow::Rxreaddate()//判斷收到的資料屬於哪個DSP位址並將值取出放入相對應的控件
- {
- }
- void MainWindow::Gainwrite()
- {
- QString str =QString::number(ui->Gain_spinBox->value());
- Txserialport->write(str.toStdString().data());
- qDebug()<<str.toStdString().data();
- }
|