├── GoBao1.pro ├── GoBao1.pro.user ├── README.md ├── dev ├── frame.cpp ├── frame.h ├── qcustomplot.cpp ├── qcustomplot.h └── readme.txt ├── four_pages ├── calibration.cpp ├── calibration.h ├── calibration.ui ├── ctrpanel.cpp ├── ctrpanel.h ├── ctrpanel.ui ├── home.cpp ├── home.h ├── home.ui ├── readme.txt ├── showpanel.cpp ├── showpanel.h └── showpanel.ui ├── images.qrc ├── images ├── Gobao.png ├── Panel.png ├── calbration.png ├── calibration_selected.png ├── communacation.png ├── communacation2.png ├── control.png ├── control_selected.png ├── home.png ├── home_selected.png ├── readme.txt ├── showpanel.png └── showpanel_selected.png ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui └── 版本记录与说明.txt /GoBao1.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2021-11-02T10:40:40 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | QT += serialport 9 | QT += widgets printsupport 10 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 11 | 12 | TARGET = GoBao1 13 | TEMPLATE = app 14 | 15 | # The following define makes your compiler emit warnings if you use 16 | # any feature of Qt which as been marked as deprecated (the exact warnings 17 | # depend on your compiler). Please consult the documentation of the 18 | # deprecated API in order to know how to port your code away from it. 19 | DEFINES += QT_DEPRECATED_WARNINGS 20 | 21 | # You can also make your code fail to compile if you use deprecated APIs. 22 | # In order to do so, uncomment the following line. 23 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 24 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 25 | 26 | 27 | SOURCES += \ 28 | main.cpp \ 29 | mainwindow.cpp \ 30 | four_pages/home.cpp \ 31 | four_pages/ctrpanel.cpp \ 32 | four_pages/showpanel.cpp\ 33 | dev/qcustomplot.cpp \ 34 | dev/frame.cpp \ 35 | four_pages/calibration.cpp 36 | 37 | 38 | 39 | HEADERS += \ 40 | mainwindow.h \ 41 | four_pages/home.h \ 42 | four_pages/ctrpanel.h \ 43 | four_pages/showpanel.h \ 44 | dev/qcustomplot.h \ 45 | dev/frame.h \ 46 | four_pages/calibration.h 47 | 48 | 49 | 50 | 51 | FORMS += \ 52 | mainwindow.ui \ 53 | four_pages/home.ui \ 54 | four_pages/ctrpanel.ui \ 55 | four_pages/showpanel.ui \ 56 | four_pages/calibration.ui 57 | 58 | RESOURCES += \ 59 | images.qrc 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /GoBao1.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {1c8b73dc-4226-480f-948a-bf59e38c4537} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | 60 | ProjectExplorer.Project.Target.0 61 | 62 | Desktop Qt 5.9.0 MinGW 32bit 63 | Desktop Qt 5.9.0 MinGW 32bit 64 | qt.59.win32_mingw53_kit 65 | 0 66 | 0 67 | 0 68 | 69 | D:/Qt program/build-GoBao1-Desktop_Qt_5_9_0_MinGW_32bit-Debug 70 | 71 | 72 | true 73 | qmake 74 | 75 | QtProjectManager.QMakeBuildStep 76 | true 77 | 78 | false 79 | false 80 | false 81 | 82 | 83 | true 84 | Make 85 | 86 | Qt4ProjectManager.MakeStep 87 | 88 | false 89 | 90 | 91 | 92 | 2 93 | 构建 94 | 95 | ProjectExplorer.BuildSteps.Build 96 | 97 | 98 | 99 | true 100 | Make 101 | 102 | Qt4ProjectManager.MakeStep 103 | 104 | true 105 | clean 106 | 107 | 108 | 1 109 | 清理 110 | 111 | ProjectExplorer.BuildSteps.Clean 112 | 113 | 2 114 | false 115 | 116 | Debug 117 | 118 | Qt4ProjectManager.Qt4BuildConfiguration 119 | 2 120 | true 121 | 122 | 123 | D:/Qt program/build-GoBao1-Desktop_Qt_5_9_0_MinGW_32bit-Release 124 | 125 | 126 | true 127 | qmake 128 | 129 | QtProjectManager.QMakeBuildStep 130 | false 131 | 132 | false 133 | false 134 | false 135 | 136 | 137 | true 138 | Make 139 | 140 | Qt4ProjectManager.MakeStep 141 | 142 | false 143 | 144 | 145 | 146 | 2 147 | 构建 148 | 149 | ProjectExplorer.BuildSteps.Build 150 | 151 | 152 | 153 | true 154 | Make 155 | 156 | Qt4ProjectManager.MakeStep 157 | 158 | true 159 | clean 160 | 161 | 162 | 1 163 | 清理 164 | 165 | ProjectExplorer.BuildSteps.Clean 166 | 167 | 2 168 | false 169 | 170 | Release 171 | 172 | Qt4ProjectManager.Qt4BuildConfiguration 173 | 0 174 | true 175 | 176 | 177 | D:/Qt program/build-GoBao1-Desktop_Qt_5_9_0_MinGW_32bit-Profile 178 | 179 | 180 | true 181 | qmake 182 | 183 | QtProjectManager.QMakeBuildStep 184 | true 185 | 186 | false 187 | true 188 | false 189 | 190 | 191 | true 192 | Make 193 | 194 | Qt4ProjectManager.MakeStep 195 | 196 | false 197 | 198 | 199 | 200 | 2 201 | 构建 202 | 203 | ProjectExplorer.BuildSteps.Build 204 | 205 | 206 | 207 | true 208 | Make 209 | 210 | Qt4ProjectManager.MakeStep 211 | 212 | true 213 | clean 214 | 215 | 216 | 1 217 | 清理 218 | 219 | ProjectExplorer.BuildSteps.Clean 220 | 221 | 2 222 | false 223 | 224 | Profile 225 | 226 | Qt4ProjectManager.Qt4BuildConfiguration 227 | 0 228 | true 229 | 230 | 3 231 | 232 | 233 | 0 234 | 部署 235 | 236 | ProjectExplorer.BuildSteps.Deploy 237 | 238 | 1 239 | 在本地部署 240 | 241 | ProjectExplorer.DefaultDeployConfiguration 242 | 243 | 1 244 | 245 | 246 | false 247 | false 248 | 1000 249 | 250 | true 251 | 252 | false 253 | false 254 | false 255 | false 256 | true 257 | 0.01 258 | 10 259 | true 260 | 1 261 | 25 262 | 263 | 1 264 | true 265 | false 266 | true 267 | valgrind 268 | 269 | 0 270 | 1 271 | 2 272 | 3 273 | 4 274 | 5 275 | 6 276 | 7 277 | 8 278 | 9 279 | 10 280 | 11 281 | 12 282 | 13 283 | 14 284 | 285 | 2 286 | 287 | GoBao1 288 | 289 | Qt4ProjectManager.Qt4RunConfiguration:D:/Qt program/GoBao1/GoBao1.pro 290 | true 291 | 292 | GoBao1.pro 293 | false 294 | 295 | D:/Qt program/build-GoBao1-Desktop_Qt_5_9_0_MinGW_32bit-Debug 296 | 3768 297 | false 298 | true 299 | false 300 | false 301 | true 302 | 303 | 1 304 | 305 | 306 | 307 | ProjectExplorer.Project.TargetCount 308 | 1 309 | 310 | 311 | ProjectExplorer.Project.Updater.FileVersion 312 | 18 313 | 314 | 315 | Version 316 | 18 317 | 318 | 319 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Upper-machine(中控上位机) 2 | Central control upper computer, used to control the motor, monitoring the motor running state of the data. The code mainly realizes UART data communication, as well as data unframe data transmission and other conventional upper computer functions. This is my first project, the project code annotation is more detailed. 3 | 中控上位机,用来控制下位机,监视下位机数据。 4 | 代码中主要实现了UART数据通信,以及数据的解帧数据传输等功能。 5 | 这是我的第一个项目,项目中代码注释的较为详细。 6 | ![image](https://user-images.githubusercontent.com/53364849/141730354-de1e4c76-adb1-4126-a945-7787c49055d2.png) 7 | 8 | ![image](https://user-images.githubusercontent.com/53364849/141730323-12096d42-924c-494a-aba4-49ac66fa750c.png) 9 | 10 | ![image](https://user-images.githubusercontent.com/53364849/141730293-d309fdb1-41b3-4bec-89f9-61d159bb61ec.png) 11 | 12 | ![image](https://user-images.githubusercontent.com/53364849/141730183-b00712c7-1ec9-408f-b633-4d93c5badeb9.png) 13 | 14 | ![GoBao](https://user-images.githubusercontent.com/53364849/141729996-98525cf9-f998-4e8d-b1d0-69de200ddfee.png) 15 | 16 | -------------------------------------------------------------------------------- /dev/frame.cpp: -------------------------------------------------------------------------------- 1 | #include "frame.h" 2 | #include 3 | #include 4 | 5 | #define CHECK_CODE "aa55" //设置帧头用于定位和组帧 6 | 7 | QString FIRST_FRAME = "aa551216310100XXXX"; //用于握手的第一帧 8 | 9 | QString ERR_00 = "aa551216310100XX"; //无效ID 10 | QString ERR_01 = "aa551216310101XX"; //数据长度n超范围; 11 | QString ERR_02 = "aa551216310102XX"; //ID+n超范围; 12 | 13 | QString linked_frame=""; //保存连接后的帧 14 | 15 | //确保输出的是两个连接正确的帧 16 | bool first=false; 17 | bool second=false; 18 | Frame::Frame(){ 19 | 20 | } 21 | //用于选择的函数 因为本页不能使用connec传递参数,所以只让函数直接返回分类值。 22 | /*1 代表握手成功 23 | *0 代表需要进一步处理的帧 24 | *-1代表无效ID 25 | *-2代表输出长度n超范围 26 | *-3代表ID+n超范围 27 | */ 28 | int Frame::CheckFrame(QString str){ 29 | if(str.mid(0,4)==CHECK_CODE){ 30 | if(str==FIRST_FRAME){ 31 | qDebug()<<"握手成功"; 32 | return 1; 33 | //emit connect_sucess(REPLY_FIRST); 34 | }else if (str==ERR_00) { 35 | qDebug()<<"无效ID"; 36 | return -1; 37 | }else if (str==ERR_01) { 38 | qDebug()<<"数据长度n超范围"; 39 | return -2; 40 | }else if (str==ERR_02) { 41 | return -3; 42 | qDebug()<<"ID+n超范围"; 43 | }else{ 44 | return 0; 45 | 46 | } 47 | }else{ 48 | return 0; 49 | } 50 | } 51 | 52 | //用于连接的函数 53 | QString Frame::LinkFram(QString str){ 54 | 55 | if(str.mid(0,4)==CHECK_CODE&&first==false&&linked_frame.length()<124){ 56 | first=true; 57 | linked_frame=""; 58 | linked_frame=str; 59 | }else{ 60 | if(first==true&&linked_frame.length()<124){ //帧前半部分已确定 61 | linked_frame=linked_frame+str; 62 | first=false; 63 | //qDebug()<<"连接后的:"<CRC8(buffer, len); 111 | } 112 | //转义 113 | INT8U Frame::protocol_convert(INT8U ch) 114 | { 115 | if ((converter == 1) && (ch == 0xA5)) 116 | { 117 | converter = 0; 118 | ch = 0x5A; 119 | } 120 | else if ((converter == 1) && (ch == 0x66)) 121 | { 122 | converter = 0; 123 | ch = 0x99; 124 | } 125 | else if ((converter == 1) && (ch == 0x95)) 126 | { 127 | converter = 0; 128 | ch = 0x6A; 129 | } 130 | else if (converter == 1) 131 | { 132 | frame_state = F_ERROR; 133 | } 134 | return ch; 135 | } 136 | //反转义 137 | INT8U Frame::protocol_deconvert(INT8U ch) 138 | { 139 | INT8U rtn = 0; 140 | switch(ch) 141 | { 142 | case 0x5A: 143 | rtn = 0xA5; 144 | break; 145 | case 0x99: 146 | rtn = 0x66; 147 | break; 148 | case 0x6A: 149 | rtn = 0x95; 150 | break; 151 | default: 152 | rtn = ch; 153 | break; 154 | } 155 | return rtn; 156 | } 157 | //组帧,解析帧 158 | bool Frame::PackFrame(Msg src, INT8U * dst, INT8U *len) 159 | { 160 | 161 | // 增加CRC校验 162 | src.crc = CRC8(src.data, src.length); 163 | 164 | dst[0] = 0x5A; 165 | dst[1] = 0x55; 166 | int8_t j = 2; 167 | // lenth 168 | if (src.length == protocol_deconvert(src.length)) 169 | { 170 | dst[j++] = src.length; 171 | } 172 | else 173 | { 174 | dst[j++] = 0x99; 175 | dst[j++] = protocol_deconvert(src.length); 176 | } 177 | //data 178 | for (int i = 0; i < src.length; i++) 179 | { 180 | if (src.data[i] == protocol_deconvert(src.data[i])) 181 | { 182 | dst[j++] = src.data[i]; 183 | } 184 | else 185 | { 186 | dst[j++] = 0x99; 187 | dst[j++] = protocol_deconvert(src.data[i]); 188 | } 189 | } 190 | //crc 191 | if (src.crc == protocol_deconvert(src.crc)) 192 | { 193 | dst[j++] = src.crc; 194 | } 195 | else 196 | { 197 | dst[j++] = 0x99; 198 | dst[j++] = protocol_deconvert(src.crc); 199 | } 200 | 201 | dst[j++] = 0x6A; //packet tail1 202 | dst[j++] = 0x69; //packet tail2 203 | (*len) = j; 204 | 205 | return true; 206 | 207 | } 208 | 209 | 210 | INT8U Frame::UnpackFrame(INT8U ch, Msg *pmsg) 211 | { 212 | if ((ch == 0x5a) && (frame_state != F_HEADER_H) && (frame_state != F_CRC)) 213 | { 214 | frame_state = F_HEADER_H; 215 | } 216 | if ((ch == 0x6a) && (frame_state != F_END_H) && (frame_state != F_CRC)) 217 | { 218 | frame_state = F_ERROR; 219 | } 220 | 221 | if (frame_state == F_HEADER_H) 222 | { 223 | if (ch == 0x5A) 224 | { 225 | data_point = 0; 226 | frame_state = F_HEADER_L; 227 | } 228 | else 229 | { 230 | frame_state = F_ERROR; 231 | } 232 | } 233 | else if (frame_state == F_HEADER_L) 234 | { 235 | if (ch == 0x55) 236 | { 237 | frame_state = F_LENGTH; 238 | } 239 | else 240 | { 241 | frame_state = F_ERROR; 242 | } 243 | } 244 | else if (frame_state == F_LENGTH) 245 | { 246 | if (ch == 0x99) 247 | { 248 | converter = 1; 249 | return 0; 250 | } 251 | pmsg->length = protocol_convert(ch); 252 | if (pmsg->length > MAX_MSG_LEN) 253 | { 254 | frame_state = F_ERROR; 255 | } 256 | else 257 | { 258 | frame_state = F_DATA; 259 | } 260 | } 261 | else if (frame_state == F_DATA) 262 | { 263 | if (pmsg->length == 0)//没有数据区 264 | { 265 | frame_state = F_CRC; 266 | return 0; 267 | } 268 | 269 | if (ch == 0x99) //转义 270 | { 271 | converter = 1; 272 | return 0; 273 | } 274 | 275 | pmsg->data[data_point] = protocol_convert(ch); 276 | data_point++; 277 | if (data_point == pmsg->length) 278 | { 279 | data_point = 0; 280 | frame_state = F_CRC; 281 | } 282 | } 283 | else if (frame_state == F_CRC) 284 | { 285 | if (ch == 0x99) //转义 286 | { 287 | converter = 1; 288 | return 0; 289 | } 290 | pmsg->crc = protocol_convert(ch); 291 | frame_state = F_END_H; 292 | } 293 | else if (frame_state == F_END_H) 294 | { 295 | if (ch != 0x6A) 296 | { 297 | frame_state = F_ERROR; 298 | } 299 | else 300 | { 301 | frame_state = F_END_L; 302 | } 303 | 304 | } 305 | else if (frame_state == F_END_L) 306 | { 307 | if (ch != 0x69) 308 | { 309 | frame_state = F_ERROR; 310 | } 311 | else 312 | { 313 | // frame_state = FRAME_STATE.F_HEADER_H; 314 | //CRC success 315 | if (pmsg->crc == CRC8(pmsg->data, pmsg->length)) 316 | { 317 | frame_state = F_HEADER_H; 318 | return 1; 319 | } 320 | else 321 | { 322 | frame_state = F_ERROR; 323 | } 324 | } 325 | } 326 | 327 | if (frame_state == F_ERROR) 328 | { 329 | frame_state = F_HEADER_H; 330 | return 2; 331 | } 332 | 333 | return 0; 334 | } 335 | */ 336 | 337 | -------------------------------------------------------------------------------- /dev/frame.h: -------------------------------------------------------------------------------- 1 | #include 2 | #ifndef FRAME_H 3 | #define FRAME_H 4 | 5 | 6 | #define INT8U unsigned char 7 | #define INT32U unsigned int 8 | #define INT16U unsigned short 9 | #define MAX_MSG_LEN 128 10 | 11 | typedef struct _Msg_ 12 | { 13 | INT8U length; 14 | INT8U crc; 15 | INT8U data[MAX_MSG_LEN]; 16 | }Msg,*pMsg; 17 | #pragma pack() 18 | 19 | 20 | class Frame 21 | { 22 | // Q_OBJECT 23 | 24 | public: 25 | Frame(); 26 | int CheckFrame(QString str); 27 | QString LinkFram(QString str); 28 | QString CheckCode(QString frame); 29 | QString split(QString Frame); 30 | bool PackFrame(Msg src, INT8U * dst, INT8U *len); //组包 31 | INT8U UnpackFrame(INT8U ch, Msg *pmsg); //解包 32 | QString test1; 33 | 34 | 35 | private: 36 | enum FRAME_STATE 37 | { 38 | F_ERROR = -1, 39 | F_HEADER_H, 40 | F_HEADER_L, 41 | F_LENGTH, 42 | F_DATA, 43 | F_CRC, 44 | F_END_H, 45 | F_END_L, 46 | F_OVER, 47 | }; 48 | 49 | // Encrypt *_encrypt; //加密对象 50 | 51 | int converter = 0; 52 | int data_point = 0; 53 | FRAME_STATE frame_state; 54 | 55 | INT8U protocol_convert(INT8U ch); //转义 56 | INT8U protocol_deconvert(INT8U ch); //反转义 57 | INT8U CRC8( INT8U*buffer, INT8U len); 58 | 59 | }; 60 | 61 | #endif // FRAME_H 62 | -------------------------------------------------------------------------------- /dev/readme.txt: -------------------------------------------------------------------------------- 1 | 这里放的是开发用的第三方工具 2 | -------------------------------------------------------------------------------- /four_pages/calibration.cpp: -------------------------------------------------------------------------------- 1 | #include "calibration.h" 2 | #include "ui_calibration.h" 3 | #include "QDebug" 4 | 5 | Calibration::Calibration(QWidget *parent) : 6 | QWidget(parent), 7 | ui(new Ui::Calibration) 8 | { 9 | ui->setupUi(this); 10 | } 11 | 12 | Calibration::~Calibration() 13 | { 14 | delete ui; 15 | } 16 | 17 | void Calibration::sendEdit(int number,QString text){ 18 | bool ok; 19 | QString base_addr= "5A00"; 20 | QString pre_str="55aa04611104"; 21 | int addr =base_addr.toInt(&ok,16)+number; 22 | QString frame=pre_str+QString("%1").arg(addr,4,16,QLatin1Char('0'))+QString("%1").arg(text.toInt(),2,16,QLatin1Char('0'))+"XXXX"; 23 | // qDebug()<<"frame"<sendEdit(0,ui->cal_0x00_lineEdit->text()); 30 | } 31 | 32 | void Calibration::on_cal_0x01_lineEdit_editingFinished() 33 | { 34 | this->sendEdit(1,ui->cal_0x01_lineEdit->text()); 35 | } 36 | 37 | void Calibration::on_cal_0x02_lineEdit_editingFinished() 38 | { 39 | this->sendEdit(2,ui->cal_0x02_lineEdit->text()); 40 | } 41 | 42 | void Calibration::on_cal_0x03_lineEdit_editingFinished() 43 | { 44 | this->sendEdit(3,ui->cal_0x03_lineEdit->text()); 45 | } 46 | 47 | void Calibration::on_cal_0x04_lineEdit_editingFinished() 48 | { 49 | this->sendEdit(4,ui->cal_0x04_lineEdit->text()); 50 | } 51 | 52 | void Calibration::on_cal_0x05_lineEdit_editingFinished() 53 | { 54 | this->sendEdit(5,ui->cal_0x05_lineEdit->text()); 55 | } 56 | 57 | void Calibration::on_cal_0x06_lineEdit_editingFinished() 58 | { 59 | this->sendEdit(6,ui->cal_0x06_lineEdit->text()); 60 | } 61 | 62 | void Calibration::on_cal_0x07_lineEdit_editingFinished() 63 | { 64 | this->sendEdit(7,ui->cal_0x07_lineEdit->text()); 65 | } 66 | 67 | void Calibration::on_cal_0x08_lineEdit_editingFinished() 68 | { 69 | this->sendEdit(8,ui->cal_0x08_lineEdit->text()); 70 | } 71 | 72 | void Calibration::on_cal_0x09_lineEdit_editingFinished() 73 | { 74 | this->sendEdit(9,ui->cal_0x09_lineEdit->text()); 75 | } 76 | 77 | void Calibration::on_cal_0x0A_lineEdit_editingFinished() 78 | { 79 | this->sendEdit(10,ui->cal_0x0A_lineEdit->text()); 80 | } 81 | 82 | void Calibration::on_cal_0x0B_lineEdit_editingFinished() 83 | { 84 | this->sendEdit(11,ui->cal_0x0B_lineEdit->text()); 85 | } 86 | 87 | void Calibration::on_cal_0x0C_lineEdit_editingFinished() 88 | { 89 | this->sendEdit(12,ui->cal_0x0C_lineEdit->text()); 90 | } 91 | 92 | void Calibration::on_cal_0x0D_lineEdit_editingFinished() 93 | { 94 | this->sendEdit(13,ui->cal_0x0D_lineEdit->text()); 95 | } 96 | 97 | void Calibration::on_cal_0x0E_lineEdit_editingFinished() 98 | { 99 | this->sendEdit(14,ui->cal_0x0E_lineEdit->text()); 100 | } 101 | 102 | void Calibration::on_cal_0x0F_lineEdit_editingFinished() 103 | { 104 | this->sendEdit(15,ui->cal_0x0F_lineEdit->text()); 105 | } 106 | 107 | void Calibration::on_cal_0x10_lineEdit_editingFinished() 108 | { 109 | this->sendEdit(16,ui->cal_0x10_lineEdit->text()); 110 | } 111 | 112 | void Calibration::on_cal_0x11_lineEdit_editingFinished() 113 | { 114 | this->sendEdit(17,ui->cal_0x11_lineEdit->text()); 115 | } 116 | 117 | void Calibration::on_cal_0x12_lineEdit_editingFinished() 118 | { 119 | this->sendEdit(18,ui->cal_0x12_lineEdit->text()); 120 | } 121 | 122 | void Calibration::on_cal_0x13_lineEdit_editingFinished() 123 | { 124 | this->sendEdit(19,ui->cal_0x13_lineEdit->text()); 125 | } 126 | 127 | void Calibration::on_cal_0x14_lineEdit_editingFinished() 128 | { 129 | this->sendEdit(20,ui->cal_0x14_lineEdit->text()); 130 | } 131 | 132 | void Calibration::on_cal_0x15_lineEdit_editingFinished() 133 | { 134 | this->sendEdit(21,ui->cal_0x15_lineEdit->text()); 135 | } 136 | -------------------------------------------------------------------------------- /four_pages/calibration.h: -------------------------------------------------------------------------------- 1 | #ifndef CALIBRATION_H 2 | #define CALIBRATION_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class Calibration; 8 | } 9 | 10 | class Calibration : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit Calibration(QWidget *parent = 0); 16 | ~Calibration(); 17 | 18 | signals: 19 | void send_frame(QString); 20 | 21 | private slots: 22 | 23 | void on_cal_0x00_lineEdit_editingFinished(); 24 | 25 | void on_cal_0x01_lineEdit_editingFinished(); 26 | 27 | void on_cal_0x02_lineEdit_editingFinished(); 28 | 29 | void on_cal_0x03_lineEdit_editingFinished(); 30 | 31 | void on_cal_0x04_lineEdit_editingFinished(); 32 | 33 | void on_cal_0x05_lineEdit_editingFinished(); 34 | 35 | void on_cal_0x06_lineEdit_editingFinished(); 36 | 37 | void on_cal_0x07_lineEdit_editingFinished(); 38 | 39 | void on_cal_0x08_lineEdit_editingFinished(); 40 | 41 | void on_cal_0x09_lineEdit_editingFinished(); 42 | 43 | void on_cal_0x0A_lineEdit_editingFinished(); 44 | 45 | void on_cal_0x0B_lineEdit_editingFinished(); 46 | 47 | void on_cal_0x0C_lineEdit_editingFinished(); 48 | 49 | void on_cal_0x0D_lineEdit_editingFinished(); 50 | 51 | void on_cal_0x0E_lineEdit_editingFinished(); 52 | 53 | void on_cal_0x0F_lineEdit_editingFinished(); 54 | 55 | void on_cal_0x10_lineEdit_editingFinished(); 56 | 57 | void on_cal_0x11_lineEdit_editingFinished(); 58 | 59 | void on_cal_0x12_lineEdit_editingFinished(); 60 | 61 | void on_cal_0x13_lineEdit_editingFinished(); 62 | 63 | void on_cal_0x14_lineEdit_editingFinished(); 64 | 65 | void on_cal_0x15_lineEdit_editingFinished(); 66 | 67 | 68 | private: 69 | Ui::Calibration *ui; 70 | void sendEdit(int, QString); 71 | }; 72 | 73 | #endif // CALIBRATION_H 74 | -------------------------------------------------------------------------------- /four_pages/calibration.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Calibration 4 | 5 | 6 | 7 | 0 8 | 0 9 | 446 10 | 484 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Qt::Horizontal 23 | 24 | 25 | 26 | 40 27 | 20 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 速度控制Kp 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 0 46 | 0 47 | 48 | 49 | 50 | Qt::RightToLeft 51 | 52 | 53 | NULL 54 | 55 | 56 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 57 | 58 | 59 | 60 | 61 | 62 | 63 | 速度控制Ki 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 0 72 | 0 73 | 74 | 75 | 76 | Qt::RightToLeft 77 | 78 | 79 | NULL 80 | 81 | 82 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 83 | 84 | 85 | 86 | 87 | 88 | 89 | Id_Kp 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 0 98 | 0 99 | 100 | 101 | 102 | Qt::RightToLeft 103 | 104 | 105 | NULL 106 | 107 | 108 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 109 | 110 | 111 | 112 | 113 | 114 | 115 | Id_Ki 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 0 124 | 0 125 | 126 | 127 | 128 | Qt::RightToLeft 129 | 130 | 131 | NULL 132 | 133 | 134 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 135 | 136 | 137 | 138 | 139 | 140 | 141 | Iq_Kp 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 0 150 | 0 151 | 152 | 153 | 154 | NULL 155 | 156 | 157 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 158 | 159 | 160 | 161 | 162 | 163 | 164 | Iq_Ki 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 0 173 | 0 174 | 175 | 176 | 177 | NULL 178 | 179 | 180 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 181 | 182 | 183 | 184 | 185 | 186 | 187 | 母线电压系数 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 0 196 | 0 197 | 198 | 199 | 200 | NULL 201 | 202 | 203 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 204 | 205 | 206 | 207 | 208 | 209 | 210 | U相电流系数 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 0 219 | 0 220 | 221 | 222 | 223 | NULL 224 | 225 | 226 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 227 | 228 | 229 | 230 | 231 | 232 | 233 | V相电流系数 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 0 242 | 0 243 | 244 | 245 | 246 | NULL 247 | 248 | 249 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 250 | 251 | 252 | 253 | 254 | 255 | 256 | W相电流系数 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 0 265 | 0 266 | 267 | 268 | 269 | NULL 270 | 271 | 272 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 273 | 274 | 275 | 276 | 277 | 278 | 279 | 踏板零位标定 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 0 288 | 0 289 | 290 | 291 | 292 | NULL 293 | 294 | 295 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | Qt::Horizontal 305 | 306 | 307 | 308 | 34 309 | 20 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 左踏板扭矩系数 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 0 328 | 0 329 | 330 | 331 | 332 | NULL 333 | 334 | 335 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 336 | 337 | 338 | 339 | 340 | 341 | 342 | 右踏板扭矩系数 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 0 351 | 0 352 | 353 | 354 | 355 | NULL 356 | 357 | 358 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 359 | 360 | 361 | 362 | 363 | 364 | 365 | 自定义参数1 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 0 374 | 0 375 | 376 | 377 | 378 | NULL 379 | 380 | 381 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 382 | 383 | 384 | 385 | 386 | 387 | 388 | 自定义参数2 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 0 397 | 0 398 | 399 | 400 | 401 | NULL 402 | 403 | 404 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 405 | 406 | 407 | 408 | 409 | 410 | 411 | 自定义参数3 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 0 420 | 0 421 | 422 | 423 | 424 | NULL 425 | 426 | 427 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 428 | 429 | 430 | 431 | 432 | 433 | 434 | 自定义参数4 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 0 443 | 0 444 | 445 | 446 | 447 | NULL 448 | 449 | 450 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 451 | 452 | 453 | 454 | 455 | 456 | 457 | 自定义参数5 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 0 466 | 0 467 | 468 | 469 | 470 | NULL 471 | 472 | 473 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 474 | 475 | 476 | 477 | 478 | 479 | 480 | 自定义参数6 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 0 489 | 0 490 | 491 | 492 | 493 | NULL 494 | 495 | 496 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 497 | 498 | 499 | 500 | 501 | 502 | 503 | 自定义参数7 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 0 512 | 0 513 | 514 | 515 | 516 | NULL 517 | 518 | 519 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 520 | 521 | 522 | 523 | 524 | 525 | 526 | 自定义参数8 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 0 535 | 0 536 | 537 | 538 | 539 | NULL 540 | 541 | 542 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 543 | 544 | 545 | 546 | 547 | 548 | 549 | 自定义参数9 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 0 558 | 0 559 | 560 | 561 | 562 | NULL 563 | 564 | 565 | Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | Qt::Horizontal 575 | 576 | 577 | 578 | 40 579 | 20 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | Qt::Vertical 590 | 591 | 592 | 593 | 20 594 | 40 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | Qt::Vertical 603 | 604 | 605 | 606 | 20 607 | 40 608 | 609 | 610 | 611 | 612 | 613 | 614 | verticalSpacer 615 | verticalSpacer_2 616 | 617 | 618 | 619 | 620 | -------------------------------------------------------------------------------- /four_pages/ctrpanel.cpp: -------------------------------------------------------------------------------- 1 | #include "ctrpanel.h" 2 | #include "ui_ctrpanel.h" 3 | #include 4 | #include 5 | #include 6 | #include "ui_showpanel.h" 7 | #include 8 | 9 | float all_list[27]; //定义出所有的数据样本 10 | 11 | 12 | Ctrpanel::Ctrpanel(QWidget *parent) : 13 | QWidget(parent), 14 | ui(new Ui::Ctrpanel) 15 | { 16 | ui->setupUi(this); 17 | //向下位机发送数据 18 | connect(ui->sendButton,SIGNAL(clicked()),this, SLOT(trigger_select())); 19 | for(int i=0;i<27;i++){ 20 | all_list[i]=0; //list_map赋初值 21 | } 22 | } 23 | 24 | Ctrpanel::~Ctrpanel() 25 | { 26 | delete ui; 27 | } 28 | //将接收到的帧通过截取直接显示在页面上 29 | //已经修改了指定位置截取帧,符合协议,只需要再略微修改即可。 30 | void Ctrpanel::receive_frame(QString frame){ /*这个接收到的是系列号、地址、命令为 */ 31 | bool ok; 32 | int preface=60; 33 | // int length=frame.mid(10,2).toInt(&ok,16); 34 | // int begin=frame.mid(12,4).toInt(&ok,16); 35 | int length=30; 36 | int begin=0; 37 | // qDebug()<<"frame"<mcu_ox00_lineEdit->setText(QString::number(all_list[0],'f',2)); 48 | ui->mcu_ox01_lineEdit->setText(QString::number(all_list[1],'f',2)); 49 | ui->mcu_ox02_lineEdit->setText(QString::number(all_list[2],'f',2)); 50 | ui->mcu_ox03_lineEdit->setText(QString::number(all_list[3],'f',2)); 51 | ui->mcu_ox04_lineEdit->setText(QString::number(all_list[4],'f',2)); 52 | ui->mcu_ox05_lineEdit->setText(QString::number(all_list[5],'g',10)); 53 | ui->mcu_ox06_lineEdit->setText(QString::number(all_list[6],'g',10)); 54 | ui->mcu_ox07_lineEdit->setText(QString::number(all_list[7],'g',10)); 55 | ui->mcu_ox08_lineEdit->setText(QString::number(all_list[8],'g',10)); 56 | ui->mcu_ox09_lineEdit->setText(QString::number(all_list[9],'g',10)); 57 | ui->mcu_ox0A_lineEdit->setText(QString::number(all_list[10],'g',10)); 58 | ui->mcu_ox0B_lineEdit->setText(QString::number(all_list[11],'f',2)); 59 | ui->mcu_ox0C_lineEdit->setText(QString::number(all_list[12],'f',2)); 60 | ui->mcu_ox0D_lineEdit->setText(QString::number(all_list[13],'f',2)); 61 | ui->mcu_ox0E_lineEdit->setText(QString::number(all_list[14],'f',2)); 62 | ui->mcu_ox0F_lineEdit->setText(QString::number(all_list[15],'f',2)); 63 | ui->mcu_ox10_lineEdit->setText(QString::number(all_list[16],'g',10)); 64 | ui->mcu_ox11_lineEdit->setText(QString::number(all_list[17],'g',10)); 65 | ui->mcu_ox12_lineEdit->setText(QString::number(all_list[18],'g',10)); 66 | ui->mcu_ox13_lineEdit->setText(QString::number(all_list[19],'g',10)); 67 | ui->mcu_ox14_lineEdit->setText(QString::number(all_list[20],'g',10)); 68 | ui->mcu_ox15_lineEdit->setText(QString::number(all_list[21],'g',10)); 69 | ui->mcu_ox16_lineEdit->setText(QString::number(all_list[22],'g',10)); 70 | ui->mcu_ox17_lineEdit->setText(QString::number(all_list[23],'g',10)); 71 | ui->mcu_ox18_lineEdit->setText(QString::number(all_list[24],'g',10)); 72 | ui->mcu_ox19_lineEdit->setText(QString::number(all_list[25],'g',10)); 73 | ui->mcu_ox1A_lineEdit->setText(QString::number(all_list[26],'g',10)); 74 | 75 | //qDebug()<<"控制台接收到帧数据"<exists(dir)){ 96 | Dir->mkdir(dir); //找不到就直接生成对应文件夹 97 | emit send_operation_messgae(0,"生成文件,见D:/GoBao1_operation_Blog/",Qt::blue); 98 | } 99 | delete Dir; 100 | if(!file->exists(file_path)){ 101 | file->open(QIODevice::WriteOnly); 102 | file->close(); //不存在对应的文件就直接生成 103 | emit send_operation_messgae(0,"生成Blog文件,见D:/GoBao1_operation_Blog/下",Qt::blue); 104 | } 105 | if(!file->open(QIODevice::ReadWrite | QIODevice::Text)) { 106 | QMessageBox::critical(this, tr("QMessageBox::critical()"), 107 | "无法打开Blog文件!", 108 | QMessageBox::Retry | QMessageBox::Ignore); 109 | emit send_operation_messgae(0,"无法打开Blog文件",Qt::red); 110 | }else{ 111 | //写数据 112 | emit send_operation_messgae(0,"成功打开Blog文件",Qt::blue); 113 | QString all=file->readAll(); 114 | //qDebug()<<"all"<write(all.toUtf8()+blog.toUtf8()); 118 | file->close(); 119 | delete file; 120 | 121 | QMessageBox::information(this, tr("操作提醒!"), 122 | "成功保存到"+file_path, 123 | QMessageBox::Ok); 124 | } 125 | } 126 | 127 | 128 | /*下边是发送数据所进行的格式化*/ 129 | void Ctrpanel::on_sendButton_clicked() 130 | { 131 | //将Int形转为16进制并在前面补零 132 | QString speed_0x00 = QString("%1").arg(ui->set_0x00->text().toInt(),2,16,QLatin1Char('0')); 133 | QString torque_0x01 = QString("%1").arg((int)(ui->set_0x01->text().toFloat()*100),2,16,QLatin1Char('0')) ; 134 | QString Id_0x02 = QString("%1").arg(ui->set_0x02->text().toInt(),2,16,QLatin1Char('0')); 135 | QString Iq_0x03 = QString("%1").arg(ui->set_0x03->text().toInt(),2,16,QLatin1Char('0')); 136 | QString Vd_0x04 = QString("%1").arg(ui->set_0x04->text().toInt(),2,16,QLatin1Char('0')); 137 | QString Vq_0x05 = QString("%1").arg(ui->set_0x05->text().toInt(),2,16,QLatin1Char('0')); 138 | QString mode_0x06_1 = QString("%1").arg(ui->set_0x06_1->currentIndex(),2,16,QLatin1Char('0')); 139 | QString mode_0x06_2 = QString("%1").arg(ui->set_0x06_2->currentIndex(),2,16,QLatin1Char('0')); 140 | 141 | QString frame=speed_0x00+torque_0x01+Id_0x02+Iq_0x03+Vd_0x04+Vq_0x05+mode_0x06_1+mode_0x06_2; 142 | // qDebug()<<"frame:"<50){ 156 | QDateTime curDateTime=QDateTime::currentDateTime(); 157 | // QString currientTime=curDateTime.toString("yyyy-MM-dd hh:mm:ss"); 158 | // QString blog_name= curDateTime.toString("yyyy-MM-dd"); 159 | QString time=curDateTime.toString("hh:mm:ss"); 160 | // qDebug()<<"currientTime"<exists(path)){ 173 | // Dir->mkdir(dir); 174 | // } 175 | // delete Dir; 176 | if(!file->exists(path)){ 177 | file->open(QIODevice::WriteOnly); 178 | file->close(); 179 | } 180 | qDebug() <<"successful find Blog"; 181 | if(!file->open(QIODevice::ReadWrite | QIODevice::Text)) { 182 | qDebug()<<"Can't open the file!"<readAll(); 186 | qDebug()<<"all"<write(wdata+","+Frame+"\n"); 190 | file->close(); 191 | delete file; 192 | } 193 | cnt=0; 194 | }else{ 195 | cnt++; 196 | } 197 | }else{ 198 | qDebug()<<"没有保存" ; 199 | } 200 | } 201 | */ 202 | 203 | //向操作日志填写内容 204 | void Ctrpanel::operation(QString str, bool checked){ 205 | if(checked){ 206 | emit send_operation_messgae(0,"选中"+str,Qt::blue); 207 | }else{ 208 | emit send_operation_messgae(0,"取消选中"+str,Qt::blue); 209 | } 210 | } 211 | 212 | //下面都是复选框选中后触发的发送信号 213 | void Ctrpanel::on_mcu_ox00_checkbox_clicked(bool checked) 214 | { 215 | QString str=ui->mcu_ox00_checkbox->text(); 216 | int number=0; 217 | emit send_option(str,checked,number); //第1个选中 218 | operation(str,checked); 219 | } 220 | 221 | void Ctrpanel::on_mcu_ox01_checkBox_clicked(bool checked) 222 | { 223 | QString str=ui->mcu_ox01_checkBox->text(); 224 | int number=1; 225 | emit send_option(str,checked,number); //第2个选中 226 | operation(str,checked); 227 | } 228 | 229 | void Ctrpanel::on_mcu_ox02_checkbox_clicked(bool checked) 230 | { 231 | QString str=ui->mcu_ox02_checkbox->text(); 232 | int number=2; emit send_option(str,checked,number); operation(str,checked); 233 | } 234 | 235 | void Ctrpanel::on_mcu_ox03_checkbox_clicked(bool checked) 236 | { 237 | QString str=ui->mcu_ox03_checkbox->text(); 238 | int number=3; emit send_option(str,checked,number); operation(str,checked); 239 | } 240 | 241 | void Ctrpanel::on_mcu_ox04_checkbox_clicked(bool checked) 242 | { 243 | QString str=ui->mcu_ox04_checkbox->text(); 244 | int number=4; emit send_option(str,checked,number); operation(str,checked); 245 | } 246 | 247 | void Ctrpanel::on_mcu_ox05_checkbox_clicked(bool checked) 248 | { 249 | QString str=ui->mcu_ox05_checkbox->text(); 250 | int number=5; emit send_option(str,checked,number); operation(str,checked); 251 | } 252 | 253 | void Ctrpanel::on_mcu_ox06_checkbox_clicked(bool checked) 254 | { 255 | QString str=ui->mcu_ox06_checkbox->text(); 256 | int number=6; emit send_option(str,checked,number); operation(str,checked); 257 | } 258 | 259 | void Ctrpanel::on_mcu_ox07_checkbox_clicked(bool checked) 260 | { 261 | QString str=ui->mcu_ox07_checkbox->text(); 262 | int number=7; emit send_option(str,checked,number); operation(str,checked); 263 | } 264 | 265 | void Ctrpanel::on_mcu_ox08_checkbox_clicked(bool checked) 266 | { 267 | QString str=ui->mcu_ox08_checkbox->text(); 268 | int number=8; emit send_option(str,checked,number); operation(str,checked); 269 | } 270 | 271 | void Ctrpanel::on_mcu_ox09_checkbox_clicked(bool checked) 272 | { 273 | QString str=ui->mcu_ox09_checkbox->text(); 274 | int number=9; emit send_option(str,checked,number); operation(str,checked); 275 | } 276 | 277 | void Ctrpanel::on_mcu_ox0A_checkbox_clicked(bool checked) 278 | { 279 | QString str=ui->mcu_ox0A_checkbox->text(); 280 | int number=10; emit send_option(str,checked,number); operation(str,checked); 281 | } 282 | 283 | void Ctrpanel::on_mcu_ox0B_checkbox_clicked(bool checked) 284 | { 285 | QString str=ui->mcu_ox0B_checkbox->text(); 286 | int number=11; emit send_option(str,checked,number); operation(str,checked); 287 | } 288 | 289 | void Ctrpanel::on_mcu_ox0C_checkbox_clicked(bool checked) 290 | { 291 | QString str=ui->mcu_ox0C_checkbox->text(); 292 | int number=12; emit send_option(str,checked,number); operation(str,checked); 293 | } 294 | 295 | void Ctrpanel::on_mcu_ox0D_checkbox_clicked(bool checked) 296 | { 297 | QString str=ui->mcu_ox0D_checkbox->text(); 298 | int number=13; emit send_option(str,checked,number); operation(str,checked); 299 | } 300 | 301 | void Ctrpanel::on_mcu_ox0E_checkbox_clicked(bool checked) 302 | { 303 | QString str=ui->mcu_ox0E_checkbox->text(); 304 | int number=14; emit send_option(str,checked,number); operation(str,checked); 305 | } 306 | 307 | void Ctrpanel::on_mcu_ox0F_checkbox_clicked(bool checked) 308 | { 309 | QString str=ui->mcu_ox0F_checkbox->text(); 310 | int number=15; emit send_option(str,checked,number); operation(str,checked); 311 | } 312 | 313 | void Ctrpanel::on_mcu_ox10_checkbox_clicked(bool checked) 314 | { 315 | QString str=ui->mcu_ox10_checkbox->text(); 316 | int number=16; emit send_option(str,checked,number); operation(str,checked); 317 | } 318 | 319 | void Ctrpanel::on_mcu_ox11_checkbox_clicked(bool checked) 320 | { 321 | QString str=ui->mcu_ox11_checkbox->text(); 322 | int number=17; emit send_option(str,checked,number); operation(str,checked); 323 | } 324 | 325 | void Ctrpanel::on_mcu_ox12_checkbox_clicked(bool checked) 326 | { 327 | QString str=ui->mcu_ox12_checkbox->text(); 328 | int number=18; emit send_option(str,checked,number); operation(str,checked); 329 | } 330 | 331 | void Ctrpanel::on_mcu_ox13_checkbox_clicked(bool checked) 332 | { 333 | QString str=ui->mcu_ox13_checkbox->text(); 334 | int number=19; emit send_option(str,checked,number); operation(str,checked); 335 | } 336 | 337 | void Ctrpanel::on_mcu_ox14_checkbox_clicked(bool checked) 338 | { 339 | QString str=ui->mcu_ox14_checkbox->text(); 340 | int number=20; emit send_option(str,checked,number); operation(str,checked); 341 | } 342 | 343 | void Ctrpanel::on_mcu_ox15_checkbox_clicked(bool checked) 344 | { 345 | QString str=ui->mcu_ox15_checkbox->text(); 346 | int number=21; emit send_option(str,checked,number); operation(str,checked); 347 | } 348 | 349 | void Ctrpanel::on_mcu_ox16_checkbox_clicked(bool checked) 350 | { 351 | QString str=ui->mcu_ox16_checkbox->text(); 352 | int number=22; emit send_option(str,checked,number); operation(str,checked); 353 | } 354 | 355 | void Ctrpanel::on_mcu_ox17_checkbox_clicked(bool checked) 356 | { 357 | QString str=ui->mcu_ox17_checkbox->text(); 358 | int number=23; emit send_option(str,checked,number); operation(str,checked); 359 | } 360 | 361 | void Ctrpanel::on_mcu_ox18_checkbox_clicked(bool checked) 362 | { 363 | QString str=ui->mcu_ox18_checkbox->text(); 364 | int number=24; emit send_option(str,checked,number); operation(str,checked); 365 | } 366 | 367 | void Ctrpanel::on_mcu_ox19_checkbox_clicked(bool checked) 368 | { 369 | QString str=ui->mcu_ox19_checkbox->text(); 370 | int number=25; emit send_option(str,checked,number); operation(str,checked); 371 | } 372 | 373 | void Ctrpanel::on_mcu_ox1A_checkbox_clicked(bool checked) 374 | { 375 | QString str=ui->mcu_ox1A_checkbox->text(); 376 | int number=26; emit send_option(str,checked,number); operation(str,checked); 377 | } 378 | 379 | //结构体预留备用 380 | typedef struct _Message_{ 381 | QString Rotate; 382 | QString Torque; 383 | QString Voltage; 384 | QString Electricity; 385 | QString Sys_Station; 386 | QString Machine_Tempture; 387 | QString Controller_Tempture; 388 | QString Machine_Zeropoint; 389 | QString Machine_Tempturypoint; 390 | QString Max_AllowedTorque; 391 | QString Malfunction_Output; 392 | }MESSAGE; 393 | -------------------------------------------------------------------------------- /four_pages/ctrpanel.h: -------------------------------------------------------------------------------- 1 | #ifndef CTRPANEL_H 2 | #define CTRPANEL_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class Ctrpanel; 8 | } 9 | 10 | class Ctrpanel : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Ui::Ctrpanel *ui; 16 | explicit Ctrpanel(QWidget *parent = 0); 17 | void Blog(); 18 | 19 | ~Ctrpanel(); 20 | 21 | private slots: 22 | 23 | void receive_frame(QString); //获取到由主页面发来的整个帧数据,准备解用。 24 | 25 | void save_operationblog(QString); 26 | 27 | void on_mcu_ox00_checkbox_clicked(bool checked); 28 | 29 | void on_mcu_ox01_checkBox_clicked(bool checked); 30 | 31 | void on_mcu_ox02_checkbox_clicked(bool checked); 32 | 33 | void on_sendButton_clicked(); 34 | 35 | void on_mcu_ox03_checkbox_clicked(bool checked); 36 | 37 | void on_mcu_ox04_checkbox_clicked(bool checked); 38 | 39 | void on_mcu_ox05_checkbox_clicked(bool checked); 40 | 41 | void on_mcu_ox06_checkbox_clicked(bool checked); 42 | 43 | void on_mcu_ox07_checkbox_clicked(bool checked); 44 | 45 | void on_mcu_ox08_checkbox_clicked(bool checked); 46 | 47 | void on_mcu_ox09_checkbox_clicked(bool checked); 48 | 49 | void on_mcu_ox0A_checkbox_clicked(bool checked); 50 | 51 | void on_mcu_ox0B_checkbox_clicked(bool checked); 52 | 53 | void on_mcu_ox0C_checkbox_clicked(bool checked); 54 | 55 | void on_mcu_ox0D_checkbox_clicked(bool checked); 56 | 57 | void on_mcu_ox0E_checkbox_clicked(bool checked); 58 | 59 | void on_mcu_ox0F_checkbox_clicked(bool checked); 60 | 61 | void on_mcu_ox10_checkbox_clicked(bool checked); 62 | 63 | void on_mcu_ox11_checkbox_clicked(bool checked); 64 | 65 | void on_mcu_ox12_checkbox_clicked(bool checked); 66 | 67 | void on_mcu_ox13_checkbox_clicked(bool checked); 68 | 69 | void on_mcu_ox14_checkbox_clicked(bool checked); 70 | 71 | void on_mcu_ox15_checkbox_clicked(bool checked); 72 | 73 | void on_mcu_ox16_checkbox_clicked(bool checked); 74 | 75 | void on_mcu_ox17_checkbox_clicked(bool checked); 76 | 77 | void on_mcu_ox18_checkbox_clicked(bool checked); 78 | 79 | void on_mcu_ox19_checkbox_clicked(bool checked); 80 | 81 | void on_mcu_ox1A_checkbox_clicked(bool checked); 82 | 83 | 84 | signals: 85 | void send_option(QString,bool,int); //选择后复选框后将选择的数据发送给mainwindow再给shoupanel页面 86 | 87 | void send_operation_messgae(int, QString, QColor); 88 | 89 | void send_frame(QString); 90 | 91 | private: 92 | QByteArray Frame; 93 | void operation(QString,bool); 94 | }; 95 | 96 | #endif // CTRPANEL_H 97 | -------------------------------------------------------------------------------- /four_pages/home.cpp: -------------------------------------------------------------------------------- 1 | #include "home.h" 2 | #include "ui_home.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "dev/frame.h" 10 | #include 11 | #include 12 | 13 | QString REPLY_FIRST = "aa5502613103XXXXXXXXXX"; //上位机向下位机发送的第一帧请求数据 14 | QString OFFSET_SHOW = "0x5200"; 15 | QString OFFSET_CTR = "0x5100"; 16 | Frame *f=new Frame(); 17 | bool connect_state=false; 18 | 19 | Home::Home(QWidget *parent) : 20 | QWidget(parent), 21 | ui(new Ui::Home) 22 | { 23 | ui->setupUi(this); 24 | //查找可用的串口 25 | this->Find_Port(); 26 | //设置波特率下拉菜单默认显示第0项 27 | ui->BaudBox->setCurrentIndex(4); 28 | int BaudIndex=ui->BaudBox->currentIndex(); 29 | switch (BaudIndex) { 30 | case 0: 31 | ui->BaudBox->setCurrentIndex(0);break; 32 | case 1: 33 | ui->BaudBox->setCurrentIndex(1);break; 34 | case 2: 35 | ui->BaudBox->setCurrentIndex(2);break; 36 | case 3: 37 | ui->BaudBox->setCurrentIndex(3);break; 38 | case 5: 39 | ui->BaudBox->setCurrentIndex(4);break; 40 | default: 41 | ui->BaudBox->setCurrentIndex(4);break; 42 | } 43 | 44 | QAction *pActionTest = new QAction(); 45 | 46 | ui->OpenSerialButton->addAction(pActionTest); 47 | 48 | connect(pActionTest,&QAction::triggered,this,&Home::OnActionTest); 49 | 50 | ui->SendButton->setDisabled(true); 51 | 52 | } 53 | 54 | Home::~Home() 55 | { 56 | delete ui; 57 | } 58 | 59 | void Home::on_FindPort_clicked(){ 60 | this->Find_Port(); 61 | } 62 | 63 | void Home::Find_Port(){ 64 | //查找可用的串口 65 | int res=QSerialPortInfo::availablePorts().count(); 66 | // qDebug()<<"串口数量"<OpenSerialButton->setDisabled(true); 70 | }else{ 71 | 72 | foreach (const QSerialPortInfo &info,QSerialPortInfo::availablePorts()) 73 | { 74 | QSerialPort serial; 75 | serial.setPort(info); 76 | //qDebug()<PortBox->addItem(serial.portName()); 81 | serial.close(); 82 | } 83 | emit send_operation_messgae(0,"成功找到串口:"+serial.portName(),Qt::blue); 84 | } 85 | ui->OpenSerialButton->setDisabled(false); 86 | } 87 | } 88 | 89 | //菜单响应函数 90 | void Home::OnActionTest() 91 | { 92 | QDialog dlg; 93 | dlg.setWindowTitle("测试菜单响应"); 94 | dlg.exec(); 95 | } 96 | 97 | void Home::on_OpenSerialButton_clicked() 98 | { 99 | if(ui->OpenSerialButton->text() == tr("打开串口")) 100 | { 101 | ui->SendButton->setDisabled(false); //发送按钮可以使用 102 | serial = new QSerialPort; 103 | //设置串口名 104 | serial->setPortName(ui->PortBox->currentText()); 105 | //打开串口 106 | bool res= serial->open(QIODevice::ReadWrite); 107 | if(res==0){ 108 | emit send_operation_messgae(0,"连接失败",Qt::red); 109 | 110 | }else{ 111 | emit send_operation_messgae(0,"连接成功",Qt::blue); 112 | emit send_upmachine_state(1); 113 | } 114 | //设置波特率 115 | int BaudIndex=ui->BaudBox->currentIndex(); 116 | //设置波特率 117 | switch (BaudIndex) { 118 | case 0: 119 | serial->setBaudRate(QSerialPort::Baud9600);break; 120 | case 1: 121 | serial->setBaudRate(QSerialPort::Baud115200);break; 122 | case 2: 123 | serial->setBaudRate(QSerialPort::Baud38400);break; 124 | case 3: 125 | serial->setBaudRate(QSerialPort::Baud57600);break; 126 | case 5: 127 | serial->setBaudRate(QSerialPort::Baud115200);break; 128 | default: 129 | serial->setBaudRate(QSerialPort::Baud115200);break; 130 | } 131 | 132 | //设置数据位数 133 | switch (ui->BitBox->currentIndex()) 134 | { 135 | case 8: 136 | serial->setDataBits(QSerialPort::Data8);//设置数据位8 137 | break; 138 | default: 139 | break; 140 | } 141 | //设置校验位 142 | switch (ui->ParityBox->currentIndex()) 143 | { 144 | case 0: 145 | serial->setParity(QSerialPort::NoParity); 146 | break; 147 | default: 148 | break; 149 | } 150 | //设置停止位 151 | switch (ui->BitBox->currentIndex()) 152 | { 153 | case 1: 154 | serial->setStopBits(QSerialPort::OneStop);//停止位设置为1 155 | break; 156 | case 2: 157 | serial->setStopBits(QSerialPort::TwoStop); 158 | default: 159 | break; 160 | } 161 | //设置流控制 162 | serial->setFlowControl(QSerialPort::NoFlowControl);//设置为无流控制 163 | 164 | //关闭设置菜单使能 165 | ui->PortBox->setEnabled(false); 166 | ui->BaudBox->setEnabled(false); 167 | ui->BitBox->setEnabled(false); 168 | ui->ParityBox->setEnabled(false); 169 | ui->StopBox->setEnabled(false); 170 | ui->OpenSerialButton->setText(tr("关闭串口")); 171 | 172 | //连接信号槽 173 | QObject::connect(serial,&QSerialPort::readyRead,this,&Home::ReadData); 174 | connect_state=true; 175 | emit send_start_or_not(connect_state); 176 | 177 | } 178 | else 179 | { 180 | ui->SendButton->setDisabled(true); 181 | //关闭串口 182 | serial->clear(); 183 | serial->close(); 184 | serial->deleteLater(); 185 | 186 | //恢复设置使能 187 | ui->PortBox->setEnabled(true); 188 | ui->BaudBox->setEnabled(true); 189 | ui->BitBox->setEnabled(true); 190 | ui->ParityBox->setEnabled(true); 191 | ui->StopBox->setEnabled(true); 192 | ui->OpenSerialButton->setText(tr("打开串口")); 193 | 194 | emit send_upmachine_state(0); 195 | connect_state=false; 196 | emit send_start_or_not(connect_state); 197 | 198 | } 199 | 200 | } 201 | //读取接收到的信息 202 | 203 | 204 | //int i=0; 205 | void Home::ReadData() 206 | { 207 | QString FRAME=""; 208 | QDateTime curDateTime=QDateTime::currentDateTime(); 209 | QString currientTime=curDateTime.toString("yyyy-MM-dd hh:mm:ss"); 210 | QByteArray buf; 211 | QByteArray arr=""; 212 | 213 | buf = serial->readAll(); 214 | 215 | if(!buf.isEmpty()) 216 | { 217 | arr=arr.append(buf); 218 | } 219 | //qDebug()<<"接收到的数据:"<CheckFrame(arr.toHex()); 229 | switch (res) { 230 | case 1: 231 | //emit connect_success(REPLY_FIRST); //调用send发送一帧 232 | qDebug()<<"成功连接,发送一个回复帧"; 233 | break; 234 | case -1: 235 | qDebug()<<"无效ID"; break; 236 | QMessageBox::warning(this,"警告","无效ID!"); 237 | break; 238 | case -2: 239 | qDebug()<<"输出长度n超范围"; break; 240 | QMessageBox::warning(this,"警告","输出长度n超范围!"); 241 | break; 242 | case -3: 243 | qDebug()<<"ID+n超范围"; break; 244 | QMessageBox::warning(this,"警告","ID+n超范围!"); 245 | break; 246 | case 0: 247 | // qDebug()<<"解帧处理"; break; 248 | break; 249 | 250 | default: 251 | qDebug()<<"解帧处理"; break; 252 | break; 253 | } 254 | FRAME=f->LinkFram(arr.toHex()); //获取到剪切后的数据,下一步传输到主页面进行显示 255 | if(FRAME!=0){ //判断一下连接后的是否为0 256 | FRAME=f->CheckCode(FRAME); //校验数据是否 257 | } 258 | if(FRAME!=0){ //判断一下校验后的是否为0 259 | //这里应该根据帧的类型发送到不同界面 260 | // if(frame.mid(4,2)=="13"){ 261 | // //这里发送到 262 | // }else{ 263 | // if(frame.mid(4,2)=="14"){ 264 | // } 265 | // } 266 | emit frame_to_mainwindow(FRAME); //在这里定义一个signal用于向主页面发送数据并用于显示 267 | } 268 | show_receive=arr.toHex(); //将多个帧放在一起显示在界面里 269 | ui->receive_textEdit->append(show_receive); 270 | buf.clear(); 271 | } 272 | void Home::Unpacked_frame(QString frame){ 273 | //下面这部分需要在进一步处理帧的函数里 274 | QString adress=frame.mid(12,4); 275 | bool ok; 276 | int addr = adress.toInt(&ok,16); 277 | int offset_show = OFFSET_SHOW.toInt(&ok,16); 278 | int offset_ctr = OFFSET_CTR.toInt(&ok,16); 279 | if(offset_showreceive_textEdit->clear(); 291 | ui->send_textEdit->clear(); 292 | emit send_operation_messgae(0,"已清空显示框内的接收和发送数据",Qt::blue); 293 | } 294 | 295 | //发送按钮槽函数 296 | void Home::on_SendButton_clicked() 297 | { 298 | // qDebug()<<"on_SendButton_clicked is called"; 299 | if(ui->OpenSerialButton->text() == tr("关闭串口")){ 300 | this->Write_Data(ui->send_textEdit->toPlainText()); 301 | // serial->write(ui->send_textEdit->toPlainText().toLatin1()); 302 | }else{ 303 | // qDebug()<<"串口关闭"; 304 | } 305 | } 306 | 307 | void Home::Write_Data(QString str){ 308 | qDebug()<<"write data"<write(str.toLatin1()); 311 | }else{ 312 | QMessageBox::warning(this,"警告","请检查是否连接!"); 313 | } 314 | } 315 | -------------------------------------------------------------------------------- /four_pages/home.h: -------------------------------------------------------------------------------- 1 | #ifndef HOME_H 2 | #define HOME_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Ui { //Ui是指向Ui界面的指针,对应于home.ui文件 9 | class Home; //指定Ui作用域,作用域Home类里 10 | } 11 | 12 | class Home : public QWidget //Home继承于Qwidget 13 | { 14 | Q_OBJECT //Q_OBJECT间接子类,拥有很多重要的功能,比如信号与槽机制,必须添加 15 | 16 | public: 17 | 18 | explicit Home(QWidget *parent = 0); //explicit(明确的)防止隐式转换 19 | Ui::Home *ui; //修改成public在其他界面可以操纵本页的控件 20 | 21 | void ReadData(); 22 | void OnActionTest(); 23 | QSerialPort *serial; 24 | QString test1=0; 25 | QString show_receive=""; 26 | void Find_Port(); 27 | 28 | 29 | ~Home(); 30 | 31 | signals: 32 | void frame_to_mainwindow(QString); 33 | void send_operation_messgae(int,QString,QColor); 34 | void send_upmachine_state(int); 35 | void send_start_or_not(bool); 36 | 37 | private slots: 38 | 39 | void on_OpenSerialButton_clicked(); 40 | void on_SendButton_clicked(); 41 | void on_ClearData_clicked(); 42 | void on_FindPort_clicked(); 43 | void Write_Data(QString); 44 | 45 | private: 46 | void Unpacked_frame(QString); 47 | 48 | }; 49 | 50 | #endif // HOME_H 51 | -------------------------------------------------------------------------------- /four_pages/home.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Home 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 333 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | Qt::Vertical 21 | 22 | 23 | 24 | 20 25 | 40 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | Qt::Vertical 34 | 35 | 36 | 37 | 20 38 | 40 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 0 48 | 0 49 | 50 | 51 | 52 | 接收数据 53 | 54 | 55 | Qt::AlignCenter 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 0 68 | 0 69 | 70 | 71 | 72 | 串口 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 0 81 | 0 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 0 91 | 0 92 | 93 | 94 | 95 | 波特率 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 0 104 | 0 105 | 106 | 107 | 108 | 109 | 9600 110 | 111 | 112 | 113 | 114 | 19200 115 | 116 | 117 | 118 | 119 | 38400 120 | 121 | 122 | 123 | 124 | 57600 125 | 126 | 127 | 128 | 129 | 115200 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 0 139 | 0 140 | 141 | 142 | 143 | 数据位 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 0 152 | 0 153 | 154 | 155 | 156 | 157 | 8 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 0 167 | 0 168 | 169 | 170 | 171 | 校验位 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 0 180 | 0 181 | 182 | 183 | 184 | 185 | 0 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 0 195 | 0 196 | 197 | 198 | 199 | 停止位 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 0 208 | 0 209 | 210 | 211 | 212 | 213 | 0 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 0 223 | 0 224 | 225 | 226 | 227 | 打开串口 228 | 229 | 230 | 231 | 232 | 233 | 234 | 清除数据 235 | 236 | 237 | 238 | 239 | 240 | 241 | 查找端口 242 | 243 | 244 | 245 | 246 | 247 | 248 | 发送数据 249 | 250 | 251 | 252 | 253 | 254 | 255 | Qt::Vertical 256 | 257 | 258 | 259 | 20 260 | 40 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | Qt::Vertical 269 | 270 | 271 | 272 | 20 273 | 40 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | Qt::Vertical 282 | 283 | 284 | 285 | 20 286 | 40 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | Qt::Vertical 295 | 296 | 297 | 298 | 20 299 | 40 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | Qt::Vertical 308 | 309 | 310 | 311 | 20 312 | 40 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 0 332 | 0 333 | 334 | 335 | 336 | 发送数据 337 | 338 | 339 | Qt::AlignCenter 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | Qt::Horizontal 349 | 350 | 351 | 352 | 40 353 | 20 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 仪表故障码1 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 仪表故障码2 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 软件版本号 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | Qt::Horizontal 396 | 397 | 398 | 399 | 40 400 | 20 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | -------------------------------------------------------------------------------- /four_pages/readme.txt: -------------------------------------------------------------------------------- 1 | 这里放的是四个子页面的代码 2 | -------------------------------------------------------------------------------- /four_pages/showpanel.cpp: -------------------------------------------------------------------------------- 1 | #include "QMap" 2 | #include "showpanel.h" 3 | #include "ui_showpanel.h" 4 | #include "dev/qcustomplot.h" 5 | #include "four_pages/ctrpanel.h" 6 | 7 | QMapall_list_map; //存入所有项的键值对供查找 8 | QMapchosed_list_map; //被选中的复选框 9 | QMapshowgraph_list_map;//用于显示所选图像的map,int代表序号,bool代表是否被选中 10 | //需要再定义一个Map,用于辨别showpanel页面复选框被选中的情况 11 | //默认添加到showpanel的都是没有被选中的,这样方便处理和显示 12 | //在showpanel页面选择后会添加graph显示对应的图像 13 | //可以使用一键多值的方法把上边的三个map合并一下进行优化 14 | 15 | QMapcolor; 16 | bool controller=false; 17 | bool receive_start=false; 18 | QString save_file=""; 19 | 20 | //定义一个Widgets类供后面添加checkbox与lineedit用 21 | Widgets::Widgets(QWidget *parent):QWidget(parent) 22 | { 23 | 24 | //this->resize(232, 27); 25 | formLayout = new QFormLayout(this); 26 | formLayout->setObjectName(QStringLiteral("formLayout")); 27 | formLayout->setHorizontalSpacing(0); 28 | formLayout->setVerticalSpacing(2); 29 | formLayout->setContentsMargins(2, 0, 0, 0); 30 | checkBox = new QCheckBox(this); 31 | checkBox->setObjectName(QStringLiteral("checkBox")); 32 | 33 | formLayout->setWidget(0, QFormLayout::LabelRole, checkBox); 34 | 35 | lineEdit = new QLineEdit(this); 36 | lineEdit->setObjectName(QStringLiteral("lineEdit")); 37 | lineEdit->setReadOnly(true); 38 | 39 | formLayout->setWidget(0, QFormLayout::FieldRole, lineEdit); 40 | 41 | checkBox->setMinimumWidth(200); 42 | checkBox->setMaximumWidth(200); 43 | //checkBox->setChecked(true); 44 | lineEdit->setMinimumWidth(50); 45 | 46 | 47 | } 48 | 49 | class Ctrpanel; 50 | Showpanel::Showpanel(QWidget *parent) : 51 | QWidget(parent), 52 | ui(new Ui::Showpanel) 53 | { 54 | ui->setupUi(this); 55 | this->initial(); 56 | Showpanel::plot(); 57 | 58 | } 59 | 60 | Showpanel::~Showpanel() 61 | { 62 | delete ui; 63 | } 64 | 65 | void Showpanel::plot(){ 66 | 67 | QSharedPointer dateTicker(new QCPAxisTickerDateTime);//日期做X轴 68 | dateTicker->setDateTimeFormat("hh:mm:ss.zzz"); //日期格式(可参考QDateTime::fromString()函数) 69 | ui->customwidget->xAxis->setTicker(dateTicker); //设置X轴为时间轴 70 | ui->customwidget->xAxis->setTickLabels(true); //显示刻度标签 71 | // ui->customwidget->addGraph(ui->customwidget->xAxis, ui->customwidget->yAxis); 72 | 73 | ui->customwidget->setInteractions(QCP::iRangeDrag //可平移 74 | | QCP::iRangeZoom //可滚轮缩放 75 | | QCP::iSelectLegend //可选中图例 76 | | QCP::iSelectAxes ); //可以选中横纵坐标放大缩小、 77 | ui->customwidget->legend->setVisible(true); //设置图例可见 78 | 79 | // ui->customwidget->legend->setFont(QFont("first")); 80 | // ui->customwidget->yAxis->setRange(-1.5, 1.5); 81 | // ui->customwidget->xAxis-> ->setRange(Qt::Horizontal); 82 | 83 | refreshTimer = startTimer(30, Qt::CoarseTimer); //设置刷新频率 84 | sampleTimer = startTimer(500, Qt::CoarseTimer); //设置采样频率 85 | 86 | tLast = getNow(); 87 | lastPoint.setX(getNow()); 88 | 89 | } 90 | 91 | //接收到帧数据,并实时更新ListWidget里的数据 92 | int count=0; 93 | void Showpanel::receive_frame(QString frame){ 94 | QMap::iterator iter = chosed_list_map.begin(); 95 | while (iter != chosed_list_map.end()){ //遍历choose_list_map里的数据,只更新选中的项 96 | QListitem3 = ui->listWidget->findItems(iter.value(),Qt::MatchContains); 97 | if(!item3.isEmpty()){ 98 | Widgets *itemWdt2 = static_cast(ui->listWidget->itemWidget(item3.at(0))); 99 | itemWdt2->lineEdit->setText(frame.mid(iter.key()+10,4)); 100 | } 101 | iter++; 102 | } 103 | 104 | /*下面是画动态图,这部分也非常重要*/ 105 | QMap::iterator iter2 = showgraph_list_map.begin(); 106 | // int len=showgraph_list_map.count(); 107 | int i=0; //showgraph_list_map有多少成员,并按顺序给他们分配graph(这里需要注意分配的graph与map对应关系) 108 | while (iter2 != showgraph_list_map.end()){ //遍历showgraph_list_map里的数据,只更新选中的项 109 | 110 | double xHigh = getNow() - 0.5; 111 | ui->customwidget->xAxis->setRange(xHigh - ui->customwidget->xAxis->range().size(), xHigh); 112 | 113 | ui->customwidget->replot(); 114 | 115 | newPoint.setX(getNow()); 116 | newPoint.setY((frame.mid(iter2.key()*2+12,2)).toFloat()); //接收到的数据 117 | // qDebug() << newPoint.x() << newPoint.y(); 118 | switch (i) { //可以不用switch语句,但是需要再次确认图与变量名是否一一对应 119 | case 0: 120 | ui->customwidget->graph(i)->addData(newPoint.x(), newPoint.y()); //添加值 121 | ui->customwidget->graph(i)->setName(iter2.value()); //graph的名字与color对应 122 | ui->customwidget->graph(i)->setPen(color.find(iter2.key()).value()); 123 | break; 124 | case 1: 125 | ui->customwidget->graph(i)->addData(newPoint.x(), newPoint.y()); //添加值 126 | ui->customwidget->graph(i)->setName(iter2.value()); //graph的名字与color对应 127 | ui->customwidget->graph(i)->setPen(color.find(iter2.key()).value()); 128 | break; 129 | case 2: 130 | ui->customwidget->graph(i)->addData(newPoint.x(), newPoint.y()); //添加值 131 | ui->customwidget->graph(i)->setName(iter2.value()); //graph的名字与color对应 132 | ui->customwidget->graph(i)->setPen(color.find(iter2.key()).value()); 133 | break; 134 | default: 135 | break; 136 | } 137 | lastPoint.setX(newPoint.x()); 138 | lastPoint.setY(newPoint.y()); 139 | ui->customwidget->replot(); 140 | i++; 141 | 142 | iter2++; 143 | } 144 | this->savedata(frame); 145 | 146 | } 147 | 148 | void Showpanel::selected(QString data,bool action,int Number){ 149 | if(action){ 150 | /*下面这部分代码理清思绪,明白操作原理*/ 151 | QListWidgetItem *item = new QListWidgetItem(data); 152 | item->setTextColor(Qt::white); 153 | Widgets *itemWdt = new Widgets(this); 154 | ui->listWidget->addItem(item); 155 | ui->listWidget->setItemWidget(item, itemWdt); 156 | itemWdt->checkBox->setText(data); 157 | itemWdt->lineEdit->setText("NULL"); 158 | //showpanel界面的复选框状态改变 159 | connect(itemWdt->checkBox, SIGNAL(clicked()), this, SLOT(change_graph())); 160 | //获取到指定的item并修改数值 161 | chosed_list_map.insert(Number,all_list_map.find(Number).value()); 162 | }else{ //取消勾选直接删掉对应的item与widget 163 | QList item2; 164 | item2=ui->listWidget->findItems(data,Qt::MatchExactly); 165 | // qDebug()<<"要删除的item"<listWidget->removeItemWidget(item2.at(0)); 169 | } 170 | chosed_list_map.remove(Number); //同时更新chosed_list_map的内容 171 | } 172 | } 173 | 174 | double Showpanel::getNow(){ 175 | return (double)(QDateTime::currentMSecsSinceEpoch()) / 1000.0; 176 | } 177 | 178 | void Showpanel::change_graph(){ 179 | 180 | QMap::iterator iter = chosed_list_map.begin(); 181 | showgraph_list_map.clear(); //这里是遍历的choose_list_map并添加数据,可以改成逐个添加和清除 182 | ui->customwidget->clearGraphs(); 183 | while (iter != chosed_list_map.end()){ //遍历choose_list_map里的数据,只更新选中的项 184 | QListitem3 = ui->listWidget->findItems(iter.value(),Qt::MatchContains); 185 | if(!item3.isEmpty()){ 186 | Widgets *itemWdt2 = static_cast(ui->listWidget->itemWidget(item3.at(0))); 187 | if(itemWdt2->checkBox->checkState()){ 188 | //每次按钮变动都更新一下选中的list,因为是全局map上面receive_frame内自动根据该map更新 189 | // qDebug()<<"update_graph"<checkBox->text(); 190 | showgraph_list_map.insert(iter.key(),iter.value()); 191 | ui->customwidget->addGraph(ui->customwidget->xAxis, ui->customwidget->yAxis); 192 | //update_graph(iter.key()); 193 | } 194 | } 195 | iter++; 196 | } 197 | } 198 | 199 | void Showpanel::on_Save_Button_clicked(bool checked) 200 | { 201 | if(checked){ 202 | if(!receive_start){ 203 | QMessageBox::warning(this,"警告","未开启数据连接"); 204 | ui->Save_Button->setChecked(false); 205 | }else{ 206 | if(chosed_list_map.size()==0){ 207 | QMessageBox::warning(this,"警告","没有数据可以保存"); 208 | ui->Save_Button->setChecked(false); 209 | }else{ 210 | if(save_file!=""){ 211 | QMessageBox::information(this,"提醒","已继续保存"); 212 | emit send_operation_messgae(0,"继续保存数据",Qt::blue); 213 | }else{ 214 | save_file=QFileDialog::getSaveFileName(this, tr("Save As"), "", tr("Curve TagName Files (*.csv)")); 215 | emit send_operation_messgae(0,"保存数据",Qt::blue); 216 | } 217 | // qDebug()<<"save_file:"<Save_Button->setText("停止记录"); 220 | ui->save_state->setText("正在保存..."); 221 | } 222 | } 223 | 224 | }else{ 225 | controller=checked; 226 | ui->Save_Button->setText("记录数据"); 227 | ui->save_state->setText("已停止"); 228 | emit send_operation_messgae(0,"停止保存数据",Qt::red); 229 | } 230 | } 231 | 232 | //从control panel页面搬过来 233 | int cnt=0; 234 | void Showpanel::savedata(QString frame){ 235 | if(controller==true){ 236 | QString chosed_frame=""; 237 | QString chosed_name="时间"; 238 | if(cnt>5){ 239 | QDateTime curDateTime=QDateTime::currentDateTime(); 240 | //QString currientTime=curDateTime.toString("yyyy-MM-dd hh:mm:ss"); 241 | QString time=curDateTime.toString("hh:mm:ss"); 242 | 243 | QFile *file= new QFile(save_file); 244 | // qDebug()<<"file_path:"<exists(save_file)){ 247 | file->open(QIODevice::WriteOnly); 248 | file->close(); 249 | } 250 | if(!file->open(QIODevice::ReadWrite | QIODevice::Text)) { 251 | qDebug()<<"Can't open the file!"<::iterator iter = chosed_list_map.begin(); 254 | while (iter != chosed_list_map.end()){ //遍历choose_list_map里的数据,只更新选中的项 255 | QListitem3 = ui->listWidget->findItems(iter.value(),Qt::MatchContains); 256 | if(!item3.isEmpty()){ 257 | //要用iter.value的值去截取frame并存进chosed_frame里 258 | chosed_name+=","+iter.value(); 259 | chosed_frame=chosed_frame+frame.mid(2*iter.key(),2)+","; 260 | // qDebug()<<"iter.value().toInt():"<readAll(); 266 | // qDebug()<<"all"<write(chosed_name.toLocal8Bit()+"\n"); 271 | // qDebug()<write(wdata+","+chosed_frame.toLatin1()+"\n"); 274 | } 275 | file->close(); 276 | delete file; 277 | } 278 | cnt=0; 279 | }else{ 280 | cnt++; 281 | } 282 | }else{ 283 | // qDebug()<<"没有保存" ; 284 | } 285 | } 286 | 287 | void Showpanel::receive_start_or_not(bool start_or_not){ 288 | receive_start=start_or_not; //判断是否已经与下位机连接并收发数据 289 | } 290 | 291 | //每一个参数对应设定一种颜色 292 | void Showpanel::initial() 293 | { 294 | color.insert(0,QColor(0,0,0)); 295 | color.insert(1,QColor(255,0,0)); 296 | color.insert(2,QColor(0,255,0)); 297 | color.insert(3,QColor(0,0,255)); 298 | color.insert(4,QColor(139,0,0)); 299 | color.insert(5,QColor(205,133,63)); 300 | color.insert(6,QColor(128,128,0)); 301 | color.insert(7,QColor(255,255,0)); 302 | color.insert(8,QColor(0,100,0)); 303 | color.insert(9,QColor(0,128,128)); 304 | color.insert(10,QColor(0,191,255)); 305 | color.insert(11,QColor(0,0,128)); 306 | color.insert(12,QColor(153,50,204)); 307 | color.insert(13,QColor(218,113,214)); 308 | color.insert(14,QColor(220,20,60)); 309 | color.insert(15,QColor(75,0,130)); 310 | color.insert(16,QColor(70,130,180)); 311 | color.insert(17,QColor(0,191,255)); 312 | color.insert(18,QColor(95,158,160)); 313 | color.insert(19,QColor(0,139,139)); 314 | color.insert(20,QColor(144,238,144)); 315 | color.insert(21,QColor(173,255,47)); 316 | color.insert(22,QColor(50,205,50)); 317 | color.insert(23,QColor(127,255,170)); 318 | color.insert(24,QColor(175,238,238)); 319 | color.insert(25,QColor(176,196,222)); 320 | color.insert(26,QColor(0,0,139)); 321 | color.insert(27,QColor(123,104,238)); 322 | { 323 | all_list_map.insert(0,"电机转速"); 324 | all_list_map.insert(1,"电机扭矩"); 325 | all_list_map.insert(2,"母线电压"); 326 | all_list_map.insert(3,"母线电流"); 327 | all_list_map.insert(4,"系统状态"); 328 | all_list_map.insert(5,"电机温度"); 329 | all_list_map.insert(6,"控制器温度"); 330 | all_list_map.insert(7,"电机零位角度"); 331 | all_list_map.insert(8,"电机瞬时角度"); 332 | all_list_map.insert(9,"电机最大允许扭矩"); 333 | all_list_map.insert(10,"故障允许输出"); 334 | all_list_map.insert(11,"踏板速度"); 335 | all_list_map.insert(12,"踏板角度"); 336 | all_list_map.insert(13,"左踏板瞬时扭矩"); 337 | all_list_map.insert(14,"右踏板瞬时扭矩"); 338 | all_list_map.insert(15,"踏板滤波扭矩"); 339 | all_list_map.insert(16,"电机故障码1"); 340 | all_list_map.insert(17,"电机故障码2"); 341 | all_list_map.insert(18,"电机故障码3"); 342 | all_list_map.insert(19,"电机故障码4"); 343 | all_list_map.insert(20,"电机故障码5"); 344 | all_list_map.insert(21,"电机角度磁编故障码"); 345 | all_list_map.insert(22,"曲柄角度磁编故障码"); 346 | all_list_map.insert(23,"通信小板故障码"); 347 | all_list_map.insert(24,"系统运行时钟"); 348 | all_list_map.insert(25,"软件版本号"); 349 | all_list_map.insert(26,"硬件版本号"); 350 | } 351 | } 352 | 353 | /* 354 | QString Rotate; 355 | QString Torque; 356 | QString Voltage; 357 | QString ; 358 | QString Sys_Station; 359 | QString Machine_Tempture; 360 | QString Controller_Tempture; 361 | QString Machine_Zeropoint; 362 | QString Machine_Tempturypoint; 363 | QString Max_AllowedTorque; 364 | QString Malfunction_Output; 365 | */ 366 | -------------------------------------------------------------------------------- /four_pages/showpanel.h: -------------------------------------------------------------------------------- 1 | #ifndef SHOWPANEL_H 2 | #define SHOWPANEL_H 3 | 4 | #include 5 | #include "dev/qcustomplot.h" 6 | #include "ctrpanel.h" 7 | #include "ui_ctrpanel.h" 8 | #include "dev/frame.h" 9 | #include 10 | #include 11 | 12 | namespace Ui { 13 | class Showpanel; 14 | } 15 | 16 | class Widgets: public QWidget 17 | { 18 | Q_OBJECT 19 | public: 20 | explicit Widgets(QWidget *parent = 0); 21 | QCheckBox *checkBox; 22 | QLineEdit *lineEdit; 23 | 24 | private: 25 | QFormLayout *formLayout; 26 | 27 | }; 28 | 29 | class Showpanel : public QWidget 30 | { 31 | Q_OBJECT 32 | 33 | public: 34 | explicit Showpanel(QWidget *parent = 0); 35 | void plot(); 36 | void savedata(QString); 37 | ~Showpanel(); 38 | private: 39 | //画图专用 40 | double getNow(); 41 | int refreshTimer;//刷新图像的定时器 42 | int sampleTimer;//模拟采样的定时器 43 | double tLast; 44 | QPointF newPoint; 45 | QPointF lastPoint; 46 | int cnt; 47 | protected: 48 | // void timerEvent(QTimerEvent *event); 49 | 50 | signals: 51 | // void send_savedata_signal(QString,bool); 52 | void send_operation_messgae(int,QString,QColor); 53 | 54 | private slots: 55 | void selected(QString data,bool action,int Number); //负责接收来自control panel页面选择的结果 56 | void receive_frame(QString); //从mainwindow接收到的帧数据 57 | //void canceled(QString No); 58 | void change_graph(); 59 | void on_Save_Button_clicked(bool checked); 60 | void receive_start_or_not(bool); //判断是否已经开启UART数据通信 61 | 62 | private: 63 | Ui::Showpanel *ui; 64 | QMap map; //item映射到CheckBox 65 | void initial(); 66 | 67 | }; 68 | 69 | #endif // SHOWPANEL_H 70 | -------------------------------------------------------------------------------- /four_pages/showpanel.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Showpanel 4 | 5 | 6 | 7 | 0 8 | 0 9 | 416 10 | 338 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | Form 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | Qt::Horizontal 29 | 30 | 31 | 32 | 40 33 | 20 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | Qt::Horizontal 42 | 43 | 44 | 45 | 128 46 | 17 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | Qt::Horizontal 55 | 56 | 57 | 58 | 48 59 | 17 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | Qt::Horizontal 68 | 69 | 70 | 71 | 38 72 | 17 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | true 81 | 82 | 83 | 函数成员 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 启动保存数据 104 | 105 | 106 | true 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 0 127 | 0 128 | 129 | 130 | 131 | true 132 | 133 | 134 | 示波器 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | QCustomPlot 150 | QWidget 151 |
../../qcustomplot.h
152 | 1 153 |
154 |
155 | 156 | 157 |
158 | -------------------------------------------------------------------------------- /images.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | Images/control.png 4 | Images/Gobao.png 5 | Images/calbration.png 6 | Images/calibration_selected.png 7 | Images/control_selected.png 8 | Images/home.png 9 | Images/home_selected.png 10 | Images/showpanel.png 11 | Images/showpanel_selected.png 12 | Images/communacation.png 13 | Images/communacation2.png 14 | Images/Panel.png 15 | 16 | 17 | -------------------------------------------------------------------------------- /images/Gobao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VGuoGavin/Upper-machine-based-on-Qt/d0d030dcc07d336f3124d6acfcc85f6ba2526c8d/images/Gobao.png -------------------------------------------------------------------------------- /images/Panel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VGuoGavin/Upper-machine-based-on-Qt/d0d030dcc07d336f3124d6acfcc85f6ba2526c8d/images/Panel.png -------------------------------------------------------------------------------- /images/calbration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VGuoGavin/Upper-machine-based-on-Qt/d0d030dcc07d336f3124d6acfcc85f6ba2526c8d/images/calbration.png -------------------------------------------------------------------------------- /images/calibration_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VGuoGavin/Upper-machine-based-on-Qt/d0d030dcc07d336f3124d6acfcc85f6ba2526c8d/images/calibration_selected.png -------------------------------------------------------------------------------- /images/communacation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VGuoGavin/Upper-machine-based-on-Qt/d0d030dcc07d336f3124d6acfcc85f6ba2526c8d/images/communacation.png -------------------------------------------------------------------------------- /images/communacation2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VGuoGavin/Upper-machine-based-on-Qt/d0d030dcc07d336f3124d6acfcc85f6ba2526c8d/images/communacation2.png -------------------------------------------------------------------------------- /images/control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VGuoGavin/Upper-machine-based-on-Qt/d0d030dcc07d336f3124d6acfcc85f6ba2526c8d/images/control.png -------------------------------------------------------------------------------- /images/control_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VGuoGavin/Upper-machine-based-on-Qt/d0d030dcc07d336f3124d6acfcc85f6ba2526c8d/images/control_selected.png -------------------------------------------------------------------------------- /images/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VGuoGavin/Upper-machine-based-on-Qt/d0d030dcc07d336f3124d6acfcc85f6ba2526c8d/images/home.png -------------------------------------------------------------------------------- /images/home_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VGuoGavin/Upper-machine-based-on-Qt/d0d030dcc07d336f3124d6acfcc85f6ba2526c8d/images/home_selected.png -------------------------------------------------------------------------------- /images/readme.txt: -------------------------------------------------------------------------------- 1 | 这里放一些用的图片 2 | -------------------------------------------------------------------------------- /images/showpanel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VGuoGavin/Upper-machine-based-on-Qt/d0d030dcc07d336f3124d6acfcc85f6ba2526c8d/images/showpanel.png -------------------------------------------------------------------------------- /images/showpanel_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VGuoGavin/Upper-machine-based-on-Qt/d0d030dcc07d336f3124d6acfcc85f6ba2526c8d/images/showpanel_selected.png -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include "ui_home.h" 4 | #include "ui_ctrpanel.h" 5 | #include "ui_calibration.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "dev/frame.h" 15 | 16 | #define LOG_COLOR (Qt::blue) 17 | #define LOG_ERR (Qt::red) 18 | 19 | QString currentFilePath=""; 20 | extern Home *p_home=nullptr; 21 | extern Showpanel *p_show=nullptr; 22 | extern Ctrpanel *p_ctrpanel=nullptr; 23 | //extern Calibration *p_calibra=nullptr; 24 | //extern Frame *f=new Frame(); 25 | QString currientTime=""; 26 | 27 | 28 | MainWindow::MainWindow(QWidget *parent) : 29 | QMainWindow(parent), 30 | ui(new Ui::MainWindow) 31 | { 32 | ui->setupUi(this); 33 | setWindowTitle("GoBao control Panel"); 34 | setWindowIcon(QIcon("../GoBao1/Images/communacation2.png")); 35 | 36 | Home *homewidget=new Home(this); //三个页面 37 | p_home=homewidget; 38 | 39 | ctrwidget=new Ctrpanel(this); 40 | p_ctrpanel=ctrwidget; 41 | 42 | showwidget=new Showpanel(this); 43 | p_show=showwidget; 44 | 45 | calibration=new Calibration(this); 46 | 47 | QAction *open_file= new QAction("打开文件"); //添加动作,动作会自动与被连接控件匹配 48 | QAction *save_as= new QAction("另存为"); 49 | QAction *help=new QAction("帮助"); 50 | QAction *about=new QAction("关于"); 51 | 52 | QMenu *File=new QMenu("文件"); //创建菜单栏 53 | QMenu *Setting=new QMenu("设置"); 54 | QMenu *Help=new QMenu("帮助"); 55 | QMenu *About=new QMenu("关于"); 56 | 57 | ui->menuBar->addMenu(File); //添加菜单栏 58 | ui->menuBar->addMenu(Setting); 59 | ui->menuBar->addMenu(Help); 60 | ui->menuBar->addMenu(About); 61 | 62 | File->addAction(open_file); //创建menu并与action连接 63 | File->addAction(save_as); 64 | Help->addAction(help); 65 | About->addAction(about); 66 | 67 | //QMenu *Save=new QMenu("Save as"); //另一种常见menu的方式 68 | //File->addMenu(Save); //直接添加菜单 69 | 70 | ui->stackedWidget->addWidget(homewidget); 71 | ui->stackedWidget->addWidget(ctrwidget); 72 | ui->stackedWidget->addWidget(showwidget); 73 | ui->stackedWidget->setCurrentWidget(homewidget); 74 | ui->stackedWidget->addWidget(calibration); 75 | 76 | connect(open_file,&QAction::triggered,this,&MainWindow::Open_file); //将动作与信号相连 77 | connect(save_as,&QAction::triggered,this,&MainWindow::Save_as); 78 | connect(help,&QAction::triggered,this,&MainWindow::Help); 79 | connect(about,&QAction::triggered,this,&MainWindow::About); 80 | 81 | QDateTime curDateTime=QDateTime::currentDateTime(); 82 | currientTime=curDateTime.toString("yyyy-MM-dd hh:mm:ss"); 83 | qDebug()<<"currientTime"<upmachine_message(0); 116 | //ctrwidget->Blog(); 117 | } 118 | 119 | MainWindow::~MainWindow() 120 | { 121 | delete ui; 122 | } 123 | 124 | //传来的是在control panel界面选择的check box的信号 125 | void MainWindow::receive_option(QString receive_option,bool action,int number){ 126 | emit data_to_showpanel(receive_option,action,number); 127 | //return 0; 128 | } 129 | 130 | void MainWindow::receive_frame(QString data){ 131 | if(data!=0){ 132 | //成功拿到连接好的帧数据 133 | p_home->ui->board_0x00_lineEdit->setText(data); 134 | //将数据发送到control panel页面和show panel页面进行显示 135 | emit frame_to_ctrpanel(data); 136 | emit frame_to_showpanel(data); 137 | } 138 | } 139 | 140 | 141 | 142 | void MainWindow::Open_file() 143 | { 144 | //获取文件绝对路径 145 | QString file_path = QFileDialog::getOpenFileName(this,"open file"," ",tr("CSV文件(*.csv)"));// tr("Allfile(*.*);;mp3file(*.txt)")); 146 | qDebug() <<"file path:"<exists()){ 151 | QByteArray all; 152 | //QByteArray line; 153 | 154 | if(!file->open(QIODevice::ReadWrite | QIODevice::Text)) { 155 | qDebug()<<"Can't open the file!"<atEnd()) { 159 | line = file->readLine(); //循环一行一行的读 160 | qDebug()<< line; 161 | } */ 162 | all=file->readAll(); 163 | qDebug()<< all; 164 | p_home->ui->board_0x00_lineEdit->setText(all); //测试操纵子页面的控件 165 | //写数据 166 | //QByteArray wdata("hello world\n"); 167 | //file->write(wdata); 168 | 169 | file->close(); 170 | delete file; 171 | } 172 | 173 | //ui->lineEdit->setText(line); 174 | } 175 | else{ 176 | qDebug() <<"no file"; 177 | } 178 | 179 | } 180 | void MainWindow::Save_as(){ 181 | 182 | //将数据另存为 183 | QString save_file=QFileDialog::getSaveFileName(this, tr("Save As"), "", tr("Curve TagName Files (*.csv)")); 184 | qDebug()<<"save_file:"<setText("高标,科技"); 189 | CurrentContent->document()->setModified(false); 190 | 191 | if (save_file==""){ 192 | return; 193 | }else{ 194 | currentFilePath=save_file; 195 | if(!file2->open(QIODevice::WriteOnly|QIODevice::Text)){ 196 | qDebug()<<"error about save as path"; 197 | return; 198 | } 199 | QTextStream textStream(file2); 200 | textStream<toPlainText(); 201 | file2->close(); 202 | delete file2; 203 | } 204 | 205 | } 206 | void MainWindow::operation_message(int code, QString text,QColor color){ 207 | qDebug()<<"err code:"<blog_textEdit->moveCursor(QTextCursor::End); 239 | debug_tmp = stringToHtml(debug_tmp, color); 240 | ui->blog_textEdit->append(debug_tmp); 241 | 242 | } 243 | 244 | QString MainWindow::stringToHtml(QString str, QColor crl) 245 | { 246 | QByteArray array; 247 | array.append(crl.red()); 248 | array.append(crl.green()); 249 | array.append(crl.blue()); 250 | QString strC(array.toHex()); 251 | //return (QString("%2").arg(strC).arg(str)); 252 | return (QString("%2").arg(strC).arg(str)); 253 | } 254 | 255 | void MainWindow:: upmachine_message(int res){ 256 | QString str=""; 257 | if(res){ 258 | str=stringToHtml("已连接",Qt::red); 259 | ui->label->setText(str); 260 | }else{ 261 | str=stringToHtml("空闲",Qt::blue); 262 | ui->label->setText(str); 263 | } 264 | } 265 | 266 | 267 | //这里可以用switch语句优化下,多个页面组合在一个函数里 268 | 269 | void MainWindow::on_home_pushButton_clicked() 270 | { 271 | ui->stackedWidget->setCurrentIndex(2); 272 | ui->ctr_pushButton->setChecked(false); 273 | ui->show_pushButton->setChecked(false); 274 | ui->clibration_pushButton->setChecked(false); 275 | } 276 | 277 | void MainWindow::on_ctr_pushButton_clicked() 278 | { 279 | int i=ui->stackedWidget->currentIndex(); 280 | // qDebug()<<"i:"<stackedWidget->setCurrentIndex(3); 282 | ui->home_pushButton->setChecked(false); 283 | ui->show_pushButton->setChecked(false); 284 | ui->clibration_pushButton->setChecked(false); 285 | } 286 | 287 | 288 | void MainWindow::on_show_pushButton_clicked() 289 | { 290 | int j=ui->stackedWidget->currentIndex(); 291 | // qDebug()<<"j:"<stackedWidget->setCurrentIndex(4); 293 | ui->home_pushButton->setChecked(false); 294 | ui->ctr_pushButton->setChecked(false); 295 | ui->clibration_pushButton->setChecked(false); 296 | } 297 | 298 | void MainWindow::on_clibration_pushButton_clicked() 299 | { 300 | int j=ui->stackedWidget->currentIndex(); 301 | // qDebug()<<"j:"<stackedWidget->setCurrentIndex(5); 303 | ui->home_pushButton->setChecked(false); 304 | ui->ctr_pushButton->setChecked(false); 305 | ui->show_pushButton->setChecked(false); 306 | } 307 | 308 | void MainWindow::Help(){ 309 | QMessageBox::information(this,"帮助", "1、程序启动会自动搜索可用端口,如果查找失败可以手动操作,连接后可以收发数据。\n2、示波器界面保存的数据是图像列表中所有项的数据。\n3、控制下位机界面输入数据后回车便将数据放松到下位机。"); 310 | } 311 | void MainWindow::About(){ 312 | QMessageBox::information(this,"关于", "广东高标电子科技中控上位机。"); 313 | } 314 | 315 | 316 | void MainWindow::on_save_pushButton_clicked() 317 | { 318 | emit save_operation_message(ui->blog_textEdit->toPlainText()); 319 | } 320 | 321 | void MainWindow::on_clearblog_pushButton_clicked() 322 | { 323 | ui->blog_textEdit->clear(); 324 | } 325 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include "four_pages/home.h" 7 | #include "four_pages/ctrpanel.h" 8 | #include "four_pages/showpanel.h" 9 | #include "four_pages/calibration.h" 10 | #include 11 | #include 12 | 13 | #define OBJ_SYS 0x01 //系统信息 14 | #define OBJ_SEND 0x02 //发送信息 15 | #define OBJ_RECV 0x03 //接收信息 16 | #define OBJ_ERR 0x04 //错误信息 17 | #define OBJ_REDO 0x05 //重发信息 18 | #define OBJ_DEVI 0x06 //采集设备 19 | #define OBJ_DEVII 0x07 //控制器设备 20 | 21 | namespace Ui { //Ui是指向Ui界面的指针,对应于home.ui文件 22 | class MainWindow; //指定Ui作用域,作用域此类里 23 | } 24 | 25 | class MainWindow : public QMainWindow //继承于Qwidget 26 | { 27 | Q_OBJECT //Q_OBJECT间接子类,拥有很多重要的功能,比如信号与槽机制,必须添加 28 | 29 | public: 30 | explicit MainWindow(QWidget *parent = 0); //explicit(明确的)防止隐式转换 31 | 32 | QString stringToHtml(QString, QColor); 33 | 34 | 35 | ~MainWindow(); //析构函数 36 | 37 | signals: //信号函数,页面内产生信号的函数 38 | void data_to_showpanel(QString,bool,int);//将controlpanel中选择复选框数据发送给showpanel 39 | void frame_to_ctrpanel(QString); //向control panel发送帧数据 40 | void frame_to_showpanel(QString); //向showpanel页面发送帧数据 41 | void save_operation_message(QString); 42 | 43 | private slots: //这里定义的是槽函数,对应的信号来后出发下面的函数 44 | 45 | void Open_file(); 46 | void Save_as(); 47 | void Help(); 48 | void About(); 49 | 50 | void receive_option(QString,bool,int); //从Control panel页面传来的复选框数据 51 | //void pushButton4(); 52 | void receive_frame(QString); 53 | 54 | void operation_message(int,QString,QColor); 55 | 56 | void upmachine_message(int); 57 | 58 | void on_home_pushButton_clicked(); 59 | 60 | void on_ctr_pushButton_clicked(); 61 | 62 | void on_show_pushButton_clicked(); 63 | 64 | void on_clibration_pushButton_clicked(); 65 | 66 | void on_save_pushButton_clicked(); 67 | 68 | void on_clearblog_pushButton_clicked(); 69 | 70 | private: 71 | Ui::MainWindow *ui; 72 | QStackedWidget *pages; 73 | 74 | 75 | Showpanel *showwidget; 76 | Home *homewidget; 77 | Ctrpanel *ctrwidget; 78 | Calibration *calibration; 79 | QAction *open_file; 80 | QAction *save_as; 81 | 82 | }; 83 | 84 | #endif // MAINWINDOW_H 85 | -------------------------------------------------------------------------------- /mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 443 10 | 623 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | MainWindow 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 0 31 | 0 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | :/back/Images/home.png 40 | :/back/Images/home_selected.png:/back/Images/home.png 41 | 42 | 43 | 44 | 60 45 | 60 46 | 47 | 48 | 49 | true 50 | 51 | 52 | true 53 | 54 | 55 | false 56 | 57 | 58 | false 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 0 67 | 0 68 | 69 | 70 | 71 | Qt::LeftToRight 72 | 73 | 74 | 75 | 76 | 77 | 78 | :/back/Images/control.png 79 | :/back/Images/control_selected.png 80 | :/back/Images/control_selected.png 81 | :/back/Images/control_selected.png:/back/Images/control.png 82 | 83 | 84 | 85 | 60 86 | 60 87 | 88 | 89 | 90 | true 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 0 99 | 0 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | :/back/Images/showpanel.png 108 | :/back/Images/showpanel_selected.png:/back/Images/showpanel.png 109 | 110 | 111 | 112 | 60 113 | 60 114 | 115 | 116 | 117 | true 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 0 126 | 0 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | :/back/Images/calbration.png 135 | :/back/Images/calibration_selected.png:/back/Images/calbration.png 136 | 137 | 138 | 139 | 60 140 | 60 141 | 142 | 143 | 144 | true 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 清空日志 159 | 160 | 161 | 162 | 163 | 164 | 165 | 保存操作日志 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 0 180 | 0 181 | 182 | 183 | 184 | true 185 | 186 | 187 | true 188 | 189 | 190 | QFrame::Panel 191 | 192 | 193 | 1 194 | 195 | 196 | 197 | 198 | 0 199 | 0 200 | 201 | 202 | 203 | 204 | 205 | 206 | 0 207 | 0 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | Qt::Horizontal 221 | 222 | 223 | 224 | 40 225 | 20 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 0 235 | 0 236 | 237 | 238 | 239 | 上位机状态: 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | Qt::Horizontal 256 | 257 | 258 | 259 | 40 260 | 20 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | Qt::Horizontal 269 | 270 | 271 | 272 | 40 273 | 20 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | Qt::Horizontal 282 | 283 | 284 | 285 | 40 286 | 20 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | Qt::Horizontal 297 | 298 | 299 | 300 | 40 301 | 20 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 0 316 | 0 317 | 443 318 | 17 319 | 320 | 321 | 322 | 323 | 324 | TopToolBarArea 325 | 326 | 327 | false 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | -------------------------------------------------------------------------------- /版本记录与说明.txt: -------------------------------------------------------------------------------- 1 | ——2021.11.10 上午完成的版本中包括主控界面的选择,但是无法获取到WidgetList里的控件,下一步进行完善。其他部分如数据接收 2 | 帧提取,数据在个页面传递都已经完成。(已删除) 3 | 4 | ——2021.11.10 下午已完成control panel界面与showpanel界面的数据完美同步,并可以实时更新数据。 5 | 6 | ——2021.11.11版本完成了大部分功能,操作提醒初步完成但还有点问题。 7 | 8 | 下个目标画出动态图像。 9 | ——V1版本已经基本完成原计划的所有功能,优化了操作提醒,操作日志储存等功能。 10 | 但因为通讯方式发生,目前不准备继续按照修改后的方案修改,等下位机可以通讯后再根据实际情况修改。 11 | 12 | ——V2版本进行了进一步优化,包括UI设计,规范了函数命名(有可能引起了未察觉的错误),添加注释等。 13 | 14 | ——V3版本做了进一步优化,添加了提醒功能,包括多种操作的操作提醒,画图界面数据选定保存,画图颜色设定,界面添加图像 15 | 各个接口都给定特定的函数,也添加对话框提醒。规范了各个函数变量的名称。 16 | 可优化地方:——可以用一个一键多值的map优化showpanel界面的逻辑,减少map的使用量,逻辑更加清晰。 17 | ——代码需要进一步规范化,许多宏定义等都没有按照开发文档命名。 18 | ——判断UART数据通信的部分不准确。 19 | ——V4版本基本完善了所有的端口,所有枚举类型已经完善,向下位机发送数据的函数也已经完善好,控制界面与示波器界面 20 | 之间的交互已完成控制界面所有的复选框都可以选定,标定界面的数据编辑后自动发送也已完善。 21 | 下一步:与下位机通信测试,解帧操作需要进一步优化。 --------------------------------------------------------------------------------