diff --git a/softwareDirectory/AutoVerScheme/checkwindow.cpp b/softwareDirectory/AutoVerScheme/checkwindow.cpp index dcaa48a..99738d8 100644 --- a/softwareDirectory/AutoVerScheme/checkwindow.cpp +++ b/softwareDirectory/AutoVerScheme/checkwindow.cpp @@ -36,9 +36,10 @@ for(int i=0;i<2;i++) ui->tableWidget_Standard->horizontalHeader()->setSectionResizeMode(i,QHeaderView::Stretch); ui->tableWidgetStd->verticalHeader()->setParent(nullptr); //隐藏行头 - for(int i=1;i<7;i++) + for(int i=1;i<6;i++) ui->tableWidgetStd->horizontalHeader()->setSectionResizeMode(i,QHeaderView::Stretch); ui->tableWidgetStd->setColumnWidth(0, 60); + ui->tableWidgetStd->setColumnWidth(7, 120); ui->tableWidgetCheck->verticalHeader()->setParent(nullptr); ui->comboBoxName->addItem("ALL"); ui->comboBoxModal->addItem("ALL"); @@ -74,6 +75,7 @@ measureCalList.clear(); caliDataListAll.clear(); headTableListAll.clear(); + VisaStanEngineList.clear(); delete ui; } @@ -104,21 +106,30 @@ void CheckWindow::updateStandardTable() { + + + QStringList ValueList; + ValueList.append("请选择角色"); + for (int i=0;itableWidgetStd->clearContents(); ui->tableWidgetStd->setRowCount(0); QString sFilterName = ui->comboBoxName_2->currentText(); QString sFilterModal = ui->comboBoxModal_2->currentText(); QString sFilterDepart = ui->lineEdit_4->text(); QString sFilterNo = ui->lineEditNo_2->text(); - int rowCount=0; - int row=0; + //catDeviceList.clear(); catIdList.clear(); if(programInfo.standard_device_id!=""){ catIdList = programInfo.standard_device_id.split(","); + int row=0; for(int i=catIdList.length()-1;i>=0; i--) { QString id = catIdList[i]; + + QString readraleName; QList result = BaseCommonApi::getCatDeviceInfor(id); if(result.length()>0){ CatDeviceInfor item = result[0]; @@ -148,17 +159,82 @@ ui->tableWidgetStd->setItem(0, 4, new QTableWidgetItem(item.dept_name)); ui->tableWidgetStd->setItem(0, 5, new QTableWidgetItem(item.director_name)); ui->tableWidgetStd->setItem(0, 6, new QTableWidgetItem(item.measure_valid_date)); - row++; + if(RoleList.count()!=0){ + + QComboBox *comboBox=new QComboBox(); + comboBox->addItems(ValueList); + ui->tableWidgetStd->setCellWidget(0, 7,comboBox); + + readraleName=GetdeviceidByRole(id); + if(readraleName!=""){ + comboBox->setCurrentText(readraleName); + } + // 连接下拉框的currentIndexChanged信号到槽函数 + connect(comboBox, &QComboBox::currentTextChanged, this, [this, id,comboBox,i]() { + onComboBoxCurrTextChanged(comboBox->currentText(),id,i); + + }); + }else{ui->tableWidgetStd->setItem(0, 7,new QTableWidgetItem("标准设备"));} + + + //catDeviceList.append(item); }else{ catIdList.removeAt(i); } } result.clear(); + row++; } + } } +void CheckWindow::onComboBoxCurrTextChanged(QString Value,QString device_id,int row) +{ + if(RoleList.count()!=0){ + QString cateory_id=DeviceMeasureEquipmentCatorycatory[0].item_category_id; + for (int i=0;itableWidgetStd->rowCount();i++){ + QComboBox *comboBox = qobject_cast(ui->tableWidgetStd->cellWidget(i, 7)); + if (comboBox) { + QString str=comboBox->currentText(); + if(comboBox->currentText()==Value && i!=row){ + comboBox->setCurrentIndex(0); + } + } + } + + + } + +} +QString CheckWindow::GetdeviceidByRole(QString device_id) +{ + QString cateory_id=DeviceMeasureEquipmentCatorycatory[0].item_category_id; + QString temprole=""; + for(int i=0;itableWidgetMethod->rowCount();i++){ @@ -196,8 +272,13 @@ ui->comboBoxModal_2->setCurrentIndex(0); ui->lineEditNo_2->setText(""); ui->lineEdit_4->setText(""); + //获取检定项分类 及 检定项分类包含的角色 + DeviceMeasureEquipmentCatorycatory = BaseCommonApi::getDeviceMeasureEquipmentCatory(selectTaskList[0].sample_id); + RoleList=BaseCommonApi::getDeviceRoleBydeviceId(DeviceMeasureEquipmentCatorycatory[0].item_category_id); updateStandardTable(); } + //查询角色表信息 getDeviceRoleBydeviceId + //catory[0].item_category_id 检定项目ID ui->stackedWidget->setCurrentIndex(2); } } @@ -206,31 +287,39 @@ { //QStringList idList = programInfo.standard_device_id.split(","); QString sId=""; - for(int i=0;itableWidgetStd->rowCount();i++){ + StandarIdList.clear(); + /*for(int i=0;itableWidgetStd->rowCount();i++){ Qt::CheckState state = ui->tableWidgetStd->item(i,0)->checkState(); if(state == Qt::Checked){ sId = catIdList[i]; break; } - } + }*/ + for(int i=0;itableWidgetStd->rowCount();i++){ + Qt::CheckState state = ui->tableWidgetStd->item(i,0)->checkState(); + if(state == Qt::Checked){ + StandarIdList.append(catIdList[i]); + break; + } + } if(catIdList.count()==1) { - sId = catIdList[0]; + StandarIdList.append(catIdList[0]); } - if(sId==""){ + if(StandarIdList.count()==0){ QMessageBox::warning(this, "提示", "请选择标准设备!"); }else{ //programInfo = BaseCommonApi::getVerificationProgramInfo(sId); - initDeviceInfo(sId); + initDeviceInfo(StandarIdList); ui->stackedWidget->setCurrentIndex(3); } } -void CheckWindow::initDeviceInfo(QString sId) +void CheckWindow::initDeviceInfo(QList sId) { - standardId = sId; + StandarIdList = sId; QString strStyle = QString("QLabel{image:url(%1);}").arg(programInfo.img_path); qDebug() << "strStyle:" << strStyle; ui->label_8->setStyleSheet(strStyle); @@ -246,8 +335,9 @@ connectList.clear(); if(selectTaskList.length()>0) { - QList catory = BaseCommonApi::getDeviceMeasureEquipmentCatory(selectTaskList[0].sample_id); + QList catory = DeviceMeasureEquipmentCatorycatory; if(catory.length() > 0 ){ + ui->lineEdit_category->setText(catory[0].item_category_name); } //idList = programInfo.tested_device_id.split(","); @@ -263,6 +353,7 @@ info.programInterface = addrList[0]; } info.cmdList = BaseCommonApi::getInstructionLib(programInfo.id); + info.rolenName="被检设备"; connectList.append(info); addrList.clear(); } @@ -271,14 +362,19 @@ if(programInfo.standard_device_id!=""){ idList = programInfo.standard_device_id.split(","); + for(const QString& id : idList) { - if(id!=sId) - continue; + //if(id!=CheckId) + // continue; ConnectInfo info; info.id = id; info.type = 1; info.state="未连接"; + if(idList.count()==1) + info.rolenName="标准设备"; + else + info.rolenName=GetdeviceidByRole(id); QList result = BaseCommonApi::getCatDeviceInfor(id); if(result.length()>0){ info.deviceName = result[0].equipment_name; @@ -286,8 +382,9 @@ //更新标准设备表格 rowCount = ui->tableWidget_Standard->rowCount(); ui->tableWidget_Standard->insertRow(rowCount); - ui->tableWidget_Standard->setItem(row, 0, new QTableWidgetItem(info.deviceName)); - ui->tableWidget_Standard->setItem(row, 1, new QTableWidgetItem("OFF")); //设置数据 + ui->tableWidget_Standard->setItem(row, 0, new QTableWidgetItem(info.rolenName)); + ui->tableWidget_Standard->setItem(row, 1, new QTableWidgetItem(info.deviceName)); + ui->tableWidget_Standard->setItem(row, 2, new QTableWidgetItem("OFF")); //设置数据 row++; } result.clear(); @@ -299,6 +396,7 @@ connectList.append(info); addrList.clear(); } + idList.clear(); } rowCount=0; @@ -306,8 +404,9 @@ for(const ConnectInfo& info : connectList){ rowCount = ui->tableWidget_3->rowCount(); ui->tableWidget_3->insertRow(rowCount); - ui->tableWidget_3->setItem(row, 0, new QTableWidgetItem(info.deviceName)); - ui->tableWidget_3->setItem(row, 1, new QTableWidgetItem(info.state)); //设置数据 + ui->tableWidget_3->setItem(row, 0, new QTableWidgetItem(info.rolenName)); + ui->tableWidget_3->setItem(row, 1, new QTableWidgetItem(info.deviceName)); + ui->tableWidget_3->setItem(row, 2, new QTableWidgetItem(info.state)); //设置数据 row++; } //搜索仪器地址放入下拉框 @@ -836,8 +935,8 @@ //修改连接状态 if(getJoinState(addr.visa)) { - ui->tableWidget_3->setItem(currentRow,1,new QTableWidgetItem("ON")); - }else{ ui->tableWidget_3->setItem(currentRow,1,new QTableWidgetItem("OFF"));} + ui->tableWidget_3->setItem(currentRow,2,new QTableWidgetItem("已连接")); + }else{ ui->tableWidget_3->setItem(currentRow,2,new QTableWidgetItem("未连接"));} } } @@ -1087,20 +1186,23 @@ BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam,newCmd; - QString sLabel = headTableList->keys()[curHeadIdx]; - QList dataRes = caliDataList->value(sLabel); - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + constsLable = headTableList->keys()[curHeadIdx]; + QList dataRes = caliDataList->value(constsLable); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); if(idx!=-1) sParam = dataRes[nextGageIndex][idx]; else - sParam = sLabel; //示值误差/回程误差/轻敲位移 - if(standardEngine.getState()){ + sParam = constsLable; //示值误差/回程误差/轻敲位移 + InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); + constDataRes= dataRes[nextGageIndex]; + SendDevice(instrcutLib,&standardEngine); + /*if(standardEngine.getState()){ InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); if(instrcutLib!=nullptr){ QStringList sList = instrcutLib->instruct_config.split(";"); if(sList.length()>0){ for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[nextGageIndex],true); + newCmd = transCmd(sCmd,constsLable,dataRes[nextGageIndex],true); if(newCmd!=""){ standardEngine.sendData(newCmd); qDebug() << "standard cmds:" << newCmd; @@ -1108,7 +1210,7 @@ } } } - } + }*/ currentItem = ui->tableWidgetCheck->item(nextGageIndex, 0); currentItem->setSelected(true); @@ -1145,14 +1247,18 @@ BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam,newCmd; - QString sLabel = headTableList->keys()[curHeadIdx]; - QList dataRes = caliDataList->value(sLabel); - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + constsLable = headTableList->keys()[curHeadIdx]; + QList dataRes = caliDataList->value(constsLable); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); if(idx!=-1) sParam = dataRes[nextGageIndex][idx]; else - sParam = sLabel; //示值误差/回程误差/轻敲位移 - if(standardEngine.getState()){ + sParam = constsLable; //示值误差/回程误差/轻敲位移 + + InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); + constDataRes= dataRes[nextGageIndex]; + SendDevice(instrcutLib,&standardEngine); + /*if(standardEngine.getState()){ InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); if(instrcutLib!=nullptr){ QStringList sList = instrcutLib->instruct_config.split(";"); @@ -1166,7 +1272,7 @@ } } } - } + }*/ currentItem = ui->tableWidgetCheck->item(nextGageIndex, 0); currentItem->setSelected(true); @@ -1241,71 +1347,146 @@ } } } +void CheckWindow::InItcmd(){ + //发送INIt相关指令 + int count=0; + for(const ConnectInfo &visa:connectList) + { + VisaCommonEngine *Engine; + InstructionLib *instrcutLib; + if(connectList.length()>0&&visa.type==0) + { + instrcutLib = getCmdByCheckName(count,"INIT"); + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + instrcutLib = getCmdByCheckName(count,"INIT"); + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } + } + } + } + SendDevice(instrcutLib,Engine); + } +} void CheckWindow::connectDevice(){ - if(connectList.length()>0&&connectList[0].type==0){ - if(deviceEngine.openDevice(connectList[0].programInterface.visa,"Visa")){ - InstructionLib *instrcutLib = getCmdByCheckName(0,"INIT"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - deviceEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } - } - } - } - } - if(connectList.length()>1&&connectList[1].type==1) + int count=0; + QString rolename; + for(const ConnectInfo &visa:connectList) { - if(standardEngine.openDevice(connectList[1].programInterface.visa,"Visa")){ - ui->tableWidget_Standard->setItem(0,1,new QTableWidgetItem("ON")); - InstructionLib *instrcutLib = getCmdByCheckName(1,"INIT"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - standardEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } + VisaCommonEngine Engine; + if(Engine.openDevice(visa.programInterface.visa,"Visa")){ + if(connectList.length()>0&&visa.type==0) + { + deviceEngine=Engine; + } + if(connectList.length()>1&&visa.type==1) + { + if(connectList.count()==2){ + standardEngine=Engine; + }else{ + rolename=this->GetdeviceidByRole(visa.programInterface.device_id); + VisaStanEngineList.insert(rolename,Engine); } + } } + count++; + } - } +void CheckWindow::closeCmd(){ + //发送Close相关指令 + int count=0; + for(const ConnectInfo &visa:connectList) + { + VisaCommonEngine *Engine; + InstructionLib *instrcutLib; + if(connectList.length()>0&&visa.type==0) + { + instrcutLib = getCmdByCheckName(count,"CLOSE"); + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + instrcutLib = getCmdByCheckName(count,"CLOSE"); + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } + } + } + } + SendDevice(instrcutLib,Engine); + } +} void CheckWindow::closeDevice(){ - if(connectList.length()>0&&connectList[0].type==0){ - InstructionLib *instrcutLib = getCmdByCheckName(0,"CLOSE"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - deviceEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } - } - } - deviceEngine.closeDevice(); - } - if(connectList.length()>1&&connectList[1].type==1) + //关闭设备连接 + int count=0; + for(const ConnectInfo &visa:connectList) { - InstructionLib *instrcutLib = getCmdByCheckName(1,"CLOSE"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - standardEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; + VisaCommonEngine *Engine; + if(connectList.length()>0&&visa.type==0) + { + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } } } + } - standardEngine.closeDevice(); + Engine->closeDevice(); + count++; + } } +InstructionLib* CheckWindow::getCmdByRoleName(QString RoleName,QString name){ + for (ConnectInfo& info : connectList) { + if(info.rolenName==RoleName){ + for (InstructionLib& item : info.cmdList) { + if(item.belong_vername==name) + return &item; + } + } + + } + return nullptr; +} +VisaCommonEngine CheckWindow::getVisaCommbyRoleName(QString RoleName){ + VisaCommonEngine visa; + for(VisaCommonEngine &item : VisaStanEngineList){ + if(item.role==RoleName){ + return item; + } + } + return visa; +} InstructionLib* CheckWindow::getCmdByCheckName(int idx,QString name) { if(idx>=0&&idxkeys().count()==0) return; BaseCommonApi::SaveLogInfo(1,QString("-----------------------------------")); if(iEquipType==13) { + connectDevice(); this->Oscilloscopetextflow(); + return; } else if(iEquipType==4){ @@ -1508,70 +1692,69 @@ connectDevice(); for(int i=0;ikeys().length();i++) { + if(Teststate==SyncRunStatus::Stopped){break;}; //每次循环按钮变化 initCheckTable(i); - QString sLabel = headTableList->keys()[i]; - QList dataRes = caliDataList->value(sLabel); - BaseCommonApi::SaveLogInfo(1,QString("开始 %1 测试").arg(sLabel)); + constsLable= headTableList->keys()[i]; + QList dataRes = caliDataList->value(constsLable); + BaseCommonApi::SaveLogInfo(1,QString("开始 %1 测试").arg(constsLable)); for (int i = 0; i < dataRes.count(); ++i) { + if(Teststate==SyncRunStatus::Stopped){break;}; + constDataRes=dataRes[i]; + InItcmd(); QString sRet=""; QString newCmd; double dStdValue=FP_INFINITE,dError=0; QString newdStdValue,newdError; + CheckBackColorUpdate(true,i); //标准器输出 BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam; QStringList TempValue; TempValue.append("检定项目"); - int idx= getIndexByHeader(sLabel,TempValue); + int idx= getIndexByHeader(constsLable,TempValue); if(idx!=-1) sParam = dataRes[i][idx]; - if(standardEngine.getState()){ - InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i],true); - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } + //暂时加到这个地方 后面统一编写 + if(sParam=="DCI"||sParam=="ACI") + { + int idx2= getIndexByHeader(constsLable,QStrTranQStrList("单位")); + if(idx2!=-1) + { + QString ConstUnit=""; + QString v=dataRes[i][idx2].toUpper(); + if(i!=0) + ConstUnit=dataRes[i-1][idx2].toUpper(); + + BaseCommonApi::SaveLogInfo(1,ConstUnit+"-"+v); + if((ConstUnit=="MA" && v=="A") || (ConstUnit=="A" && v=="MA")) + { + if(!this->showDialog("电流换线提醒",QString("换线提醒\n %1 -> %2").arg(ConstUnit).arg(v))) + { + continue; + } } } } + InstructionLib *instrcutLibstan = getCmdByCheckName(1,sParam); + SendDevice(instrcutLibstan,&standardEngine,true); //被检设备读数 BaseCommonApi::SaveLogInfo(1,QString("被检设备输出")); - if(deviceEngine.getState()){ - InstructionLib *instrcutLib = getCmdByCheckName(0,sParam); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "config cmds:" << newCmd; - } - } - } - - newCmd = transCmd(instrcutLib->instruct_read,sLabel,dataRes[i]); - if(newCmd!=""){ - qDebug() << "query cmds:" << newCmd; - sRet = deviceEngine.queryData(newCmd); - TempValue.clear(); - TempValue.append("单位"); - idx= getIndexByHeader(sLabel,TempValue); - dStdValue = transUnit(sRet,dataRes[i][idx]); - } - } + InstructionLib *instrcutLib = getCmdByCheckName(0,sParam); + SendDevice(instrcutLib,&deviceEngine); + sRet=ReadDevice(instrcutLib,&deviceEngine); + if(sRet!=""){ + TempValue.clear(); + TempValue.append("单位"); + idx= getIndexByHeader(constsLable,TempValue); + dStdValue = transUnit(sRet,dataRes[i][idx]); } - autoAdujstData(sLabel,i,dStdValue,dataRes); + autoAdujstData(constsLable,i,dStdValue,dataRes); + CheckBackColorUpdate(false,i); + closeCmd(); Delay_MSec(2000); } - caliDataList->insert(sLabel,dataRes); + caliDataList->insert(constsLable,dataRes); } closeDevice(); } @@ -1842,15 +2025,17 @@ BaseCommonApi::SaveLogInfo(1,QString("---------------------------------------------------")); //首先检索当前检定项目的通道 initCheckTable(i); - QString sLabel = headTableList->keys()[i]; - QList dataRes = caliDataList->value(sLabel); - BaseCommonApi::SaveLogInfo(1,QString("开始 %1 %2 测试").arg(chList[_ch]).arg(sLabel)); + constsLable = headTableList->keys()[i]; + QList dataRes = caliDataList->value(constsLable); + BaseCommonApi::SaveLogInfo(1,QString("开始 %1 %2 测试").arg(chList[_ch]).arg(constsLable)); QString sParam; QString ValueUnit; InstructionLib *instrcutLibOhm; for (int i = 0; i < dataRes.count(); ++i) { TextCount=1; - int _dex= getIndexByHeader(sLabel,QStrTranQStrList("通道")); + constDataRes=dataRes[i]; + InItcmd(); + int _dex= getIndexByHeader(constsLable,QStrTranQStrList("通道")); if(_dex==-1){sParam=chList[_ch];}else{sParam=dataRes[i][_dex];} if(sParam!=chList[_ch]){continue;}; CheckBackColorUpdate(true,i); @@ -1858,80 +2043,46 @@ QString newCmd; double dStdValue=FP_INFINITE; QString newdStdValue; - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); QString sParam; if(idx!=-1) sParam = dataRes[i][idx]; InstructionLib *instrcutLibbiz=getCmdByCheckName(0,sParam); InstructionLib *instrcutLibstan=getCmdByCheckName(1,sParam); //INIT 被检设备 - 标准设备 - BaseCommonApi::SaveLogInfo(1,QString("INIT")); - InstructionLib *InItbiz; - InstructionLib *InItstan; - InItbiz= getCmdByCheckName(0,"INIT"); - InItstan= getCmdByCheckName(1,"INIT"); - if(InItbiz!=nullptr && instrcutLibbiz!=nullptr) - { - if(deviceEngine.getState() ) + instrcutLibOhm= getCmdByCheckName(0,"电阻"); + if(deviceEngine.getState()) { //设置电阻值+ instrcutLibOhm= getCmdByCheckName(0,"电阻"); if(instrcutLibOhm!=nullptr){ QStringList ohmList = instrcutLibOhm->instruct_config.split(";"); - int idxohm= getIndexByHeader(sLabel,QStrTranQStrList("阻抗")); + int idxohm= getIndexByHeader(constsLable,QStrTranQStrList("阻抗")); + if(sParam=="输入电阻"){ + if(!this->showDialog("输入电阻","请接入电阻测试线")){continue;} + idxohm= getIndexByHeader(constsLable,QStrTranQStrList("标称值")); + } + if(idxohm!=-1) { QString onmname="50Ω"; QString CmdOhm; onmname=dataRes[i][idxohm]; - if(onmname=="50Ω"){CmdOhm=ohmList[0];}else{CmdOhm=ohmList[1];}; - newCmd = transCmd(CmdOhm,sLabel,dataRes[i],true); + if(onmname=="50Ω"){CmdOhm=ohmList[0];} + else if(onmname=="75Ω"){CmdOhm=ohmList[1];} + else{ + if(ohmList.count()>2){CmdOhm=ohmList[2];}else{CmdOhm=ohmList[1];}; + } + newCmd = transCmd(CmdOhm,constsLable,constDataRes,true); deviceEngine.sendData(newCmd); } } - //读取配置指令 - - QStringList sList = InItbiz->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - }; - - } - - if(InItstan!=nullptr && instrcutLibstan!=nullptr) - { - if(standardEngine.getState()) - { - //读取配置指令 - QStringList sList = InItstan->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - } - - } + } if(sParam=="频带宽度"){TextCount=2;}; for (int d=0;dinstruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "config cmds:" << newCmd; - } - } - } - newCmd = transCmd(instrcutLibbiz->instruct_read,sLabel,dataRes[i]); - if(newCmd!=""){ - qDebug() << "query cmds:" << newCmd; + SendDevice(instrcutLibbiz,&deviceEngine); + sRet=ReadDevice(instrcutLibbiz,&deviceEngine); + if(sParam=="输入电阻"){ + BaseCommonApi::SaveLogInfo(1,QString("数字万用表控制")); + VisaCommonEngine tempEngine=getVisaCommbyRoleName("数字多用表"); //角色 + InstructionLib *instrcutLibNum=getCmdByRoleName("数字多用表",sParam); + sRet=ReadDevice(instrcutLibNum,&tempEngine); + } + if(sParam=="校准信号"){ + idx= getIndexByHeader(constsLable,QStrTranQStrList("项目")); + if(dataRes[i][idx]=="频率"){ + if(!this->showDialog("输入电阻","请接入频率测试线")){continue;} + BaseCommonApi::SaveLogInfo(1,QString("通用计数器控制")); + VisaCommonEngine tempEngine=getVisaCommbyRoleName("通用计数器"); //角色 + InstructionLib *instrcutLibNum=getCmdByRoleName("通用计数器",sParam); + SendDevice(instrcutLibbiz,&deviceEngine); + sRet=ReadDevice(instrcutLibNum,&tempEngine); + } + } + //测试结果单位转换 + if(sRet!=""){ + idx= getIndexByHeader(constsLable,QStrTranQStrList("单位")); + //ValueUnit + if(idx!=-1) + { + ValueUnit=dataRes[i][idx]; + }else + { + QStringList temp; + temp.append("标准值"); + temp.append("标称值"); + int idx= getIndexByHeader(constsLable,temp); + if(idx!=-1) + ItemUnitSplit(dataRes[i][idx],ValueUnit,ValueUnit); - sRet = deviceEngine.queryData(newCmd); - idx= getIndexByHeader(sLabel,QStrTranQStrList("单位")); - //ValueUnit - if(idx!=-1) - { - ValueUnit=dataRes[i][idx]; - }else - { - QStringList temp; - temp.append("标准值"); - temp.append("标称值"); - int idx= getIndexByHeader(sLabel,temp); - if(idx!=-1) - ItemUnitSplit(dataRes[i][idx],ValueUnit,ValueUnit); - - } - dStdValue = transUnit(sRet,ValueUnit); - - } - } - + } + dStdValue = transUnit(sRet,ValueUnit); } - - autoAdujstData(sLabel,i,dStdValue,dataRes); + autoAdujstData(constsLable,i,dStdValue,dataRes); CheckBackColorUpdate(false,i); + closeCmd(); Delay_MSec(2000); + } //CLOSE 被检设备 - 标准设备 - BaseCommonApi::SaveLogInfo(1,QString("CLOSE")); - InstructionLib *Closebiz; - InstructionLib *Closestan; - Closebiz= getCmdByCheckName(0,"CLOSE"); - Closestan= getCmdByCheckName(1,"CLOSE"); - if(Closestan!=nullptr && instrcutLibstan!=nullptr) - { - if(standardEngine.getState()) - { - //读取配置指令 - QStringList sList = Closestan->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - } - } - // - if(Closebiz!=nullptr && instrcutLibbiz!=nullptr) - { - if(deviceEngine.getState()) - { - //读取配置指令 - QStringList sList = Closebiz->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - }; - - } } - caliDataList->insert(sLabel,dataRes); + caliDataList->insert(constsLable,dataRes); } + closeDevice(); } } void CheckWindow::Delay_MSec(unsigned int msec) @@ -2065,10 +2176,13 @@ void CheckWindow::on_pushButton_stop_clicked() { + Teststate=SyncRunStatus::Stopped; + if(iEquipType==5){ if(timerChart->isActive()) timerChart->stop(); } + } void CheckWindow::on_pushButton_clicked() @@ -2307,6 +2421,42 @@ } //QWidget::keyPressEvent(ev); } +void CheckWindow::SendDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran){ + //发送仪器 进一步封装 + QString newCmd=""; + if(Visa->getState()){ + if(Inst!=nullptr){ + QStringList sList = Inst->instruct_config.split(";"); + if(sList.length()>0){ + for (QString& sCmd : sList){ + newCmd = transCmd(sCmd,constsLable,constDataRes,IsUnitTran); + if(newCmd!=""){ + QString str=Visa->commType; + Visa->sendData(newCmd); + qDebug() << "config cmds:" << newCmd; + } + } + } + } +} +} +QString CheckWindow::ReadDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran){ + //读取仪器 进一步封装 + QString newCmd=""; + QString result=""; + if(Visa->getState()){ + if(Inst!=nullptr){ + newCmd = transCmd(Inst->instruct_read,constsLable,constDataRes,IsUnitTran); + if(newCmd!=""){ + qDebug() << "query cmds:" << newCmd; + result = Visa->queryData(newCmd); + } + } + } + return result; +} + + void CheckWindow::CreateCharts(){ deleteItem(ui->horizontalLayoutChart); @@ -2545,3 +2695,4 @@ caliDataList->insert(sLabel,dataRes); } } + diff --git a/softwareDirectory/AutoVerScheme/checkwindow.cpp b/softwareDirectory/AutoVerScheme/checkwindow.cpp index dcaa48a..99738d8 100644 --- a/softwareDirectory/AutoVerScheme/checkwindow.cpp +++ b/softwareDirectory/AutoVerScheme/checkwindow.cpp @@ -36,9 +36,10 @@ for(int i=0;i<2;i++) ui->tableWidget_Standard->horizontalHeader()->setSectionResizeMode(i,QHeaderView::Stretch); ui->tableWidgetStd->verticalHeader()->setParent(nullptr); //隐藏行头 - for(int i=1;i<7;i++) + for(int i=1;i<6;i++) ui->tableWidgetStd->horizontalHeader()->setSectionResizeMode(i,QHeaderView::Stretch); ui->tableWidgetStd->setColumnWidth(0, 60); + ui->tableWidgetStd->setColumnWidth(7, 120); ui->tableWidgetCheck->verticalHeader()->setParent(nullptr); ui->comboBoxName->addItem("ALL"); ui->comboBoxModal->addItem("ALL"); @@ -74,6 +75,7 @@ measureCalList.clear(); caliDataListAll.clear(); headTableListAll.clear(); + VisaStanEngineList.clear(); delete ui; } @@ -104,21 +106,30 @@ void CheckWindow::updateStandardTable() { + + + QStringList ValueList; + ValueList.append("请选择角色"); + for (int i=0;itableWidgetStd->clearContents(); ui->tableWidgetStd->setRowCount(0); QString sFilterName = ui->comboBoxName_2->currentText(); QString sFilterModal = ui->comboBoxModal_2->currentText(); QString sFilterDepart = ui->lineEdit_4->text(); QString sFilterNo = ui->lineEditNo_2->text(); - int rowCount=0; - int row=0; + //catDeviceList.clear(); catIdList.clear(); if(programInfo.standard_device_id!=""){ catIdList = programInfo.standard_device_id.split(","); + int row=0; for(int i=catIdList.length()-1;i>=0; i--) { QString id = catIdList[i]; + + QString readraleName; QList result = BaseCommonApi::getCatDeviceInfor(id); if(result.length()>0){ CatDeviceInfor item = result[0]; @@ -148,17 +159,82 @@ ui->tableWidgetStd->setItem(0, 4, new QTableWidgetItem(item.dept_name)); ui->tableWidgetStd->setItem(0, 5, new QTableWidgetItem(item.director_name)); ui->tableWidgetStd->setItem(0, 6, new QTableWidgetItem(item.measure_valid_date)); - row++; + if(RoleList.count()!=0){ + + QComboBox *comboBox=new QComboBox(); + comboBox->addItems(ValueList); + ui->tableWidgetStd->setCellWidget(0, 7,comboBox); + + readraleName=GetdeviceidByRole(id); + if(readraleName!=""){ + comboBox->setCurrentText(readraleName); + } + // 连接下拉框的currentIndexChanged信号到槽函数 + connect(comboBox, &QComboBox::currentTextChanged, this, [this, id,comboBox,i]() { + onComboBoxCurrTextChanged(comboBox->currentText(),id,i); + + }); + }else{ui->tableWidgetStd->setItem(0, 7,new QTableWidgetItem("标准设备"));} + + + //catDeviceList.append(item); }else{ catIdList.removeAt(i); } } result.clear(); + row++; } + } } +void CheckWindow::onComboBoxCurrTextChanged(QString Value,QString device_id,int row) +{ + if(RoleList.count()!=0){ + QString cateory_id=DeviceMeasureEquipmentCatorycatory[0].item_category_id; + for (int i=0;itableWidgetStd->rowCount();i++){ + QComboBox *comboBox = qobject_cast(ui->tableWidgetStd->cellWidget(i, 7)); + if (comboBox) { + QString str=comboBox->currentText(); + if(comboBox->currentText()==Value && i!=row){ + comboBox->setCurrentIndex(0); + } + } + } + + + } + +} +QString CheckWindow::GetdeviceidByRole(QString device_id) +{ + QString cateory_id=DeviceMeasureEquipmentCatorycatory[0].item_category_id; + QString temprole=""; + for(int i=0;itableWidgetMethod->rowCount();i++){ @@ -196,8 +272,13 @@ ui->comboBoxModal_2->setCurrentIndex(0); ui->lineEditNo_2->setText(""); ui->lineEdit_4->setText(""); + //获取检定项分类 及 检定项分类包含的角色 + DeviceMeasureEquipmentCatorycatory = BaseCommonApi::getDeviceMeasureEquipmentCatory(selectTaskList[0].sample_id); + RoleList=BaseCommonApi::getDeviceRoleBydeviceId(DeviceMeasureEquipmentCatorycatory[0].item_category_id); updateStandardTable(); } + //查询角色表信息 getDeviceRoleBydeviceId + //catory[0].item_category_id 检定项目ID ui->stackedWidget->setCurrentIndex(2); } } @@ -206,31 +287,39 @@ { //QStringList idList = programInfo.standard_device_id.split(","); QString sId=""; - for(int i=0;itableWidgetStd->rowCount();i++){ + StandarIdList.clear(); + /*for(int i=0;itableWidgetStd->rowCount();i++){ Qt::CheckState state = ui->tableWidgetStd->item(i,0)->checkState(); if(state == Qt::Checked){ sId = catIdList[i]; break; } - } + }*/ + for(int i=0;itableWidgetStd->rowCount();i++){ + Qt::CheckState state = ui->tableWidgetStd->item(i,0)->checkState(); + if(state == Qt::Checked){ + StandarIdList.append(catIdList[i]); + break; + } + } if(catIdList.count()==1) { - sId = catIdList[0]; + StandarIdList.append(catIdList[0]); } - if(sId==""){ + if(StandarIdList.count()==0){ QMessageBox::warning(this, "提示", "请选择标准设备!"); }else{ //programInfo = BaseCommonApi::getVerificationProgramInfo(sId); - initDeviceInfo(sId); + initDeviceInfo(StandarIdList); ui->stackedWidget->setCurrentIndex(3); } } -void CheckWindow::initDeviceInfo(QString sId) +void CheckWindow::initDeviceInfo(QList sId) { - standardId = sId; + StandarIdList = sId; QString strStyle = QString("QLabel{image:url(%1);}").arg(programInfo.img_path); qDebug() << "strStyle:" << strStyle; ui->label_8->setStyleSheet(strStyle); @@ -246,8 +335,9 @@ connectList.clear(); if(selectTaskList.length()>0) { - QList catory = BaseCommonApi::getDeviceMeasureEquipmentCatory(selectTaskList[0].sample_id); + QList catory = DeviceMeasureEquipmentCatorycatory; if(catory.length() > 0 ){ + ui->lineEdit_category->setText(catory[0].item_category_name); } //idList = programInfo.tested_device_id.split(","); @@ -263,6 +353,7 @@ info.programInterface = addrList[0]; } info.cmdList = BaseCommonApi::getInstructionLib(programInfo.id); + info.rolenName="被检设备"; connectList.append(info); addrList.clear(); } @@ -271,14 +362,19 @@ if(programInfo.standard_device_id!=""){ idList = programInfo.standard_device_id.split(","); + for(const QString& id : idList) { - if(id!=sId) - continue; + //if(id!=CheckId) + // continue; ConnectInfo info; info.id = id; info.type = 1; info.state="未连接"; + if(idList.count()==1) + info.rolenName="标准设备"; + else + info.rolenName=GetdeviceidByRole(id); QList result = BaseCommonApi::getCatDeviceInfor(id); if(result.length()>0){ info.deviceName = result[0].equipment_name; @@ -286,8 +382,9 @@ //更新标准设备表格 rowCount = ui->tableWidget_Standard->rowCount(); ui->tableWidget_Standard->insertRow(rowCount); - ui->tableWidget_Standard->setItem(row, 0, new QTableWidgetItem(info.deviceName)); - ui->tableWidget_Standard->setItem(row, 1, new QTableWidgetItem("OFF")); //设置数据 + ui->tableWidget_Standard->setItem(row, 0, new QTableWidgetItem(info.rolenName)); + ui->tableWidget_Standard->setItem(row, 1, new QTableWidgetItem(info.deviceName)); + ui->tableWidget_Standard->setItem(row, 2, new QTableWidgetItem("OFF")); //设置数据 row++; } result.clear(); @@ -299,6 +396,7 @@ connectList.append(info); addrList.clear(); } + idList.clear(); } rowCount=0; @@ -306,8 +404,9 @@ for(const ConnectInfo& info : connectList){ rowCount = ui->tableWidget_3->rowCount(); ui->tableWidget_3->insertRow(rowCount); - ui->tableWidget_3->setItem(row, 0, new QTableWidgetItem(info.deviceName)); - ui->tableWidget_3->setItem(row, 1, new QTableWidgetItem(info.state)); //设置数据 + ui->tableWidget_3->setItem(row, 0, new QTableWidgetItem(info.rolenName)); + ui->tableWidget_3->setItem(row, 1, new QTableWidgetItem(info.deviceName)); + ui->tableWidget_3->setItem(row, 2, new QTableWidgetItem(info.state)); //设置数据 row++; } //搜索仪器地址放入下拉框 @@ -836,8 +935,8 @@ //修改连接状态 if(getJoinState(addr.visa)) { - ui->tableWidget_3->setItem(currentRow,1,new QTableWidgetItem("ON")); - }else{ ui->tableWidget_3->setItem(currentRow,1,new QTableWidgetItem("OFF"));} + ui->tableWidget_3->setItem(currentRow,2,new QTableWidgetItem("已连接")); + }else{ ui->tableWidget_3->setItem(currentRow,2,new QTableWidgetItem("未连接"));} } } @@ -1087,20 +1186,23 @@ BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam,newCmd; - QString sLabel = headTableList->keys()[curHeadIdx]; - QList dataRes = caliDataList->value(sLabel); - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + constsLable = headTableList->keys()[curHeadIdx]; + QList dataRes = caliDataList->value(constsLable); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); if(idx!=-1) sParam = dataRes[nextGageIndex][idx]; else - sParam = sLabel; //示值误差/回程误差/轻敲位移 - if(standardEngine.getState()){ + sParam = constsLable; //示值误差/回程误差/轻敲位移 + InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); + constDataRes= dataRes[nextGageIndex]; + SendDevice(instrcutLib,&standardEngine); + /*if(standardEngine.getState()){ InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); if(instrcutLib!=nullptr){ QStringList sList = instrcutLib->instruct_config.split(";"); if(sList.length()>0){ for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[nextGageIndex],true); + newCmd = transCmd(sCmd,constsLable,dataRes[nextGageIndex],true); if(newCmd!=""){ standardEngine.sendData(newCmd); qDebug() << "standard cmds:" << newCmd; @@ -1108,7 +1210,7 @@ } } } - } + }*/ currentItem = ui->tableWidgetCheck->item(nextGageIndex, 0); currentItem->setSelected(true); @@ -1145,14 +1247,18 @@ BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam,newCmd; - QString sLabel = headTableList->keys()[curHeadIdx]; - QList dataRes = caliDataList->value(sLabel); - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + constsLable = headTableList->keys()[curHeadIdx]; + QList dataRes = caliDataList->value(constsLable); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); if(idx!=-1) sParam = dataRes[nextGageIndex][idx]; else - sParam = sLabel; //示值误差/回程误差/轻敲位移 - if(standardEngine.getState()){ + sParam = constsLable; //示值误差/回程误差/轻敲位移 + + InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); + constDataRes= dataRes[nextGageIndex]; + SendDevice(instrcutLib,&standardEngine); + /*if(standardEngine.getState()){ InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); if(instrcutLib!=nullptr){ QStringList sList = instrcutLib->instruct_config.split(";"); @@ -1166,7 +1272,7 @@ } } } - } + }*/ currentItem = ui->tableWidgetCheck->item(nextGageIndex, 0); currentItem->setSelected(true); @@ -1241,71 +1347,146 @@ } } } +void CheckWindow::InItcmd(){ + //发送INIt相关指令 + int count=0; + for(const ConnectInfo &visa:connectList) + { + VisaCommonEngine *Engine; + InstructionLib *instrcutLib; + if(connectList.length()>0&&visa.type==0) + { + instrcutLib = getCmdByCheckName(count,"INIT"); + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + instrcutLib = getCmdByCheckName(count,"INIT"); + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } + } + } + } + SendDevice(instrcutLib,Engine); + } +} void CheckWindow::connectDevice(){ - if(connectList.length()>0&&connectList[0].type==0){ - if(deviceEngine.openDevice(connectList[0].programInterface.visa,"Visa")){ - InstructionLib *instrcutLib = getCmdByCheckName(0,"INIT"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - deviceEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } - } - } - } - } - if(connectList.length()>1&&connectList[1].type==1) + int count=0; + QString rolename; + for(const ConnectInfo &visa:connectList) { - if(standardEngine.openDevice(connectList[1].programInterface.visa,"Visa")){ - ui->tableWidget_Standard->setItem(0,1,new QTableWidgetItem("ON")); - InstructionLib *instrcutLib = getCmdByCheckName(1,"INIT"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - standardEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } + VisaCommonEngine Engine; + if(Engine.openDevice(visa.programInterface.visa,"Visa")){ + if(connectList.length()>0&&visa.type==0) + { + deviceEngine=Engine; + } + if(connectList.length()>1&&visa.type==1) + { + if(connectList.count()==2){ + standardEngine=Engine; + }else{ + rolename=this->GetdeviceidByRole(visa.programInterface.device_id); + VisaStanEngineList.insert(rolename,Engine); } + } } + count++; + } - } +void CheckWindow::closeCmd(){ + //发送Close相关指令 + int count=0; + for(const ConnectInfo &visa:connectList) + { + VisaCommonEngine *Engine; + InstructionLib *instrcutLib; + if(connectList.length()>0&&visa.type==0) + { + instrcutLib = getCmdByCheckName(count,"CLOSE"); + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + instrcutLib = getCmdByCheckName(count,"CLOSE"); + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } + } + } + } + SendDevice(instrcutLib,Engine); + } +} void CheckWindow::closeDevice(){ - if(connectList.length()>0&&connectList[0].type==0){ - InstructionLib *instrcutLib = getCmdByCheckName(0,"CLOSE"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - deviceEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } - } - } - deviceEngine.closeDevice(); - } - if(connectList.length()>1&&connectList[1].type==1) + //关闭设备连接 + int count=0; + for(const ConnectInfo &visa:connectList) { - InstructionLib *instrcutLib = getCmdByCheckName(1,"CLOSE"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - standardEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; + VisaCommonEngine *Engine; + if(connectList.length()>0&&visa.type==0) + { + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } } } + } - standardEngine.closeDevice(); + Engine->closeDevice(); + count++; + } } +InstructionLib* CheckWindow::getCmdByRoleName(QString RoleName,QString name){ + for (ConnectInfo& info : connectList) { + if(info.rolenName==RoleName){ + for (InstructionLib& item : info.cmdList) { + if(item.belong_vername==name) + return &item; + } + } + + } + return nullptr; +} +VisaCommonEngine CheckWindow::getVisaCommbyRoleName(QString RoleName){ + VisaCommonEngine visa; + for(VisaCommonEngine &item : VisaStanEngineList){ + if(item.role==RoleName){ + return item; + } + } + return visa; +} InstructionLib* CheckWindow::getCmdByCheckName(int idx,QString name) { if(idx>=0&&idxkeys().count()==0) return; BaseCommonApi::SaveLogInfo(1,QString("-----------------------------------")); if(iEquipType==13) { + connectDevice(); this->Oscilloscopetextflow(); + return; } else if(iEquipType==4){ @@ -1508,70 +1692,69 @@ connectDevice(); for(int i=0;ikeys().length();i++) { + if(Teststate==SyncRunStatus::Stopped){break;}; //每次循环按钮变化 initCheckTable(i); - QString sLabel = headTableList->keys()[i]; - QList dataRes = caliDataList->value(sLabel); - BaseCommonApi::SaveLogInfo(1,QString("开始 %1 测试").arg(sLabel)); + constsLable= headTableList->keys()[i]; + QList dataRes = caliDataList->value(constsLable); + BaseCommonApi::SaveLogInfo(1,QString("开始 %1 测试").arg(constsLable)); for (int i = 0; i < dataRes.count(); ++i) { + if(Teststate==SyncRunStatus::Stopped){break;}; + constDataRes=dataRes[i]; + InItcmd(); QString sRet=""; QString newCmd; double dStdValue=FP_INFINITE,dError=0; QString newdStdValue,newdError; + CheckBackColorUpdate(true,i); //标准器输出 BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam; QStringList TempValue; TempValue.append("检定项目"); - int idx= getIndexByHeader(sLabel,TempValue); + int idx= getIndexByHeader(constsLable,TempValue); if(idx!=-1) sParam = dataRes[i][idx]; - if(standardEngine.getState()){ - InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i],true); - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } + //暂时加到这个地方 后面统一编写 + if(sParam=="DCI"||sParam=="ACI") + { + int idx2= getIndexByHeader(constsLable,QStrTranQStrList("单位")); + if(idx2!=-1) + { + QString ConstUnit=""; + QString v=dataRes[i][idx2].toUpper(); + if(i!=0) + ConstUnit=dataRes[i-1][idx2].toUpper(); + + BaseCommonApi::SaveLogInfo(1,ConstUnit+"-"+v); + if((ConstUnit=="MA" && v=="A") || (ConstUnit=="A" && v=="MA")) + { + if(!this->showDialog("电流换线提醒",QString("换线提醒\n %1 -> %2").arg(ConstUnit).arg(v))) + { + continue; + } } } } + InstructionLib *instrcutLibstan = getCmdByCheckName(1,sParam); + SendDevice(instrcutLibstan,&standardEngine,true); //被检设备读数 BaseCommonApi::SaveLogInfo(1,QString("被检设备输出")); - if(deviceEngine.getState()){ - InstructionLib *instrcutLib = getCmdByCheckName(0,sParam); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "config cmds:" << newCmd; - } - } - } - - newCmd = transCmd(instrcutLib->instruct_read,sLabel,dataRes[i]); - if(newCmd!=""){ - qDebug() << "query cmds:" << newCmd; - sRet = deviceEngine.queryData(newCmd); - TempValue.clear(); - TempValue.append("单位"); - idx= getIndexByHeader(sLabel,TempValue); - dStdValue = transUnit(sRet,dataRes[i][idx]); - } - } + InstructionLib *instrcutLib = getCmdByCheckName(0,sParam); + SendDevice(instrcutLib,&deviceEngine); + sRet=ReadDevice(instrcutLib,&deviceEngine); + if(sRet!=""){ + TempValue.clear(); + TempValue.append("单位"); + idx= getIndexByHeader(constsLable,TempValue); + dStdValue = transUnit(sRet,dataRes[i][idx]); } - autoAdujstData(sLabel,i,dStdValue,dataRes); + autoAdujstData(constsLable,i,dStdValue,dataRes); + CheckBackColorUpdate(false,i); + closeCmd(); Delay_MSec(2000); } - caliDataList->insert(sLabel,dataRes); + caliDataList->insert(constsLable,dataRes); } closeDevice(); } @@ -1842,15 +2025,17 @@ BaseCommonApi::SaveLogInfo(1,QString("---------------------------------------------------")); //首先检索当前检定项目的通道 initCheckTable(i); - QString sLabel = headTableList->keys()[i]; - QList dataRes = caliDataList->value(sLabel); - BaseCommonApi::SaveLogInfo(1,QString("开始 %1 %2 测试").arg(chList[_ch]).arg(sLabel)); + constsLable = headTableList->keys()[i]; + QList dataRes = caliDataList->value(constsLable); + BaseCommonApi::SaveLogInfo(1,QString("开始 %1 %2 测试").arg(chList[_ch]).arg(constsLable)); QString sParam; QString ValueUnit; InstructionLib *instrcutLibOhm; for (int i = 0; i < dataRes.count(); ++i) { TextCount=1; - int _dex= getIndexByHeader(sLabel,QStrTranQStrList("通道")); + constDataRes=dataRes[i]; + InItcmd(); + int _dex= getIndexByHeader(constsLable,QStrTranQStrList("通道")); if(_dex==-1){sParam=chList[_ch];}else{sParam=dataRes[i][_dex];} if(sParam!=chList[_ch]){continue;}; CheckBackColorUpdate(true,i); @@ -1858,80 +2043,46 @@ QString newCmd; double dStdValue=FP_INFINITE; QString newdStdValue; - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); QString sParam; if(idx!=-1) sParam = dataRes[i][idx]; InstructionLib *instrcutLibbiz=getCmdByCheckName(0,sParam); InstructionLib *instrcutLibstan=getCmdByCheckName(1,sParam); //INIT 被检设备 - 标准设备 - BaseCommonApi::SaveLogInfo(1,QString("INIT")); - InstructionLib *InItbiz; - InstructionLib *InItstan; - InItbiz= getCmdByCheckName(0,"INIT"); - InItstan= getCmdByCheckName(1,"INIT"); - if(InItbiz!=nullptr && instrcutLibbiz!=nullptr) - { - if(deviceEngine.getState() ) + instrcutLibOhm= getCmdByCheckName(0,"电阻"); + if(deviceEngine.getState()) { //设置电阻值+ instrcutLibOhm= getCmdByCheckName(0,"电阻"); if(instrcutLibOhm!=nullptr){ QStringList ohmList = instrcutLibOhm->instruct_config.split(";"); - int idxohm= getIndexByHeader(sLabel,QStrTranQStrList("阻抗")); + int idxohm= getIndexByHeader(constsLable,QStrTranQStrList("阻抗")); + if(sParam=="输入电阻"){ + if(!this->showDialog("输入电阻","请接入电阻测试线")){continue;} + idxohm= getIndexByHeader(constsLable,QStrTranQStrList("标称值")); + } + if(idxohm!=-1) { QString onmname="50Ω"; QString CmdOhm; onmname=dataRes[i][idxohm]; - if(onmname=="50Ω"){CmdOhm=ohmList[0];}else{CmdOhm=ohmList[1];}; - newCmd = transCmd(CmdOhm,sLabel,dataRes[i],true); + if(onmname=="50Ω"){CmdOhm=ohmList[0];} + else if(onmname=="75Ω"){CmdOhm=ohmList[1];} + else{ + if(ohmList.count()>2){CmdOhm=ohmList[2];}else{CmdOhm=ohmList[1];}; + } + newCmd = transCmd(CmdOhm,constsLable,constDataRes,true); deviceEngine.sendData(newCmd); } } - //读取配置指令 - - QStringList sList = InItbiz->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - }; - - } - - if(InItstan!=nullptr && instrcutLibstan!=nullptr) - { - if(standardEngine.getState()) - { - //读取配置指令 - QStringList sList = InItstan->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - } - - } + } if(sParam=="频带宽度"){TextCount=2;}; for (int d=0;dinstruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "config cmds:" << newCmd; - } - } - } - newCmd = transCmd(instrcutLibbiz->instruct_read,sLabel,dataRes[i]); - if(newCmd!=""){ - qDebug() << "query cmds:" << newCmd; + SendDevice(instrcutLibbiz,&deviceEngine); + sRet=ReadDevice(instrcutLibbiz,&deviceEngine); + if(sParam=="输入电阻"){ + BaseCommonApi::SaveLogInfo(1,QString("数字万用表控制")); + VisaCommonEngine tempEngine=getVisaCommbyRoleName("数字多用表"); //角色 + InstructionLib *instrcutLibNum=getCmdByRoleName("数字多用表",sParam); + sRet=ReadDevice(instrcutLibNum,&tempEngine); + } + if(sParam=="校准信号"){ + idx= getIndexByHeader(constsLable,QStrTranQStrList("项目")); + if(dataRes[i][idx]=="频率"){ + if(!this->showDialog("输入电阻","请接入频率测试线")){continue;} + BaseCommonApi::SaveLogInfo(1,QString("通用计数器控制")); + VisaCommonEngine tempEngine=getVisaCommbyRoleName("通用计数器"); //角色 + InstructionLib *instrcutLibNum=getCmdByRoleName("通用计数器",sParam); + SendDevice(instrcutLibbiz,&deviceEngine); + sRet=ReadDevice(instrcutLibNum,&tempEngine); + } + } + //测试结果单位转换 + if(sRet!=""){ + idx= getIndexByHeader(constsLable,QStrTranQStrList("单位")); + //ValueUnit + if(idx!=-1) + { + ValueUnit=dataRes[i][idx]; + }else + { + QStringList temp; + temp.append("标准值"); + temp.append("标称值"); + int idx= getIndexByHeader(constsLable,temp); + if(idx!=-1) + ItemUnitSplit(dataRes[i][idx],ValueUnit,ValueUnit); - sRet = deviceEngine.queryData(newCmd); - idx= getIndexByHeader(sLabel,QStrTranQStrList("单位")); - //ValueUnit - if(idx!=-1) - { - ValueUnit=dataRes[i][idx]; - }else - { - QStringList temp; - temp.append("标准值"); - temp.append("标称值"); - int idx= getIndexByHeader(sLabel,temp); - if(idx!=-1) - ItemUnitSplit(dataRes[i][idx],ValueUnit,ValueUnit); - - } - dStdValue = transUnit(sRet,ValueUnit); - - } - } - + } + dStdValue = transUnit(sRet,ValueUnit); } - - autoAdujstData(sLabel,i,dStdValue,dataRes); + autoAdujstData(constsLable,i,dStdValue,dataRes); CheckBackColorUpdate(false,i); + closeCmd(); Delay_MSec(2000); + } //CLOSE 被检设备 - 标准设备 - BaseCommonApi::SaveLogInfo(1,QString("CLOSE")); - InstructionLib *Closebiz; - InstructionLib *Closestan; - Closebiz= getCmdByCheckName(0,"CLOSE"); - Closestan= getCmdByCheckName(1,"CLOSE"); - if(Closestan!=nullptr && instrcutLibstan!=nullptr) - { - if(standardEngine.getState()) - { - //读取配置指令 - QStringList sList = Closestan->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - } - } - // - if(Closebiz!=nullptr && instrcutLibbiz!=nullptr) - { - if(deviceEngine.getState()) - { - //读取配置指令 - QStringList sList = Closebiz->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - }; - - } } - caliDataList->insert(sLabel,dataRes); + caliDataList->insert(constsLable,dataRes); } + closeDevice(); } } void CheckWindow::Delay_MSec(unsigned int msec) @@ -2065,10 +2176,13 @@ void CheckWindow::on_pushButton_stop_clicked() { + Teststate=SyncRunStatus::Stopped; + if(iEquipType==5){ if(timerChart->isActive()) timerChart->stop(); } + } void CheckWindow::on_pushButton_clicked() @@ -2307,6 +2421,42 @@ } //QWidget::keyPressEvent(ev); } +void CheckWindow::SendDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran){ + //发送仪器 进一步封装 + QString newCmd=""; + if(Visa->getState()){ + if(Inst!=nullptr){ + QStringList sList = Inst->instruct_config.split(";"); + if(sList.length()>0){ + for (QString& sCmd : sList){ + newCmd = transCmd(sCmd,constsLable,constDataRes,IsUnitTran); + if(newCmd!=""){ + QString str=Visa->commType; + Visa->sendData(newCmd); + qDebug() << "config cmds:" << newCmd; + } + } + } + } +} +} +QString CheckWindow::ReadDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran){ + //读取仪器 进一步封装 + QString newCmd=""; + QString result=""; + if(Visa->getState()){ + if(Inst!=nullptr){ + newCmd = transCmd(Inst->instruct_read,constsLable,constDataRes,IsUnitTran); + if(newCmd!=""){ + qDebug() << "query cmds:" << newCmd; + result = Visa->queryData(newCmd); + } + } + } + return result; +} + + void CheckWindow::CreateCharts(){ deleteItem(ui->horizontalLayoutChart); @@ -2545,3 +2695,4 @@ caliDataList->insert(sLabel,dataRes); } } + diff --git a/softwareDirectory/AutoVerScheme/checkwindow.h b/softwareDirectory/AutoVerScheme/checkwindow.h index d559ac9..04f5425 100644 --- a/softwareDirectory/AutoVerScheme/checkwindow.h +++ b/softwareDirectory/AutoVerScheme/checkwindow.h @@ -24,6 +24,7 @@ int type; QString deviceName; QString state; + QString rolenName; VerificationProgramConfigInterface programInterface; QList cmdList; }; @@ -81,6 +82,7 @@ void addGageData(bool bAdd=true); void on_pushButton_next_clicked(); + void onComboBoxCurrTextChanged(QString value,QString device_id,int row); QMap readDataFromFile(QString filePath); void RefreshTime_Slot(); void on_pushButtonGetTemp_clicked(); @@ -88,7 +90,7 @@ private: void getCheckDevice(bool bInit=true); void getCheckMethod(); - void initDeviceInfo(QString sId); + void initDeviceInfo(QList sId); void deleteItem(QLayout *layout); void initCheckTable(int idx); InstructionLib* getCmdByCheckName(int idx,QString name); @@ -119,6 +121,13 @@ QStringList QStrTranQStrList(QString value); void changeDevice(int idx); void keyPressEvent(QKeyEvent *ev); + QString GetdeviceidByRole(QString device_id); + InstructionLib* getCmdByRoleName(QString RoleName,QString name); + VisaCommonEngine getVisaCommbyRoleName(QString RoleName); + QString ReadDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran=false); + void SendDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran=false); + void InItcmd(); + void closeCmd(); void CreateCharts(); private: Ui::CheckWindow *ui; @@ -132,6 +141,8 @@ VisaCommonEngine deviceEngine; VisaCommonEngine standardEngine; VisaCommonEngine engine;; + QMap VisaStanEngineList; + QList measureCa3lList; QList measureCalList; SaveDeviceMeasureInfo measureInfo; QMap> *caliDataList; @@ -146,6 +157,7 @@ QMap unitTypeTransList; QMap cmdPlaceHolderList; + QList StandarIdList; QString standardId; int currConnectIdx; QList pageButtons; @@ -159,8 +171,16 @@ QString curDeviceId=""; int curDevciceIdx=-1; int nextGageIndex=-1; + + QList DeviceMeasureEquipmentCatorycatory; + QList RoleList; + + QString constsLable; + QStringList constDataRes; + QChartView *chartView; QTimer* timerChart; + SyncRunStatus Teststate; }; #endif // CHECKWINDOW_H diff --git a/softwareDirectory/AutoVerScheme/checkwindow.cpp b/softwareDirectory/AutoVerScheme/checkwindow.cpp index dcaa48a..99738d8 100644 --- a/softwareDirectory/AutoVerScheme/checkwindow.cpp +++ b/softwareDirectory/AutoVerScheme/checkwindow.cpp @@ -36,9 +36,10 @@ for(int i=0;i<2;i++) ui->tableWidget_Standard->horizontalHeader()->setSectionResizeMode(i,QHeaderView::Stretch); ui->tableWidgetStd->verticalHeader()->setParent(nullptr); //隐藏行头 - for(int i=1;i<7;i++) + for(int i=1;i<6;i++) ui->tableWidgetStd->horizontalHeader()->setSectionResizeMode(i,QHeaderView::Stretch); ui->tableWidgetStd->setColumnWidth(0, 60); + ui->tableWidgetStd->setColumnWidth(7, 120); ui->tableWidgetCheck->verticalHeader()->setParent(nullptr); ui->comboBoxName->addItem("ALL"); ui->comboBoxModal->addItem("ALL"); @@ -74,6 +75,7 @@ measureCalList.clear(); caliDataListAll.clear(); headTableListAll.clear(); + VisaStanEngineList.clear(); delete ui; } @@ -104,21 +106,30 @@ void CheckWindow::updateStandardTable() { + + + QStringList ValueList; + ValueList.append("请选择角色"); + for (int i=0;itableWidgetStd->clearContents(); ui->tableWidgetStd->setRowCount(0); QString sFilterName = ui->comboBoxName_2->currentText(); QString sFilterModal = ui->comboBoxModal_2->currentText(); QString sFilterDepart = ui->lineEdit_4->text(); QString sFilterNo = ui->lineEditNo_2->text(); - int rowCount=0; - int row=0; + //catDeviceList.clear(); catIdList.clear(); if(programInfo.standard_device_id!=""){ catIdList = programInfo.standard_device_id.split(","); + int row=0; for(int i=catIdList.length()-1;i>=0; i--) { QString id = catIdList[i]; + + QString readraleName; QList result = BaseCommonApi::getCatDeviceInfor(id); if(result.length()>0){ CatDeviceInfor item = result[0]; @@ -148,17 +159,82 @@ ui->tableWidgetStd->setItem(0, 4, new QTableWidgetItem(item.dept_name)); ui->tableWidgetStd->setItem(0, 5, new QTableWidgetItem(item.director_name)); ui->tableWidgetStd->setItem(0, 6, new QTableWidgetItem(item.measure_valid_date)); - row++; + if(RoleList.count()!=0){ + + QComboBox *comboBox=new QComboBox(); + comboBox->addItems(ValueList); + ui->tableWidgetStd->setCellWidget(0, 7,comboBox); + + readraleName=GetdeviceidByRole(id); + if(readraleName!=""){ + comboBox->setCurrentText(readraleName); + } + // 连接下拉框的currentIndexChanged信号到槽函数 + connect(comboBox, &QComboBox::currentTextChanged, this, [this, id,comboBox,i]() { + onComboBoxCurrTextChanged(comboBox->currentText(),id,i); + + }); + }else{ui->tableWidgetStd->setItem(0, 7,new QTableWidgetItem("标准设备"));} + + + //catDeviceList.append(item); }else{ catIdList.removeAt(i); } } result.clear(); + row++; } + } } +void CheckWindow::onComboBoxCurrTextChanged(QString Value,QString device_id,int row) +{ + if(RoleList.count()!=0){ + QString cateory_id=DeviceMeasureEquipmentCatorycatory[0].item_category_id; + for (int i=0;itableWidgetStd->rowCount();i++){ + QComboBox *comboBox = qobject_cast(ui->tableWidgetStd->cellWidget(i, 7)); + if (comboBox) { + QString str=comboBox->currentText(); + if(comboBox->currentText()==Value && i!=row){ + comboBox->setCurrentIndex(0); + } + } + } + + + } + +} +QString CheckWindow::GetdeviceidByRole(QString device_id) +{ + QString cateory_id=DeviceMeasureEquipmentCatorycatory[0].item_category_id; + QString temprole=""; + for(int i=0;itableWidgetMethod->rowCount();i++){ @@ -196,8 +272,13 @@ ui->comboBoxModal_2->setCurrentIndex(0); ui->lineEditNo_2->setText(""); ui->lineEdit_4->setText(""); + //获取检定项分类 及 检定项分类包含的角色 + DeviceMeasureEquipmentCatorycatory = BaseCommonApi::getDeviceMeasureEquipmentCatory(selectTaskList[0].sample_id); + RoleList=BaseCommonApi::getDeviceRoleBydeviceId(DeviceMeasureEquipmentCatorycatory[0].item_category_id); updateStandardTable(); } + //查询角色表信息 getDeviceRoleBydeviceId + //catory[0].item_category_id 检定项目ID ui->stackedWidget->setCurrentIndex(2); } } @@ -206,31 +287,39 @@ { //QStringList idList = programInfo.standard_device_id.split(","); QString sId=""; - for(int i=0;itableWidgetStd->rowCount();i++){ + StandarIdList.clear(); + /*for(int i=0;itableWidgetStd->rowCount();i++){ Qt::CheckState state = ui->tableWidgetStd->item(i,0)->checkState(); if(state == Qt::Checked){ sId = catIdList[i]; break; } - } + }*/ + for(int i=0;itableWidgetStd->rowCount();i++){ + Qt::CheckState state = ui->tableWidgetStd->item(i,0)->checkState(); + if(state == Qt::Checked){ + StandarIdList.append(catIdList[i]); + break; + } + } if(catIdList.count()==1) { - sId = catIdList[0]; + StandarIdList.append(catIdList[0]); } - if(sId==""){ + if(StandarIdList.count()==0){ QMessageBox::warning(this, "提示", "请选择标准设备!"); }else{ //programInfo = BaseCommonApi::getVerificationProgramInfo(sId); - initDeviceInfo(sId); + initDeviceInfo(StandarIdList); ui->stackedWidget->setCurrentIndex(3); } } -void CheckWindow::initDeviceInfo(QString sId) +void CheckWindow::initDeviceInfo(QList sId) { - standardId = sId; + StandarIdList = sId; QString strStyle = QString("QLabel{image:url(%1);}").arg(programInfo.img_path); qDebug() << "strStyle:" << strStyle; ui->label_8->setStyleSheet(strStyle); @@ -246,8 +335,9 @@ connectList.clear(); if(selectTaskList.length()>0) { - QList catory = BaseCommonApi::getDeviceMeasureEquipmentCatory(selectTaskList[0].sample_id); + QList catory = DeviceMeasureEquipmentCatorycatory; if(catory.length() > 0 ){ + ui->lineEdit_category->setText(catory[0].item_category_name); } //idList = programInfo.tested_device_id.split(","); @@ -263,6 +353,7 @@ info.programInterface = addrList[0]; } info.cmdList = BaseCommonApi::getInstructionLib(programInfo.id); + info.rolenName="被检设备"; connectList.append(info); addrList.clear(); } @@ -271,14 +362,19 @@ if(programInfo.standard_device_id!=""){ idList = programInfo.standard_device_id.split(","); + for(const QString& id : idList) { - if(id!=sId) - continue; + //if(id!=CheckId) + // continue; ConnectInfo info; info.id = id; info.type = 1; info.state="未连接"; + if(idList.count()==1) + info.rolenName="标准设备"; + else + info.rolenName=GetdeviceidByRole(id); QList result = BaseCommonApi::getCatDeviceInfor(id); if(result.length()>0){ info.deviceName = result[0].equipment_name; @@ -286,8 +382,9 @@ //更新标准设备表格 rowCount = ui->tableWidget_Standard->rowCount(); ui->tableWidget_Standard->insertRow(rowCount); - ui->tableWidget_Standard->setItem(row, 0, new QTableWidgetItem(info.deviceName)); - ui->tableWidget_Standard->setItem(row, 1, new QTableWidgetItem("OFF")); //设置数据 + ui->tableWidget_Standard->setItem(row, 0, new QTableWidgetItem(info.rolenName)); + ui->tableWidget_Standard->setItem(row, 1, new QTableWidgetItem(info.deviceName)); + ui->tableWidget_Standard->setItem(row, 2, new QTableWidgetItem("OFF")); //设置数据 row++; } result.clear(); @@ -299,6 +396,7 @@ connectList.append(info); addrList.clear(); } + idList.clear(); } rowCount=0; @@ -306,8 +404,9 @@ for(const ConnectInfo& info : connectList){ rowCount = ui->tableWidget_3->rowCount(); ui->tableWidget_3->insertRow(rowCount); - ui->tableWidget_3->setItem(row, 0, new QTableWidgetItem(info.deviceName)); - ui->tableWidget_3->setItem(row, 1, new QTableWidgetItem(info.state)); //设置数据 + ui->tableWidget_3->setItem(row, 0, new QTableWidgetItem(info.rolenName)); + ui->tableWidget_3->setItem(row, 1, new QTableWidgetItem(info.deviceName)); + ui->tableWidget_3->setItem(row, 2, new QTableWidgetItem(info.state)); //设置数据 row++; } //搜索仪器地址放入下拉框 @@ -836,8 +935,8 @@ //修改连接状态 if(getJoinState(addr.visa)) { - ui->tableWidget_3->setItem(currentRow,1,new QTableWidgetItem("ON")); - }else{ ui->tableWidget_3->setItem(currentRow,1,new QTableWidgetItem("OFF"));} + ui->tableWidget_3->setItem(currentRow,2,new QTableWidgetItem("已连接")); + }else{ ui->tableWidget_3->setItem(currentRow,2,new QTableWidgetItem("未连接"));} } } @@ -1087,20 +1186,23 @@ BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam,newCmd; - QString sLabel = headTableList->keys()[curHeadIdx]; - QList dataRes = caliDataList->value(sLabel); - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + constsLable = headTableList->keys()[curHeadIdx]; + QList dataRes = caliDataList->value(constsLable); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); if(idx!=-1) sParam = dataRes[nextGageIndex][idx]; else - sParam = sLabel; //示值误差/回程误差/轻敲位移 - if(standardEngine.getState()){ + sParam = constsLable; //示值误差/回程误差/轻敲位移 + InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); + constDataRes= dataRes[nextGageIndex]; + SendDevice(instrcutLib,&standardEngine); + /*if(standardEngine.getState()){ InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); if(instrcutLib!=nullptr){ QStringList sList = instrcutLib->instruct_config.split(";"); if(sList.length()>0){ for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[nextGageIndex],true); + newCmd = transCmd(sCmd,constsLable,dataRes[nextGageIndex],true); if(newCmd!=""){ standardEngine.sendData(newCmd); qDebug() << "standard cmds:" << newCmd; @@ -1108,7 +1210,7 @@ } } } - } + }*/ currentItem = ui->tableWidgetCheck->item(nextGageIndex, 0); currentItem->setSelected(true); @@ -1145,14 +1247,18 @@ BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam,newCmd; - QString sLabel = headTableList->keys()[curHeadIdx]; - QList dataRes = caliDataList->value(sLabel); - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + constsLable = headTableList->keys()[curHeadIdx]; + QList dataRes = caliDataList->value(constsLable); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); if(idx!=-1) sParam = dataRes[nextGageIndex][idx]; else - sParam = sLabel; //示值误差/回程误差/轻敲位移 - if(standardEngine.getState()){ + sParam = constsLable; //示值误差/回程误差/轻敲位移 + + InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); + constDataRes= dataRes[nextGageIndex]; + SendDevice(instrcutLib,&standardEngine); + /*if(standardEngine.getState()){ InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); if(instrcutLib!=nullptr){ QStringList sList = instrcutLib->instruct_config.split(";"); @@ -1166,7 +1272,7 @@ } } } - } + }*/ currentItem = ui->tableWidgetCheck->item(nextGageIndex, 0); currentItem->setSelected(true); @@ -1241,71 +1347,146 @@ } } } +void CheckWindow::InItcmd(){ + //发送INIt相关指令 + int count=0; + for(const ConnectInfo &visa:connectList) + { + VisaCommonEngine *Engine; + InstructionLib *instrcutLib; + if(connectList.length()>0&&visa.type==0) + { + instrcutLib = getCmdByCheckName(count,"INIT"); + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + instrcutLib = getCmdByCheckName(count,"INIT"); + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } + } + } + } + SendDevice(instrcutLib,Engine); + } +} void CheckWindow::connectDevice(){ - if(connectList.length()>0&&connectList[0].type==0){ - if(deviceEngine.openDevice(connectList[0].programInterface.visa,"Visa")){ - InstructionLib *instrcutLib = getCmdByCheckName(0,"INIT"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - deviceEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } - } - } - } - } - if(connectList.length()>1&&connectList[1].type==1) + int count=0; + QString rolename; + for(const ConnectInfo &visa:connectList) { - if(standardEngine.openDevice(connectList[1].programInterface.visa,"Visa")){ - ui->tableWidget_Standard->setItem(0,1,new QTableWidgetItem("ON")); - InstructionLib *instrcutLib = getCmdByCheckName(1,"INIT"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - standardEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } + VisaCommonEngine Engine; + if(Engine.openDevice(visa.programInterface.visa,"Visa")){ + if(connectList.length()>0&&visa.type==0) + { + deviceEngine=Engine; + } + if(connectList.length()>1&&visa.type==1) + { + if(connectList.count()==2){ + standardEngine=Engine; + }else{ + rolename=this->GetdeviceidByRole(visa.programInterface.device_id); + VisaStanEngineList.insert(rolename,Engine); } + } } + count++; + } - } +void CheckWindow::closeCmd(){ + //发送Close相关指令 + int count=0; + for(const ConnectInfo &visa:connectList) + { + VisaCommonEngine *Engine; + InstructionLib *instrcutLib; + if(connectList.length()>0&&visa.type==0) + { + instrcutLib = getCmdByCheckName(count,"CLOSE"); + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + instrcutLib = getCmdByCheckName(count,"CLOSE"); + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } + } + } + } + SendDevice(instrcutLib,Engine); + } +} void CheckWindow::closeDevice(){ - if(connectList.length()>0&&connectList[0].type==0){ - InstructionLib *instrcutLib = getCmdByCheckName(0,"CLOSE"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - deviceEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } - } - } - deviceEngine.closeDevice(); - } - if(connectList.length()>1&&connectList[1].type==1) + //关闭设备连接 + int count=0; + for(const ConnectInfo &visa:connectList) { - InstructionLib *instrcutLib = getCmdByCheckName(1,"CLOSE"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - standardEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; + VisaCommonEngine *Engine; + if(connectList.length()>0&&visa.type==0) + { + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } } } + } - standardEngine.closeDevice(); + Engine->closeDevice(); + count++; + } } +InstructionLib* CheckWindow::getCmdByRoleName(QString RoleName,QString name){ + for (ConnectInfo& info : connectList) { + if(info.rolenName==RoleName){ + for (InstructionLib& item : info.cmdList) { + if(item.belong_vername==name) + return &item; + } + } + + } + return nullptr; +} +VisaCommonEngine CheckWindow::getVisaCommbyRoleName(QString RoleName){ + VisaCommonEngine visa; + for(VisaCommonEngine &item : VisaStanEngineList){ + if(item.role==RoleName){ + return item; + } + } + return visa; +} InstructionLib* CheckWindow::getCmdByCheckName(int idx,QString name) { if(idx>=0&&idxkeys().count()==0) return; BaseCommonApi::SaveLogInfo(1,QString("-----------------------------------")); if(iEquipType==13) { + connectDevice(); this->Oscilloscopetextflow(); + return; } else if(iEquipType==4){ @@ -1508,70 +1692,69 @@ connectDevice(); for(int i=0;ikeys().length();i++) { + if(Teststate==SyncRunStatus::Stopped){break;}; //每次循环按钮变化 initCheckTable(i); - QString sLabel = headTableList->keys()[i]; - QList dataRes = caliDataList->value(sLabel); - BaseCommonApi::SaveLogInfo(1,QString("开始 %1 测试").arg(sLabel)); + constsLable= headTableList->keys()[i]; + QList dataRes = caliDataList->value(constsLable); + BaseCommonApi::SaveLogInfo(1,QString("开始 %1 测试").arg(constsLable)); for (int i = 0; i < dataRes.count(); ++i) { + if(Teststate==SyncRunStatus::Stopped){break;}; + constDataRes=dataRes[i]; + InItcmd(); QString sRet=""; QString newCmd; double dStdValue=FP_INFINITE,dError=0; QString newdStdValue,newdError; + CheckBackColorUpdate(true,i); //标准器输出 BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam; QStringList TempValue; TempValue.append("检定项目"); - int idx= getIndexByHeader(sLabel,TempValue); + int idx= getIndexByHeader(constsLable,TempValue); if(idx!=-1) sParam = dataRes[i][idx]; - if(standardEngine.getState()){ - InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i],true); - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } + //暂时加到这个地方 后面统一编写 + if(sParam=="DCI"||sParam=="ACI") + { + int idx2= getIndexByHeader(constsLable,QStrTranQStrList("单位")); + if(idx2!=-1) + { + QString ConstUnit=""; + QString v=dataRes[i][idx2].toUpper(); + if(i!=0) + ConstUnit=dataRes[i-1][idx2].toUpper(); + + BaseCommonApi::SaveLogInfo(1,ConstUnit+"-"+v); + if((ConstUnit=="MA" && v=="A") || (ConstUnit=="A" && v=="MA")) + { + if(!this->showDialog("电流换线提醒",QString("换线提醒\n %1 -> %2").arg(ConstUnit).arg(v))) + { + continue; + } } } } + InstructionLib *instrcutLibstan = getCmdByCheckName(1,sParam); + SendDevice(instrcutLibstan,&standardEngine,true); //被检设备读数 BaseCommonApi::SaveLogInfo(1,QString("被检设备输出")); - if(deviceEngine.getState()){ - InstructionLib *instrcutLib = getCmdByCheckName(0,sParam); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "config cmds:" << newCmd; - } - } - } - - newCmd = transCmd(instrcutLib->instruct_read,sLabel,dataRes[i]); - if(newCmd!=""){ - qDebug() << "query cmds:" << newCmd; - sRet = deviceEngine.queryData(newCmd); - TempValue.clear(); - TempValue.append("单位"); - idx= getIndexByHeader(sLabel,TempValue); - dStdValue = transUnit(sRet,dataRes[i][idx]); - } - } + InstructionLib *instrcutLib = getCmdByCheckName(0,sParam); + SendDevice(instrcutLib,&deviceEngine); + sRet=ReadDevice(instrcutLib,&deviceEngine); + if(sRet!=""){ + TempValue.clear(); + TempValue.append("单位"); + idx= getIndexByHeader(constsLable,TempValue); + dStdValue = transUnit(sRet,dataRes[i][idx]); } - autoAdujstData(sLabel,i,dStdValue,dataRes); + autoAdujstData(constsLable,i,dStdValue,dataRes); + CheckBackColorUpdate(false,i); + closeCmd(); Delay_MSec(2000); } - caliDataList->insert(sLabel,dataRes); + caliDataList->insert(constsLable,dataRes); } closeDevice(); } @@ -1842,15 +2025,17 @@ BaseCommonApi::SaveLogInfo(1,QString("---------------------------------------------------")); //首先检索当前检定项目的通道 initCheckTable(i); - QString sLabel = headTableList->keys()[i]; - QList dataRes = caliDataList->value(sLabel); - BaseCommonApi::SaveLogInfo(1,QString("开始 %1 %2 测试").arg(chList[_ch]).arg(sLabel)); + constsLable = headTableList->keys()[i]; + QList dataRes = caliDataList->value(constsLable); + BaseCommonApi::SaveLogInfo(1,QString("开始 %1 %2 测试").arg(chList[_ch]).arg(constsLable)); QString sParam; QString ValueUnit; InstructionLib *instrcutLibOhm; for (int i = 0; i < dataRes.count(); ++i) { TextCount=1; - int _dex= getIndexByHeader(sLabel,QStrTranQStrList("通道")); + constDataRes=dataRes[i]; + InItcmd(); + int _dex= getIndexByHeader(constsLable,QStrTranQStrList("通道")); if(_dex==-1){sParam=chList[_ch];}else{sParam=dataRes[i][_dex];} if(sParam!=chList[_ch]){continue;}; CheckBackColorUpdate(true,i); @@ -1858,80 +2043,46 @@ QString newCmd; double dStdValue=FP_INFINITE; QString newdStdValue; - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); QString sParam; if(idx!=-1) sParam = dataRes[i][idx]; InstructionLib *instrcutLibbiz=getCmdByCheckName(0,sParam); InstructionLib *instrcutLibstan=getCmdByCheckName(1,sParam); //INIT 被检设备 - 标准设备 - BaseCommonApi::SaveLogInfo(1,QString("INIT")); - InstructionLib *InItbiz; - InstructionLib *InItstan; - InItbiz= getCmdByCheckName(0,"INIT"); - InItstan= getCmdByCheckName(1,"INIT"); - if(InItbiz!=nullptr && instrcutLibbiz!=nullptr) - { - if(deviceEngine.getState() ) + instrcutLibOhm= getCmdByCheckName(0,"电阻"); + if(deviceEngine.getState()) { //设置电阻值+ instrcutLibOhm= getCmdByCheckName(0,"电阻"); if(instrcutLibOhm!=nullptr){ QStringList ohmList = instrcutLibOhm->instruct_config.split(";"); - int idxohm= getIndexByHeader(sLabel,QStrTranQStrList("阻抗")); + int idxohm= getIndexByHeader(constsLable,QStrTranQStrList("阻抗")); + if(sParam=="输入电阻"){ + if(!this->showDialog("输入电阻","请接入电阻测试线")){continue;} + idxohm= getIndexByHeader(constsLable,QStrTranQStrList("标称值")); + } + if(idxohm!=-1) { QString onmname="50Ω"; QString CmdOhm; onmname=dataRes[i][idxohm]; - if(onmname=="50Ω"){CmdOhm=ohmList[0];}else{CmdOhm=ohmList[1];}; - newCmd = transCmd(CmdOhm,sLabel,dataRes[i],true); + if(onmname=="50Ω"){CmdOhm=ohmList[0];} + else if(onmname=="75Ω"){CmdOhm=ohmList[1];} + else{ + if(ohmList.count()>2){CmdOhm=ohmList[2];}else{CmdOhm=ohmList[1];}; + } + newCmd = transCmd(CmdOhm,constsLable,constDataRes,true); deviceEngine.sendData(newCmd); } } - //读取配置指令 - - QStringList sList = InItbiz->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - }; - - } - - if(InItstan!=nullptr && instrcutLibstan!=nullptr) - { - if(standardEngine.getState()) - { - //读取配置指令 - QStringList sList = InItstan->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - } - - } + } if(sParam=="频带宽度"){TextCount=2;}; for (int d=0;dinstruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "config cmds:" << newCmd; - } - } - } - newCmd = transCmd(instrcutLibbiz->instruct_read,sLabel,dataRes[i]); - if(newCmd!=""){ - qDebug() << "query cmds:" << newCmd; + SendDevice(instrcutLibbiz,&deviceEngine); + sRet=ReadDevice(instrcutLibbiz,&deviceEngine); + if(sParam=="输入电阻"){ + BaseCommonApi::SaveLogInfo(1,QString("数字万用表控制")); + VisaCommonEngine tempEngine=getVisaCommbyRoleName("数字多用表"); //角色 + InstructionLib *instrcutLibNum=getCmdByRoleName("数字多用表",sParam); + sRet=ReadDevice(instrcutLibNum,&tempEngine); + } + if(sParam=="校准信号"){ + idx= getIndexByHeader(constsLable,QStrTranQStrList("项目")); + if(dataRes[i][idx]=="频率"){ + if(!this->showDialog("输入电阻","请接入频率测试线")){continue;} + BaseCommonApi::SaveLogInfo(1,QString("通用计数器控制")); + VisaCommonEngine tempEngine=getVisaCommbyRoleName("通用计数器"); //角色 + InstructionLib *instrcutLibNum=getCmdByRoleName("通用计数器",sParam); + SendDevice(instrcutLibbiz,&deviceEngine); + sRet=ReadDevice(instrcutLibNum,&tempEngine); + } + } + //测试结果单位转换 + if(sRet!=""){ + idx= getIndexByHeader(constsLable,QStrTranQStrList("单位")); + //ValueUnit + if(idx!=-1) + { + ValueUnit=dataRes[i][idx]; + }else + { + QStringList temp; + temp.append("标准值"); + temp.append("标称值"); + int idx= getIndexByHeader(constsLable,temp); + if(idx!=-1) + ItemUnitSplit(dataRes[i][idx],ValueUnit,ValueUnit); - sRet = deviceEngine.queryData(newCmd); - idx= getIndexByHeader(sLabel,QStrTranQStrList("单位")); - //ValueUnit - if(idx!=-1) - { - ValueUnit=dataRes[i][idx]; - }else - { - QStringList temp; - temp.append("标准值"); - temp.append("标称值"); - int idx= getIndexByHeader(sLabel,temp); - if(idx!=-1) - ItemUnitSplit(dataRes[i][idx],ValueUnit,ValueUnit); - - } - dStdValue = transUnit(sRet,ValueUnit); - - } - } - + } + dStdValue = transUnit(sRet,ValueUnit); } - - autoAdujstData(sLabel,i,dStdValue,dataRes); + autoAdujstData(constsLable,i,dStdValue,dataRes); CheckBackColorUpdate(false,i); + closeCmd(); Delay_MSec(2000); + } //CLOSE 被检设备 - 标准设备 - BaseCommonApi::SaveLogInfo(1,QString("CLOSE")); - InstructionLib *Closebiz; - InstructionLib *Closestan; - Closebiz= getCmdByCheckName(0,"CLOSE"); - Closestan= getCmdByCheckName(1,"CLOSE"); - if(Closestan!=nullptr && instrcutLibstan!=nullptr) - { - if(standardEngine.getState()) - { - //读取配置指令 - QStringList sList = Closestan->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - } - } - // - if(Closebiz!=nullptr && instrcutLibbiz!=nullptr) - { - if(deviceEngine.getState()) - { - //读取配置指令 - QStringList sList = Closebiz->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - }; - - } } - caliDataList->insert(sLabel,dataRes); + caliDataList->insert(constsLable,dataRes); } + closeDevice(); } } void CheckWindow::Delay_MSec(unsigned int msec) @@ -2065,10 +2176,13 @@ void CheckWindow::on_pushButton_stop_clicked() { + Teststate=SyncRunStatus::Stopped; + if(iEquipType==5){ if(timerChart->isActive()) timerChart->stop(); } + } void CheckWindow::on_pushButton_clicked() @@ -2307,6 +2421,42 @@ } //QWidget::keyPressEvent(ev); } +void CheckWindow::SendDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran){ + //发送仪器 进一步封装 + QString newCmd=""; + if(Visa->getState()){ + if(Inst!=nullptr){ + QStringList sList = Inst->instruct_config.split(";"); + if(sList.length()>0){ + for (QString& sCmd : sList){ + newCmd = transCmd(sCmd,constsLable,constDataRes,IsUnitTran); + if(newCmd!=""){ + QString str=Visa->commType; + Visa->sendData(newCmd); + qDebug() << "config cmds:" << newCmd; + } + } + } + } +} +} +QString CheckWindow::ReadDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran){ + //读取仪器 进一步封装 + QString newCmd=""; + QString result=""; + if(Visa->getState()){ + if(Inst!=nullptr){ + newCmd = transCmd(Inst->instruct_read,constsLable,constDataRes,IsUnitTran); + if(newCmd!=""){ + qDebug() << "query cmds:" << newCmd; + result = Visa->queryData(newCmd); + } + } + } + return result; +} + + void CheckWindow::CreateCharts(){ deleteItem(ui->horizontalLayoutChart); @@ -2545,3 +2695,4 @@ caliDataList->insert(sLabel,dataRes); } } + diff --git a/softwareDirectory/AutoVerScheme/checkwindow.h b/softwareDirectory/AutoVerScheme/checkwindow.h index d559ac9..04f5425 100644 --- a/softwareDirectory/AutoVerScheme/checkwindow.h +++ b/softwareDirectory/AutoVerScheme/checkwindow.h @@ -24,6 +24,7 @@ int type; QString deviceName; QString state; + QString rolenName; VerificationProgramConfigInterface programInterface; QList cmdList; }; @@ -81,6 +82,7 @@ void addGageData(bool bAdd=true); void on_pushButton_next_clicked(); + void onComboBoxCurrTextChanged(QString value,QString device_id,int row); QMap readDataFromFile(QString filePath); void RefreshTime_Slot(); void on_pushButtonGetTemp_clicked(); @@ -88,7 +90,7 @@ private: void getCheckDevice(bool bInit=true); void getCheckMethod(); - void initDeviceInfo(QString sId); + void initDeviceInfo(QList sId); void deleteItem(QLayout *layout); void initCheckTable(int idx); InstructionLib* getCmdByCheckName(int idx,QString name); @@ -119,6 +121,13 @@ QStringList QStrTranQStrList(QString value); void changeDevice(int idx); void keyPressEvent(QKeyEvent *ev); + QString GetdeviceidByRole(QString device_id); + InstructionLib* getCmdByRoleName(QString RoleName,QString name); + VisaCommonEngine getVisaCommbyRoleName(QString RoleName); + QString ReadDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran=false); + void SendDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran=false); + void InItcmd(); + void closeCmd(); void CreateCharts(); private: Ui::CheckWindow *ui; @@ -132,6 +141,8 @@ VisaCommonEngine deviceEngine; VisaCommonEngine standardEngine; VisaCommonEngine engine;; + QMap VisaStanEngineList; + QList measureCa3lList; QList measureCalList; SaveDeviceMeasureInfo measureInfo; QMap> *caliDataList; @@ -146,6 +157,7 @@ QMap unitTypeTransList; QMap cmdPlaceHolderList; + QList StandarIdList; QString standardId; int currConnectIdx; QList pageButtons; @@ -159,8 +171,16 @@ QString curDeviceId=""; int curDevciceIdx=-1; int nextGageIndex=-1; + + QList DeviceMeasureEquipmentCatorycatory; + QList RoleList; + + QString constsLable; + QStringList constDataRes; + QChartView *chartView; QTimer* timerChart; + SyncRunStatus Teststate; }; #endif // CHECKWINDOW_H diff --git a/softwareDirectory/AutoVerScheme/checkwindow.ui b/softwareDirectory/AutoVerScheme/checkwindow.ui index d2bfbac..a753c93 100644 --- a/softwareDirectory/AutoVerScheme/checkwindow.ui +++ b/softwareDirectory/AutoVerScheme/checkwindow.ui @@ -939,6 +939,11 @@ 检定有效期 + + + 角色信息 + + @@ -1142,6 +1147,11 @@ + 角色 + + + + 设备名称 @@ -1795,13 +1805,25 @@ + 角色 + + + + Arial + 10 + + + + + 设备名称 - 12 - 75 - true + Arial + 10 + 50 + false @@ -1811,9 +1833,10 @@ - 12 - 75 - true + Arial + 10 + 50 + false @@ -1941,6 +1964,9 @@ true + + color:orange + 出厂编号: @@ -2221,8 +2247,8 @@ showMethod() - 153 - 234 + 726 + 760 884 @@ -2237,8 +2263,8 @@ showCheck() - 1095 - 571 + 1187 + 581 1328 @@ -2253,8 +2279,8 @@ showMethodWidget() - 61 - 91 + 713 + 121 3 @@ -2269,8 +2295,8 @@ showResult() - 55 - 91 + 580 + 121 -1 diff --git a/softwareDirectory/AutoVerScheme/checkwindow.cpp b/softwareDirectory/AutoVerScheme/checkwindow.cpp index dcaa48a..99738d8 100644 --- a/softwareDirectory/AutoVerScheme/checkwindow.cpp +++ b/softwareDirectory/AutoVerScheme/checkwindow.cpp @@ -36,9 +36,10 @@ for(int i=0;i<2;i++) ui->tableWidget_Standard->horizontalHeader()->setSectionResizeMode(i,QHeaderView::Stretch); ui->tableWidgetStd->verticalHeader()->setParent(nullptr); //隐藏行头 - for(int i=1;i<7;i++) + for(int i=1;i<6;i++) ui->tableWidgetStd->horizontalHeader()->setSectionResizeMode(i,QHeaderView::Stretch); ui->tableWidgetStd->setColumnWidth(0, 60); + ui->tableWidgetStd->setColumnWidth(7, 120); ui->tableWidgetCheck->verticalHeader()->setParent(nullptr); ui->comboBoxName->addItem("ALL"); ui->comboBoxModal->addItem("ALL"); @@ -74,6 +75,7 @@ measureCalList.clear(); caliDataListAll.clear(); headTableListAll.clear(); + VisaStanEngineList.clear(); delete ui; } @@ -104,21 +106,30 @@ void CheckWindow::updateStandardTable() { + + + QStringList ValueList; + ValueList.append("请选择角色"); + for (int i=0;itableWidgetStd->clearContents(); ui->tableWidgetStd->setRowCount(0); QString sFilterName = ui->comboBoxName_2->currentText(); QString sFilterModal = ui->comboBoxModal_2->currentText(); QString sFilterDepart = ui->lineEdit_4->text(); QString sFilterNo = ui->lineEditNo_2->text(); - int rowCount=0; - int row=0; + //catDeviceList.clear(); catIdList.clear(); if(programInfo.standard_device_id!=""){ catIdList = programInfo.standard_device_id.split(","); + int row=0; for(int i=catIdList.length()-1;i>=0; i--) { QString id = catIdList[i]; + + QString readraleName; QList result = BaseCommonApi::getCatDeviceInfor(id); if(result.length()>0){ CatDeviceInfor item = result[0]; @@ -148,17 +159,82 @@ ui->tableWidgetStd->setItem(0, 4, new QTableWidgetItem(item.dept_name)); ui->tableWidgetStd->setItem(0, 5, new QTableWidgetItem(item.director_name)); ui->tableWidgetStd->setItem(0, 6, new QTableWidgetItem(item.measure_valid_date)); - row++; + if(RoleList.count()!=0){ + + QComboBox *comboBox=new QComboBox(); + comboBox->addItems(ValueList); + ui->tableWidgetStd->setCellWidget(0, 7,comboBox); + + readraleName=GetdeviceidByRole(id); + if(readraleName!=""){ + comboBox->setCurrentText(readraleName); + } + // 连接下拉框的currentIndexChanged信号到槽函数 + connect(comboBox, &QComboBox::currentTextChanged, this, [this, id,comboBox,i]() { + onComboBoxCurrTextChanged(comboBox->currentText(),id,i); + + }); + }else{ui->tableWidgetStd->setItem(0, 7,new QTableWidgetItem("标准设备"));} + + + //catDeviceList.append(item); }else{ catIdList.removeAt(i); } } result.clear(); + row++; } + } } +void CheckWindow::onComboBoxCurrTextChanged(QString Value,QString device_id,int row) +{ + if(RoleList.count()!=0){ + QString cateory_id=DeviceMeasureEquipmentCatorycatory[0].item_category_id; + for (int i=0;itableWidgetStd->rowCount();i++){ + QComboBox *comboBox = qobject_cast(ui->tableWidgetStd->cellWidget(i, 7)); + if (comboBox) { + QString str=comboBox->currentText(); + if(comboBox->currentText()==Value && i!=row){ + comboBox->setCurrentIndex(0); + } + } + } + + + } + +} +QString CheckWindow::GetdeviceidByRole(QString device_id) +{ + QString cateory_id=DeviceMeasureEquipmentCatorycatory[0].item_category_id; + QString temprole=""; + for(int i=0;itableWidgetMethod->rowCount();i++){ @@ -196,8 +272,13 @@ ui->comboBoxModal_2->setCurrentIndex(0); ui->lineEditNo_2->setText(""); ui->lineEdit_4->setText(""); + //获取检定项分类 及 检定项分类包含的角色 + DeviceMeasureEquipmentCatorycatory = BaseCommonApi::getDeviceMeasureEquipmentCatory(selectTaskList[0].sample_id); + RoleList=BaseCommonApi::getDeviceRoleBydeviceId(DeviceMeasureEquipmentCatorycatory[0].item_category_id); updateStandardTable(); } + //查询角色表信息 getDeviceRoleBydeviceId + //catory[0].item_category_id 检定项目ID ui->stackedWidget->setCurrentIndex(2); } } @@ -206,31 +287,39 @@ { //QStringList idList = programInfo.standard_device_id.split(","); QString sId=""; - for(int i=0;itableWidgetStd->rowCount();i++){ + StandarIdList.clear(); + /*for(int i=0;itableWidgetStd->rowCount();i++){ Qt::CheckState state = ui->tableWidgetStd->item(i,0)->checkState(); if(state == Qt::Checked){ sId = catIdList[i]; break; } - } + }*/ + for(int i=0;itableWidgetStd->rowCount();i++){ + Qt::CheckState state = ui->tableWidgetStd->item(i,0)->checkState(); + if(state == Qt::Checked){ + StandarIdList.append(catIdList[i]); + break; + } + } if(catIdList.count()==1) { - sId = catIdList[0]; + StandarIdList.append(catIdList[0]); } - if(sId==""){ + if(StandarIdList.count()==0){ QMessageBox::warning(this, "提示", "请选择标准设备!"); }else{ //programInfo = BaseCommonApi::getVerificationProgramInfo(sId); - initDeviceInfo(sId); + initDeviceInfo(StandarIdList); ui->stackedWidget->setCurrentIndex(3); } } -void CheckWindow::initDeviceInfo(QString sId) +void CheckWindow::initDeviceInfo(QList sId) { - standardId = sId; + StandarIdList = sId; QString strStyle = QString("QLabel{image:url(%1);}").arg(programInfo.img_path); qDebug() << "strStyle:" << strStyle; ui->label_8->setStyleSheet(strStyle); @@ -246,8 +335,9 @@ connectList.clear(); if(selectTaskList.length()>0) { - QList catory = BaseCommonApi::getDeviceMeasureEquipmentCatory(selectTaskList[0].sample_id); + QList catory = DeviceMeasureEquipmentCatorycatory; if(catory.length() > 0 ){ + ui->lineEdit_category->setText(catory[0].item_category_name); } //idList = programInfo.tested_device_id.split(","); @@ -263,6 +353,7 @@ info.programInterface = addrList[0]; } info.cmdList = BaseCommonApi::getInstructionLib(programInfo.id); + info.rolenName="被检设备"; connectList.append(info); addrList.clear(); } @@ -271,14 +362,19 @@ if(programInfo.standard_device_id!=""){ idList = programInfo.standard_device_id.split(","); + for(const QString& id : idList) { - if(id!=sId) - continue; + //if(id!=CheckId) + // continue; ConnectInfo info; info.id = id; info.type = 1; info.state="未连接"; + if(idList.count()==1) + info.rolenName="标准设备"; + else + info.rolenName=GetdeviceidByRole(id); QList result = BaseCommonApi::getCatDeviceInfor(id); if(result.length()>0){ info.deviceName = result[0].equipment_name; @@ -286,8 +382,9 @@ //更新标准设备表格 rowCount = ui->tableWidget_Standard->rowCount(); ui->tableWidget_Standard->insertRow(rowCount); - ui->tableWidget_Standard->setItem(row, 0, new QTableWidgetItem(info.deviceName)); - ui->tableWidget_Standard->setItem(row, 1, new QTableWidgetItem("OFF")); //设置数据 + ui->tableWidget_Standard->setItem(row, 0, new QTableWidgetItem(info.rolenName)); + ui->tableWidget_Standard->setItem(row, 1, new QTableWidgetItem(info.deviceName)); + ui->tableWidget_Standard->setItem(row, 2, new QTableWidgetItem("OFF")); //设置数据 row++; } result.clear(); @@ -299,6 +396,7 @@ connectList.append(info); addrList.clear(); } + idList.clear(); } rowCount=0; @@ -306,8 +404,9 @@ for(const ConnectInfo& info : connectList){ rowCount = ui->tableWidget_3->rowCount(); ui->tableWidget_3->insertRow(rowCount); - ui->tableWidget_3->setItem(row, 0, new QTableWidgetItem(info.deviceName)); - ui->tableWidget_3->setItem(row, 1, new QTableWidgetItem(info.state)); //设置数据 + ui->tableWidget_3->setItem(row, 0, new QTableWidgetItem(info.rolenName)); + ui->tableWidget_3->setItem(row, 1, new QTableWidgetItem(info.deviceName)); + ui->tableWidget_3->setItem(row, 2, new QTableWidgetItem(info.state)); //设置数据 row++; } //搜索仪器地址放入下拉框 @@ -836,8 +935,8 @@ //修改连接状态 if(getJoinState(addr.visa)) { - ui->tableWidget_3->setItem(currentRow,1,new QTableWidgetItem("ON")); - }else{ ui->tableWidget_3->setItem(currentRow,1,new QTableWidgetItem("OFF"));} + ui->tableWidget_3->setItem(currentRow,2,new QTableWidgetItem("已连接")); + }else{ ui->tableWidget_3->setItem(currentRow,2,new QTableWidgetItem("未连接"));} } } @@ -1087,20 +1186,23 @@ BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam,newCmd; - QString sLabel = headTableList->keys()[curHeadIdx]; - QList dataRes = caliDataList->value(sLabel); - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + constsLable = headTableList->keys()[curHeadIdx]; + QList dataRes = caliDataList->value(constsLable); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); if(idx!=-1) sParam = dataRes[nextGageIndex][idx]; else - sParam = sLabel; //示值误差/回程误差/轻敲位移 - if(standardEngine.getState()){ + sParam = constsLable; //示值误差/回程误差/轻敲位移 + InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); + constDataRes= dataRes[nextGageIndex]; + SendDevice(instrcutLib,&standardEngine); + /*if(standardEngine.getState()){ InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); if(instrcutLib!=nullptr){ QStringList sList = instrcutLib->instruct_config.split(";"); if(sList.length()>0){ for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[nextGageIndex],true); + newCmd = transCmd(sCmd,constsLable,dataRes[nextGageIndex],true); if(newCmd!=""){ standardEngine.sendData(newCmd); qDebug() << "standard cmds:" << newCmd; @@ -1108,7 +1210,7 @@ } } } - } + }*/ currentItem = ui->tableWidgetCheck->item(nextGageIndex, 0); currentItem->setSelected(true); @@ -1145,14 +1247,18 @@ BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam,newCmd; - QString sLabel = headTableList->keys()[curHeadIdx]; - QList dataRes = caliDataList->value(sLabel); - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + constsLable = headTableList->keys()[curHeadIdx]; + QList dataRes = caliDataList->value(constsLable); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); if(idx!=-1) sParam = dataRes[nextGageIndex][idx]; else - sParam = sLabel; //示值误差/回程误差/轻敲位移 - if(standardEngine.getState()){ + sParam = constsLable; //示值误差/回程误差/轻敲位移 + + InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); + constDataRes= dataRes[nextGageIndex]; + SendDevice(instrcutLib,&standardEngine); + /*if(standardEngine.getState()){ InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); if(instrcutLib!=nullptr){ QStringList sList = instrcutLib->instruct_config.split(";"); @@ -1166,7 +1272,7 @@ } } } - } + }*/ currentItem = ui->tableWidgetCheck->item(nextGageIndex, 0); currentItem->setSelected(true); @@ -1241,71 +1347,146 @@ } } } +void CheckWindow::InItcmd(){ + //发送INIt相关指令 + int count=0; + for(const ConnectInfo &visa:connectList) + { + VisaCommonEngine *Engine; + InstructionLib *instrcutLib; + if(connectList.length()>0&&visa.type==0) + { + instrcutLib = getCmdByCheckName(count,"INIT"); + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + instrcutLib = getCmdByCheckName(count,"INIT"); + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } + } + } + } + SendDevice(instrcutLib,Engine); + } +} void CheckWindow::connectDevice(){ - if(connectList.length()>0&&connectList[0].type==0){ - if(deviceEngine.openDevice(connectList[0].programInterface.visa,"Visa")){ - InstructionLib *instrcutLib = getCmdByCheckName(0,"INIT"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - deviceEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } - } - } - } - } - if(connectList.length()>1&&connectList[1].type==1) + int count=0; + QString rolename; + for(const ConnectInfo &visa:connectList) { - if(standardEngine.openDevice(connectList[1].programInterface.visa,"Visa")){ - ui->tableWidget_Standard->setItem(0,1,new QTableWidgetItem("ON")); - InstructionLib *instrcutLib = getCmdByCheckName(1,"INIT"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - standardEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } + VisaCommonEngine Engine; + if(Engine.openDevice(visa.programInterface.visa,"Visa")){ + if(connectList.length()>0&&visa.type==0) + { + deviceEngine=Engine; + } + if(connectList.length()>1&&visa.type==1) + { + if(connectList.count()==2){ + standardEngine=Engine; + }else{ + rolename=this->GetdeviceidByRole(visa.programInterface.device_id); + VisaStanEngineList.insert(rolename,Engine); } + } } + count++; + } - } +void CheckWindow::closeCmd(){ + //发送Close相关指令 + int count=0; + for(const ConnectInfo &visa:connectList) + { + VisaCommonEngine *Engine; + InstructionLib *instrcutLib; + if(connectList.length()>0&&visa.type==0) + { + instrcutLib = getCmdByCheckName(count,"CLOSE"); + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + instrcutLib = getCmdByCheckName(count,"CLOSE"); + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } + } + } + } + SendDevice(instrcutLib,Engine); + } +} void CheckWindow::closeDevice(){ - if(connectList.length()>0&&connectList[0].type==0){ - InstructionLib *instrcutLib = getCmdByCheckName(0,"CLOSE"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - deviceEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } - } - } - deviceEngine.closeDevice(); - } - if(connectList.length()>1&&connectList[1].type==1) + //关闭设备连接 + int count=0; + for(const ConnectInfo &visa:connectList) { - InstructionLib *instrcutLib = getCmdByCheckName(1,"CLOSE"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - standardEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; + VisaCommonEngine *Engine; + if(connectList.length()>0&&visa.type==0) + { + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } } } + } - standardEngine.closeDevice(); + Engine->closeDevice(); + count++; + } } +InstructionLib* CheckWindow::getCmdByRoleName(QString RoleName,QString name){ + for (ConnectInfo& info : connectList) { + if(info.rolenName==RoleName){ + for (InstructionLib& item : info.cmdList) { + if(item.belong_vername==name) + return &item; + } + } + + } + return nullptr; +} +VisaCommonEngine CheckWindow::getVisaCommbyRoleName(QString RoleName){ + VisaCommonEngine visa; + for(VisaCommonEngine &item : VisaStanEngineList){ + if(item.role==RoleName){ + return item; + } + } + return visa; +} InstructionLib* CheckWindow::getCmdByCheckName(int idx,QString name) { if(idx>=0&&idxkeys().count()==0) return; BaseCommonApi::SaveLogInfo(1,QString("-----------------------------------")); if(iEquipType==13) { + connectDevice(); this->Oscilloscopetextflow(); + return; } else if(iEquipType==4){ @@ -1508,70 +1692,69 @@ connectDevice(); for(int i=0;ikeys().length();i++) { + if(Teststate==SyncRunStatus::Stopped){break;}; //每次循环按钮变化 initCheckTable(i); - QString sLabel = headTableList->keys()[i]; - QList dataRes = caliDataList->value(sLabel); - BaseCommonApi::SaveLogInfo(1,QString("开始 %1 测试").arg(sLabel)); + constsLable= headTableList->keys()[i]; + QList dataRes = caliDataList->value(constsLable); + BaseCommonApi::SaveLogInfo(1,QString("开始 %1 测试").arg(constsLable)); for (int i = 0; i < dataRes.count(); ++i) { + if(Teststate==SyncRunStatus::Stopped){break;}; + constDataRes=dataRes[i]; + InItcmd(); QString sRet=""; QString newCmd; double dStdValue=FP_INFINITE,dError=0; QString newdStdValue,newdError; + CheckBackColorUpdate(true,i); //标准器输出 BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam; QStringList TempValue; TempValue.append("检定项目"); - int idx= getIndexByHeader(sLabel,TempValue); + int idx= getIndexByHeader(constsLable,TempValue); if(idx!=-1) sParam = dataRes[i][idx]; - if(standardEngine.getState()){ - InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i],true); - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } + //暂时加到这个地方 后面统一编写 + if(sParam=="DCI"||sParam=="ACI") + { + int idx2= getIndexByHeader(constsLable,QStrTranQStrList("单位")); + if(idx2!=-1) + { + QString ConstUnit=""; + QString v=dataRes[i][idx2].toUpper(); + if(i!=0) + ConstUnit=dataRes[i-1][idx2].toUpper(); + + BaseCommonApi::SaveLogInfo(1,ConstUnit+"-"+v); + if((ConstUnit=="MA" && v=="A") || (ConstUnit=="A" && v=="MA")) + { + if(!this->showDialog("电流换线提醒",QString("换线提醒\n %1 -> %2").arg(ConstUnit).arg(v))) + { + continue; + } } } } + InstructionLib *instrcutLibstan = getCmdByCheckName(1,sParam); + SendDevice(instrcutLibstan,&standardEngine,true); //被检设备读数 BaseCommonApi::SaveLogInfo(1,QString("被检设备输出")); - if(deviceEngine.getState()){ - InstructionLib *instrcutLib = getCmdByCheckName(0,sParam); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "config cmds:" << newCmd; - } - } - } - - newCmd = transCmd(instrcutLib->instruct_read,sLabel,dataRes[i]); - if(newCmd!=""){ - qDebug() << "query cmds:" << newCmd; - sRet = deviceEngine.queryData(newCmd); - TempValue.clear(); - TempValue.append("单位"); - idx= getIndexByHeader(sLabel,TempValue); - dStdValue = transUnit(sRet,dataRes[i][idx]); - } - } + InstructionLib *instrcutLib = getCmdByCheckName(0,sParam); + SendDevice(instrcutLib,&deviceEngine); + sRet=ReadDevice(instrcutLib,&deviceEngine); + if(sRet!=""){ + TempValue.clear(); + TempValue.append("单位"); + idx= getIndexByHeader(constsLable,TempValue); + dStdValue = transUnit(sRet,dataRes[i][idx]); } - autoAdujstData(sLabel,i,dStdValue,dataRes); + autoAdujstData(constsLable,i,dStdValue,dataRes); + CheckBackColorUpdate(false,i); + closeCmd(); Delay_MSec(2000); } - caliDataList->insert(sLabel,dataRes); + caliDataList->insert(constsLable,dataRes); } closeDevice(); } @@ -1842,15 +2025,17 @@ BaseCommonApi::SaveLogInfo(1,QString("---------------------------------------------------")); //首先检索当前检定项目的通道 initCheckTable(i); - QString sLabel = headTableList->keys()[i]; - QList dataRes = caliDataList->value(sLabel); - BaseCommonApi::SaveLogInfo(1,QString("开始 %1 %2 测试").arg(chList[_ch]).arg(sLabel)); + constsLable = headTableList->keys()[i]; + QList dataRes = caliDataList->value(constsLable); + BaseCommonApi::SaveLogInfo(1,QString("开始 %1 %2 测试").arg(chList[_ch]).arg(constsLable)); QString sParam; QString ValueUnit; InstructionLib *instrcutLibOhm; for (int i = 0; i < dataRes.count(); ++i) { TextCount=1; - int _dex= getIndexByHeader(sLabel,QStrTranQStrList("通道")); + constDataRes=dataRes[i]; + InItcmd(); + int _dex= getIndexByHeader(constsLable,QStrTranQStrList("通道")); if(_dex==-1){sParam=chList[_ch];}else{sParam=dataRes[i][_dex];} if(sParam!=chList[_ch]){continue;}; CheckBackColorUpdate(true,i); @@ -1858,80 +2043,46 @@ QString newCmd; double dStdValue=FP_INFINITE; QString newdStdValue; - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); QString sParam; if(idx!=-1) sParam = dataRes[i][idx]; InstructionLib *instrcutLibbiz=getCmdByCheckName(0,sParam); InstructionLib *instrcutLibstan=getCmdByCheckName(1,sParam); //INIT 被检设备 - 标准设备 - BaseCommonApi::SaveLogInfo(1,QString("INIT")); - InstructionLib *InItbiz; - InstructionLib *InItstan; - InItbiz= getCmdByCheckName(0,"INIT"); - InItstan= getCmdByCheckName(1,"INIT"); - if(InItbiz!=nullptr && instrcutLibbiz!=nullptr) - { - if(deviceEngine.getState() ) + instrcutLibOhm= getCmdByCheckName(0,"电阻"); + if(deviceEngine.getState()) { //设置电阻值+ instrcutLibOhm= getCmdByCheckName(0,"电阻"); if(instrcutLibOhm!=nullptr){ QStringList ohmList = instrcutLibOhm->instruct_config.split(";"); - int idxohm= getIndexByHeader(sLabel,QStrTranQStrList("阻抗")); + int idxohm= getIndexByHeader(constsLable,QStrTranQStrList("阻抗")); + if(sParam=="输入电阻"){ + if(!this->showDialog("输入电阻","请接入电阻测试线")){continue;} + idxohm= getIndexByHeader(constsLable,QStrTranQStrList("标称值")); + } + if(idxohm!=-1) { QString onmname="50Ω"; QString CmdOhm; onmname=dataRes[i][idxohm]; - if(onmname=="50Ω"){CmdOhm=ohmList[0];}else{CmdOhm=ohmList[1];}; - newCmd = transCmd(CmdOhm,sLabel,dataRes[i],true); + if(onmname=="50Ω"){CmdOhm=ohmList[0];} + else if(onmname=="75Ω"){CmdOhm=ohmList[1];} + else{ + if(ohmList.count()>2){CmdOhm=ohmList[2];}else{CmdOhm=ohmList[1];}; + } + newCmd = transCmd(CmdOhm,constsLable,constDataRes,true); deviceEngine.sendData(newCmd); } } - //读取配置指令 - - QStringList sList = InItbiz->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - }; - - } - - if(InItstan!=nullptr && instrcutLibstan!=nullptr) - { - if(standardEngine.getState()) - { - //读取配置指令 - QStringList sList = InItstan->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - } - - } + } if(sParam=="频带宽度"){TextCount=2;}; for (int d=0;dinstruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "config cmds:" << newCmd; - } - } - } - newCmd = transCmd(instrcutLibbiz->instruct_read,sLabel,dataRes[i]); - if(newCmd!=""){ - qDebug() << "query cmds:" << newCmd; + SendDevice(instrcutLibbiz,&deviceEngine); + sRet=ReadDevice(instrcutLibbiz,&deviceEngine); + if(sParam=="输入电阻"){ + BaseCommonApi::SaveLogInfo(1,QString("数字万用表控制")); + VisaCommonEngine tempEngine=getVisaCommbyRoleName("数字多用表"); //角色 + InstructionLib *instrcutLibNum=getCmdByRoleName("数字多用表",sParam); + sRet=ReadDevice(instrcutLibNum,&tempEngine); + } + if(sParam=="校准信号"){ + idx= getIndexByHeader(constsLable,QStrTranQStrList("项目")); + if(dataRes[i][idx]=="频率"){ + if(!this->showDialog("输入电阻","请接入频率测试线")){continue;} + BaseCommonApi::SaveLogInfo(1,QString("通用计数器控制")); + VisaCommonEngine tempEngine=getVisaCommbyRoleName("通用计数器"); //角色 + InstructionLib *instrcutLibNum=getCmdByRoleName("通用计数器",sParam); + SendDevice(instrcutLibbiz,&deviceEngine); + sRet=ReadDevice(instrcutLibNum,&tempEngine); + } + } + //测试结果单位转换 + if(sRet!=""){ + idx= getIndexByHeader(constsLable,QStrTranQStrList("单位")); + //ValueUnit + if(idx!=-1) + { + ValueUnit=dataRes[i][idx]; + }else + { + QStringList temp; + temp.append("标准值"); + temp.append("标称值"); + int idx= getIndexByHeader(constsLable,temp); + if(idx!=-1) + ItemUnitSplit(dataRes[i][idx],ValueUnit,ValueUnit); - sRet = deviceEngine.queryData(newCmd); - idx= getIndexByHeader(sLabel,QStrTranQStrList("单位")); - //ValueUnit - if(idx!=-1) - { - ValueUnit=dataRes[i][idx]; - }else - { - QStringList temp; - temp.append("标准值"); - temp.append("标称值"); - int idx= getIndexByHeader(sLabel,temp); - if(idx!=-1) - ItemUnitSplit(dataRes[i][idx],ValueUnit,ValueUnit); - - } - dStdValue = transUnit(sRet,ValueUnit); - - } - } - + } + dStdValue = transUnit(sRet,ValueUnit); } - - autoAdujstData(sLabel,i,dStdValue,dataRes); + autoAdujstData(constsLable,i,dStdValue,dataRes); CheckBackColorUpdate(false,i); + closeCmd(); Delay_MSec(2000); + } //CLOSE 被检设备 - 标准设备 - BaseCommonApi::SaveLogInfo(1,QString("CLOSE")); - InstructionLib *Closebiz; - InstructionLib *Closestan; - Closebiz= getCmdByCheckName(0,"CLOSE"); - Closestan= getCmdByCheckName(1,"CLOSE"); - if(Closestan!=nullptr && instrcutLibstan!=nullptr) - { - if(standardEngine.getState()) - { - //读取配置指令 - QStringList sList = Closestan->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - } - } - // - if(Closebiz!=nullptr && instrcutLibbiz!=nullptr) - { - if(deviceEngine.getState()) - { - //读取配置指令 - QStringList sList = Closebiz->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - }; - - } } - caliDataList->insert(sLabel,dataRes); + caliDataList->insert(constsLable,dataRes); } + closeDevice(); } } void CheckWindow::Delay_MSec(unsigned int msec) @@ -2065,10 +2176,13 @@ void CheckWindow::on_pushButton_stop_clicked() { + Teststate=SyncRunStatus::Stopped; + if(iEquipType==5){ if(timerChart->isActive()) timerChart->stop(); } + } void CheckWindow::on_pushButton_clicked() @@ -2307,6 +2421,42 @@ } //QWidget::keyPressEvent(ev); } +void CheckWindow::SendDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran){ + //发送仪器 进一步封装 + QString newCmd=""; + if(Visa->getState()){ + if(Inst!=nullptr){ + QStringList sList = Inst->instruct_config.split(";"); + if(sList.length()>0){ + for (QString& sCmd : sList){ + newCmd = transCmd(sCmd,constsLable,constDataRes,IsUnitTran); + if(newCmd!=""){ + QString str=Visa->commType; + Visa->sendData(newCmd); + qDebug() << "config cmds:" << newCmd; + } + } + } + } +} +} +QString CheckWindow::ReadDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran){ + //读取仪器 进一步封装 + QString newCmd=""; + QString result=""; + if(Visa->getState()){ + if(Inst!=nullptr){ + newCmd = transCmd(Inst->instruct_read,constsLable,constDataRes,IsUnitTran); + if(newCmd!=""){ + qDebug() << "query cmds:" << newCmd; + result = Visa->queryData(newCmd); + } + } + } + return result; +} + + void CheckWindow::CreateCharts(){ deleteItem(ui->horizontalLayoutChart); @@ -2545,3 +2695,4 @@ caliDataList->insert(sLabel,dataRes); } } + diff --git a/softwareDirectory/AutoVerScheme/checkwindow.h b/softwareDirectory/AutoVerScheme/checkwindow.h index d559ac9..04f5425 100644 --- a/softwareDirectory/AutoVerScheme/checkwindow.h +++ b/softwareDirectory/AutoVerScheme/checkwindow.h @@ -24,6 +24,7 @@ int type; QString deviceName; QString state; + QString rolenName; VerificationProgramConfigInterface programInterface; QList cmdList; }; @@ -81,6 +82,7 @@ void addGageData(bool bAdd=true); void on_pushButton_next_clicked(); + void onComboBoxCurrTextChanged(QString value,QString device_id,int row); QMap readDataFromFile(QString filePath); void RefreshTime_Slot(); void on_pushButtonGetTemp_clicked(); @@ -88,7 +90,7 @@ private: void getCheckDevice(bool bInit=true); void getCheckMethod(); - void initDeviceInfo(QString sId); + void initDeviceInfo(QList sId); void deleteItem(QLayout *layout); void initCheckTable(int idx); InstructionLib* getCmdByCheckName(int idx,QString name); @@ -119,6 +121,13 @@ QStringList QStrTranQStrList(QString value); void changeDevice(int idx); void keyPressEvent(QKeyEvent *ev); + QString GetdeviceidByRole(QString device_id); + InstructionLib* getCmdByRoleName(QString RoleName,QString name); + VisaCommonEngine getVisaCommbyRoleName(QString RoleName); + QString ReadDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran=false); + void SendDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran=false); + void InItcmd(); + void closeCmd(); void CreateCharts(); private: Ui::CheckWindow *ui; @@ -132,6 +141,8 @@ VisaCommonEngine deviceEngine; VisaCommonEngine standardEngine; VisaCommonEngine engine;; + QMap VisaStanEngineList; + QList measureCa3lList; QList measureCalList; SaveDeviceMeasureInfo measureInfo; QMap> *caliDataList; @@ -146,6 +157,7 @@ QMap unitTypeTransList; QMap cmdPlaceHolderList; + QList StandarIdList; QString standardId; int currConnectIdx; QList pageButtons; @@ -159,8 +171,16 @@ QString curDeviceId=""; int curDevciceIdx=-1; int nextGageIndex=-1; + + QList DeviceMeasureEquipmentCatorycatory; + QList RoleList; + + QString constsLable; + QStringList constDataRes; + QChartView *chartView; QTimer* timerChart; + SyncRunStatus Teststate; }; #endif // CHECKWINDOW_H diff --git a/softwareDirectory/AutoVerScheme/checkwindow.ui b/softwareDirectory/AutoVerScheme/checkwindow.ui index d2bfbac..a753c93 100644 --- a/softwareDirectory/AutoVerScheme/checkwindow.ui +++ b/softwareDirectory/AutoVerScheme/checkwindow.ui @@ -939,6 +939,11 @@ 检定有效期 + + + 角色信息 + + @@ -1142,6 +1147,11 @@ + 角色 + + + + 设备名称 @@ -1795,13 +1805,25 @@ + 角色 + + + + Arial + 10 + + + + + 设备名称 - 12 - 75 - true + Arial + 10 + 50 + false @@ -1811,9 +1833,10 @@ - 12 - 75 - true + Arial + 10 + 50 + false @@ -1941,6 +1964,9 @@ true + + color:orange + 出厂编号: @@ -2221,8 +2247,8 @@ showMethod() - 153 - 234 + 726 + 760 884 @@ -2237,8 +2263,8 @@ showCheck() - 1095 - 571 + 1187 + 581 1328 @@ -2253,8 +2279,8 @@ showMethodWidget() - 61 - 91 + 713 + 121 3 @@ -2269,8 +2295,8 @@ showResult() - 55 - 91 + 580 + 121 -1 diff --git a/softwareDirectory/AutoVerScheme/visacommonengine.cpp b/softwareDirectory/AutoVerScheme/visacommonengine.cpp index 39dfed2..e3541d0 100644 --- a/softwareDirectory/AutoVerScheme/visacommonengine.cpp +++ b/softwareDirectory/AutoVerScheme/visacommonengine.cpp @@ -2,10 +2,13 @@ #include -VisaCommonEngine::VisaCommonEngine() +VisaCommonEngine::VisaCommonEngine() : serial(new QSerialPort) { } +VisaCommonEngine::~VisaCommonEngine() +{ +} /*VisaCommonEngine::~VisaCommonEngine() { @@ -167,9 +170,9 @@ QStringList sList = sAddr.split(";"); if(sList.length()==5){ //设置串口名 - serial.setPortName(sList[0]); + serial->setPortName(sList[0]); //设置波特率 - serial.setBaudRate(sList[1].toInt()); + serial->setBaudRate(sList[1].toInt()); //设置奇偶校验 QSerialPort::Parity parity=QSerialPort::NoParity; if(sList[2]=="None") @@ -178,14 +181,14 @@ parity = QSerialPort::OddParity; else if(sList[2]=="Even") parity = QSerialPort::EvenParity; - serial.setParity(parity); + serial->setParity(parity); //设置数据位数 QSerialPort::DataBits bits=QSerialPort::Data7; if(sList[3]=="7") bits=QSerialPort::Data7; else if(sList[3]=="8") bits=QSerialPort::Data8; - serial.setDataBits(bits); + serial->setDataBits(bits); //设置停止位 QSerialPort::StopBits stop =QSerialPort::OneStop; @@ -197,11 +200,11 @@ stop=QSerialPort::TwoStop; else if(sList[4]=="OnePointFive") stop=QSerialPort::OneAndHalfStop; - serial.setStopBits(stop); + serial->setStopBits(stop); //设置流控制 //serial.setFlowControl(QSerialPort::NoFlowControl); //打开串口 - if(serial.open(QIODevice::ReadWrite)){ + if(serial->open(QIODevice::ReadWrite)){ commState = true; return true; } @@ -217,7 +220,7 @@ status = viClose(defaultRM); commState = false; }else{ - serial.close(); + serial->close(); commState = false; } } @@ -241,11 +244,11 @@ } return ""; }else{ - serial.clear(); + serial->clear(); sendData(sCmd); QString strRet; QByteArray buf; - buf = serial.readAll(); + buf = serial->readAll(); if(!buf.isEmpty()) { strRet=QString::fromLatin1(buf); @@ -257,6 +260,7 @@ bool VisaCommonEngine::sendData(QString sCmd) { + QString srr=commType; //strcpy(stringinput, strData.toLatin1().data()); //strcpy(stringinput, "*IDN?\n"); if(commType=="Visa"){ @@ -270,7 +274,7 @@ } return true; }else{ - serial.write(sCmd.toLatin1()); + serial->write(sCmd.toLatin1()); return true; } } diff --git a/softwareDirectory/AutoVerScheme/checkwindow.cpp b/softwareDirectory/AutoVerScheme/checkwindow.cpp index dcaa48a..99738d8 100644 --- a/softwareDirectory/AutoVerScheme/checkwindow.cpp +++ b/softwareDirectory/AutoVerScheme/checkwindow.cpp @@ -36,9 +36,10 @@ for(int i=0;i<2;i++) ui->tableWidget_Standard->horizontalHeader()->setSectionResizeMode(i,QHeaderView::Stretch); ui->tableWidgetStd->verticalHeader()->setParent(nullptr); //隐藏行头 - for(int i=1;i<7;i++) + for(int i=1;i<6;i++) ui->tableWidgetStd->horizontalHeader()->setSectionResizeMode(i,QHeaderView::Stretch); ui->tableWidgetStd->setColumnWidth(0, 60); + ui->tableWidgetStd->setColumnWidth(7, 120); ui->tableWidgetCheck->verticalHeader()->setParent(nullptr); ui->comboBoxName->addItem("ALL"); ui->comboBoxModal->addItem("ALL"); @@ -74,6 +75,7 @@ measureCalList.clear(); caliDataListAll.clear(); headTableListAll.clear(); + VisaStanEngineList.clear(); delete ui; } @@ -104,21 +106,30 @@ void CheckWindow::updateStandardTable() { + + + QStringList ValueList; + ValueList.append("请选择角色"); + for (int i=0;itableWidgetStd->clearContents(); ui->tableWidgetStd->setRowCount(0); QString sFilterName = ui->comboBoxName_2->currentText(); QString sFilterModal = ui->comboBoxModal_2->currentText(); QString sFilterDepart = ui->lineEdit_4->text(); QString sFilterNo = ui->lineEditNo_2->text(); - int rowCount=0; - int row=0; + //catDeviceList.clear(); catIdList.clear(); if(programInfo.standard_device_id!=""){ catIdList = programInfo.standard_device_id.split(","); + int row=0; for(int i=catIdList.length()-1;i>=0; i--) { QString id = catIdList[i]; + + QString readraleName; QList result = BaseCommonApi::getCatDeviceInfor(id); if(result.length()>0){ CatDeviceInfor item = result[0]; @@ -148,17 +159,82 @@ ui->tableWidgetStd->setItem(0, 4, new QTableWidgetItem(item.dept_name)); ui->tableWidgetStd->setItem(0, 5, new QTableWidgetItem(item.director_name)); ui->tableWidgetStd->setItem(0, 6, new QTableWidgetItem(item.measure_valid_date)); - row++; + if(RoleList.count()!=0){ + + QComboBox *comboBox=new QComboBox(); + comboBox->addItems(ValueList); + ui->tableWidgetStd->setCellWidget(0, 7,comboBox); + + readraleName=GetdeviceidByRole(id); + if(readraleName!=""){ + comboBox->setCurrentText(readraleName); + } + // 连接下拉框的currentIndexChanged信号到槽函数 + connect(comboBox, &QComboBox::currentTextChanged, this, [this, id,comboBox,i]() { + onComboBoxCurrTextChanged(comboBox->currentText(),id,i); + + }); + }else{ui->tableWidgetStd->setItem(0, 7,new QTableWidgetItem("标准设备"));} + + + //catDeviceList.append(item); }else{ catIdList.removeAt(i); } } result.clear(); + row++; } + } } +void CheckWindow::onComboBoxCurrTextChanged(QString Value,QString device_id,int row) +{ + if(RoleList.count()!=0){ + QString cateory_id=DeviceMeasureEquipmentCatorycatory[0].item_category_id; + for (int i=0;itableWidgetStd->rowCount();i++){ + QComboBox *comboBox = qobject_cast(ui->tableWidgetStd->cellWidget(i, 7)); + if (comboBox) { + QString str=comboBox->currentText(); + if(comboBox->currentText()==Value && i!=row){ + comboBox->setCurrentIndex(0); + } + } + } + + + } + +} +QString CheckWindow::GetdeviceidByRole(QString device_id) +{ + QString cateory_id=DeviceMeasureEquipmentCatorycatory[0].item_category_id; + QString temprole=""; + for(int i=0;itableWidgetMethod->rowCount();i++){ @@ -196,8 +272,13 @@ ui->comboBoxModal_2->setCurrentIndex(0); ui->lineEditNo_2->setText(""); ui->lineEdit_4->setText(""); + //获取检定项分类 及 检定项分类包含的角色 + DeviceMeasureEquipmentCatorycatory = BaseCommonApi::getDeviceMeasureEquipmentCatory(selectTaskList[0].sample_id); + RoleList=BaseCommonApi::getDeviceRoleBydeviceId(DeviceMeasureEquipmentCatorycatory[0].item_category_id); updateStandardTable(); } + //查询角色表信息 getDeviceRoleBydeviceId + //catory[0].item_category_id 检定项目ID ui->stackedWidget->setCurrentIndex(2); } } @@ -206,31 +287,39 @@ { //QStringList idList = programInfo.standard_device_id.split(","); QString sId=""; - for(int i=0;itableWidgetStd->rowCount();i++){ + StandarIdList.clear(); + /*for(int i=0;itableWidgetStd->rowCount();i++){ Qt::CheckState state = ui->tableWidgetStd->item(i,0)->checkState(); if(state == Qt::Checked){ sId = catIdList[i]; break; } - } + }*/ + for(int i=0;itableWidgetStd->rowCount();i++){ + Qt::CheckState state = ui->tableWidgetStd->item(i,0)->checkState(); + if(state == Qt::Checked){ + StandarIdList.append(catIdList[i]); + break; + } + } if(catIdList.count()==1) { - sId = catIdList[0]; + StandarIdList.append(catIdList[0]); } - if(sId==""){ + if(StandarIdList.count()==0){ QMessageBox::warning(this, "提示", "请选择标准设备!"); }else{ //programInfo = BaseCommonApi::getVerificationProgramInfo(sId); - initDeviceInfo(sId); + initDeviceInfo(StandarIdList); ui->stackedWidget->setCurrentIndex(3); } } -void CheckWindow::initDeviceInfo(QString sId) +void CheckWindow::initDeviceInfo(QList sId) { - standardId = sId; + StandarIdList = sId; QString strStyle = QString("QLabel{image:url(%1);}").arg(programInfo.img_path); qDebug() << "strStyle:" << strStyle; ui->label_8->setStyleSheet(strStyle); @@ -246,8 +335,9 @@ connectList.clear(); if(selectTaskList.length()>0) { - QList catory = BaseCommonApi::getDeviceMeasureEquipmentCatory(selectTaskList[0].sample_id); + QList catory = DeviceMeasureEquipmentCatorycatory; if(catory.length() > 0 ){ + ui->lineEdit_category->setText(catory[0].item_category_name); } //idList = programInfo.tested_device_id.split(","); @@ -263,6 +353,7 @@ info.programInterface = addrList[0]; } info.cmdList = BaseCommonApi::getInstructionLib(programInfo.id); + info.rolenName="被检设备"; connectList.append(info); addrList.clear(); } @@ -271,14 +362,19 @@ if(programInfo.standard_device_id!=""){ idList = programInfo.standard_device_id.split(","); + for(const QString& id : idList) { - if(id!=sId) - continue; + //if(id!=CheckId) + // continue; ConnectInfo info; info.id = id; info.type = 1; info.state="未连接"; + if(idList.count()==1) + info.rolenName="标准设备"; + else + info.rolenName=GetdeviceidByRole(id); QList result = BaseCommonApi::getCatDeviceInfor(id); if(result.length()>0){ info.deviceName = result[0].equipment_name; @@ -286,8 +382,9 @@ //更新标准设备表格 rowCount = ui->tableWidget_Standard->rowCount(); ui->tableWidget_Standard->insertRow(rowCount); - ui->tableWidget_Standard->setItem(row, 0, new QTableWidgetItem(info.deviceName)); - ui->tableWidget_Standard->setItem(row, 1, new QTableWidgetItem("OFF")); //设置数据 + ui->tableWidget_Standard->setItem(row, 0, new QTableWidgetItem(info.rolenName)); + ui->tableWidget_Standard->setItem(row, 1, new QTableWidgetItem(info.deviceName)); + ui->tableWidget_Standard->setItem(row, 2, new QTableWidgetItem("OFF")); //设置数据 row++; } result.clear(); @@ -299,6 +396,7 @@ connectList.append(info); addrList.clear(); } + idList.clear(); } rowCount=0; @@ -306,8 +404,9 @@ for(const ConnectInfo& info : connectList){ rowCount = ui->tableWidget_3->rowCount(); ui->tableWidget_3->insertRow(rowCount); - ui->tableWidget_3->setItem(row, 0, new QTableWidgetItem(info.deviceName)); - ui->tableWidget_3->setItem(row, 1, new QTableWidgetItem(info.state)); //设置数据 + ui->tableWidget_3->setItem(row, 0, new QTableWidgetItem(info.rolenName)); + ui->tableWidget_3->setItem(row, 1, new QTableWidgetItem(info.deviceName)); + ui->tableWidget_3->setItem(row, 2, new QTableWidgetItem(info.state)); //设置数据 row++; } //搜索仪器地址放入下拉框 @@ -836,8 +935,8 @@ //修改连接状态 if(getJoinState(addr.visa)) { - ui->tableWidget_3->setItem(currentRow,1,new QTableWidgetItem("ON")); - }else{ ui->tableWidget_3->setItem(currentRow,1,new QTableWidgetItem("OFF"));} + ui->tableWidget_3->setItem(currentRow,2,new QTableWidgetItem("已连接")); + }else{ ui->tableWidget_3->setItem(currentRow,2,new QTableWidgetItem("未连接"));} } } @@ -1087,20 +1186,23 @@ BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam,newCmd; - QString sLabel = headTableList->keys()[curHeadIdx]; - QList dataRes = caliDataList->value(sLabel); - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + constsLable = headTableList->keys()[curHeadIdx]; + QList dataRes = caliDataList->value(constsLable); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); if(idx!=-1) sParam = dataRes[nextGageIndex][idx]; else - sParam = sLabel; //示值误差/回程误差/轻敲位移 - if(standardEngine.getState()){ + sParam = constsLable; //示值误差/回程误差/轻敲位移 + InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); + constDataRes= dataRes[nextGageIndex]; + SendDevice(instrcutLib,&standardEngine); + /*if(standardEngine.getState()){ InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); if(instrcutLib!=nullptr){ QStringList sList = instrcutLib->instruct_config.split(";"); if(sList.length()>0){ for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[nextGageIndex],true); + newCmd = transCmd(sCmd,constsLable,dataRes[nextGageIndex],true); if(newCmd!=""){ standardEngine.sendData(newCmd); qDebug() << "standard cmds:" << newCmd; @@ -1108,7 +1210,7 @@ } } } - } + }*/ currentItem = ui->tableWidgetCheck->item(nextGageIndex, 0); currentItem->setSelected(true); @@ -1145,14 +1247,18 @@ BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam,newCmd; - QString sLabel = headTableList->keys()[curHeadIdx]; - QList dataRes = caliDataList->value(sLabel); - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + constsLable = headTableList->keys()[curHeadIdx]; + QList dataRes = caliDataList->value(constsLable); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); if(idx!=-1) sParam = dataRes[nextGageIndex][idx]; else - sParam = sLabel; //示值误差/回程误差/轻敲位移 - if(standardEngine.getState()){ + sParam = constsLable; //示值误差/回程误差/轻敲位移 + + InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); + constDataRes= dataRes[nextGageIndex]; + SendDevice(instrcutLib,&standardEngine); + /*if(standardEngine.getState()){ InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); if(instrcutLib!=nullptr){ QStringList sList = instrcutLib->instruct_config.split(";"); @@ -1166,7 +1272,7 @@ } } } - } + }*/ currentItem = ui->tableWidgetCheck->item(nextGageIndex, 0); currentItem->setSelected(true); @@ -1241,71 +1347,146 @@ } } } +void CheckWindow::InItcmd(){ + //发送INIt相关指令 + int count=0; + for(const ConnectInfo &visa:connectList) + { + VisaCommonEngine *Engine; + InstructionLib *instrcutLib; + if(connectList.length()>0&&visa.type==0) + { + instrcutLib = getCmdByCheckName(count,"INIT"); + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + instrcutLib = getCmdByCheckName(count,"INIT"); + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } + } + } + } + SendDevice(instrcutLib,Engine); + } +} void CheckWindow::connectDevice(){ - if(connectList.length()>0&&connectList[0].type==0){ - if(deviceEngine.openDevice(connectList[0].programInterface.visa,"Visa")){ - InstructionLib *instrcutLib = getCmdByCheckName(0,"INIT"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - deviceEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } - } - } - } - } - if(connectList.length()>1&&connectList[1].type==1) + int count=0; + QString rolename; + for(const ConnectInfo &visa:connectList) { - if(standardEngine.openDevice(connectList[1].programInterface.visa,"Visa")){ - ui->tableWidget_Standard->setItem(0,1,new QTableWidgetItem("ON")); - InstructionLib *instrcutLib = getCmdByCheckName(1,"INIT"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - standardEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } + VisaCommonEngine Engine; + if(Engine.openDevice(visa.programInterface.visa,"Visa")){ + if(connectList.length()>0&&visa.type==0) + { + deviceEngine=Engine; + } + if(connectList.length()>1&&visa.type==1) + { + if(connectList.count()==2){ + standardEngine=Engine; + }else{ + rolename=this->GetdeviceidByRole(visa.programInterface.device_id); + VisaStanEngineList.insert(rolename,Engine); } + } } + count++; + } - } +void CheckWindow::closeCmd(){ + //发送Close相关指令 + int count=0; + for(const ConnectInfo &visa:connectList) + { + VisaCommonEngine *Engine; + InstructionLib *instrcutLib; + if(connectList.length()>0&&visa.type==0) + { + instrcutLib = getCmdByCheckName(count,"CLOSE"); + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + instrcutLib = getCmdByCheckName(count,"CLOSE"); + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } + } + } + } + SendDevice(instrcutLib,Engine); + } +} void CheckWindow::closeDevice(){ - if(connectList.length()>0&&connectList[0].type==0){ - InstructionLib *instrcutLib = getCmdByCheckName(0,"CLOSE"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - deviceEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; - } - } - } - deviceEngine.closeDevice(); - } - if(connectList.length()>1&&connectList[1].type==1) + //关闭设备连接 + int count=0; + for(const ConnectInfo &visa:connectList) { - InstructionLib *instrcutLib = getCmdByCheckName(1,"CLOSE"); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - standardEngine.sendData(sCmd); - qDebug() << "standard cmds:" << sCmd; + VisaCommonEngine *Engine; + if(connectList.length()>0&&visa.type==0) + { + Engine=&deviceEngine; + } + if(connectList.length()>1&&visa.type==1) + { + if(connectList.count()==1){ + Engine=&standardEngine; + }else{ + int stancount=0; + for (VisaCommonEngine &item:VisaStanEngineList) { + if(stancount==count-1){ + Engine=&item; + break; + } } } + } - standardEngine.closeDevice(); + Engine->closeDevice(); + count++; + } } +InstructionLib* CheckWindow::getCmdByRoleName(QString RoleName,QString name){ + for (ConnectInfo& info : connectList) { + if(info.rolenName==RoleName){ + for (InstructionLib& item : info.cmdList) { + if(item.belong_vername==name) + return &item; + } + } + + } + return nullptr; +} +VisaCommonEngine CheckWindow::getVisaCommbyRoleName(QString RoleName){ + VisaCommonEngine visa; + for(VisaCommonEngine &item : VisaStanEngineList){ + if(item.role==RoleName){ + return item; + } + } + return visa; +} InstructionLib* CheckWindow::getCmdByCheckName(int idx,QString name) { if(idx>=0&&idxkeys().count()==0) return; BaseCommonApi::SaveLogInfo(1,QString("-----------------------------------")); if(iEquipType==13) { + connectDevice(); this->Oscilloscopetextflow(); + return; } else if(iEquipType==4){ @@ -1508,70 +1692,69 @@ connectDevice(); for(int i=0;ikeys().length();i++) { + if(Teststate==SyncRunStatus::Stopped){break;}; //每次循环按钮变化 initCheckTable(i); - QString sLabel = headTableList->keys()[i]; - QList dataRes = caliDataList->value(sLabel); - BaseCommonApi::SaveLogInfo(1,QString("开始 %1 测试").arg(sLabel)); + constsLable= headTableList->keys()[i]; + QList dataRes = caliDataList->value(constsLable); + BaseCommonApi::SaveLogInfo(1,QString("开始 %1 测试").arg(constsLable)); for (int i = 0; i < dataRes.count(); ++i) { + if(Teststate==SyncRunStatus::Stopped){break;}; + constDataRes=dataRes[i]; + InItcmd(); QString sRet=""; QString newCmd; double dStdValue=FP_INFINITE,dError=0; QString newdStdValue,newdError; + CheckBackColorUpdate(true,i); //标准器输出 BaseCommonApi::SaveLogInfo(1,QString("标准器输出")); QString sParam; QStringList TempValue; TempValue.append("检定项目"); - int idx= getIndexByHeader(sLabel,TempValue); + int idx= getIndexByHeader(constsLable,TempValue); if(idx!=-1) sParam = dataRes[i][idx]; - if(standardEngine.getState()){ - InstructionLib *instrcutLib = getCmdByCheckName(1,sParam); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i],true); - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } + //暂时加到这个地方 后面统一编写 + if(sParam=="DCI"||sParam=="ACI") + { + int idx2= getIndexByHeader(constsLable,QStrTranQStrList("单位")); + if(idx2!=-1) + { + QString ConstUnit=""; + QString v=dataRes[i][idx2].toUpper(); + if(i!=0) + ConstUnit=dataRes[i-1][idx2].toUpper(); + + BaseCommonApi::SaveLogInfo(1,ConstUnit+"-"+v); + if((ConstUnit=="MA" && v=="A") || (ConstUnit=="A" && v=="MA")) + { + if(!this->showDialog("电流换线提醒",QString("换线提醒\n %1 -> %2").arg(ConstUnit).arg(v))) + { + continue; + } } } } + InstructionLib *instrcutLibstan = getCmdByCheckName(1,sParam); + SendDevice(instrcutLibstan,&standardEngine,true); //被检设备读数 BaseCommonApi::SaveLogInfo(1,QString("被检设备输出")); - if(deviceEngine.getState()){ - InstructionLib *instrcutLib = getCmdByCheckName(0,sParam); - if(instrcutLib!=nullptr){ - QStringList sList = instrcutLib->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "config cmds:" << newCmd; - } - } - } - - newCmd = transCmd(instrcutLib->instruct_read,sLabel,dataRes[i]); - if(newCmd!=""){ - qDebug() << "query cmds:" << newCmd; - sRet = deviceEngine.queryData(newCmd); - TempValue.clear(); - TempValue.append("单位"); - idx= getIndexByHeader(sLabel,TempValue); - dStdValue = transUnit(sRet,dataRes[i][idx]); - } - } + InstructionLib *instrcutLib = getCmdByCheckName(0,sParam); + SendDevice(instrcutLib,&deviceEngine); + sRet=ReadDevice(instrcutLib,&deviceEngine); + if(sRet!=""){ + TempValue.clear(); + TempValue.append("单位"); + idx= getIndexByHeader(constsLable,TempValue); + dStdValue = transUnit(sRet,dataRes[i][idx]); } - autoAdujstData(sLabel,i,dStdValue,dataRes); + autoAdujstData(constsLable,i,dStdValue,dataRes); + CheckBackColorUpdate(false,i); + closeCmd(); Delay_MSec(2000); } - caliDataList->insert(sLabel,dataRes); + caliDataList->insert(constsLable,dataRes); } closeDevice(); } @@ -1842,15 +2025,17 @@ BaseCommonApi::SaveLogInfo(1,QString("---------------------------------------------------")); //首先检索当前检定项目的通道 initCheckTable(i); - QString sLabel = headTableList->keys()[i]; - QList dataRes = caliDataList->value(sLabel); - BaseCommonApi::SaveLogInfo(1,QString("开始 %1 %2 测试").arg(chList[_ch]).arg(sLabel)); + constsLable = headTableList->keys()[i]; + QList dataRes = caliDataList->value(constsLable); + BaseCommonApi::SaveLogInfo(1,QString("开始 %1 %2 测试").arg(chList[_ch]).arg(constsLable)); QString sParam; QString ValueUnit; InstructionLib *instrcutLibOhm; for (int i = 0; i < dataRes.count(); ++i) { TextCount=1; - int _dex= getIndexByHeader(sLabel,QStrTranQStrList("通道")); + constDataRes=dataRes[i]; + InItcmd(); + int _dex= getIndexByHeader(constsLable,QStrTranQStrList("通道")); if(_dex==-1){sParam=chList[_ch];}else{sParam=dataRes[i][_dex];} if(sParam!=chList[_ch]){continue;}; CheckBackColorUpdate(true,i); @@ -1858,80 +2043,46 @@ QString newCmd; double dStdValue=FP_INFINITE; QString newdStdValue; - int idx= getIndexByHeader(sLabel,QStrTranQStrList("检定项目")); + int idx= getIndexByHeader(constsLable,QStrTranQStrList("检定项目")); QString sParam; if(idx!=-1) sParam = dataRes[i][idx]; InstructionLib *instrcutLibbiz=getCmdByCheckName(0,sParam); InstructionLib *instrcutLibstan=getCmdByCheckName(1,sParam); //INIT 被检设备 - 标准设备 - BaseCommonApi::SaveLogInfo(1,QString("INIT")); - InstructionLib *InItbiz; - InstructionLib *InItstan; - InItbiz= getCmdByCheckName(0,"INIT"); - InItstan= getCmdByCheckName(1,"INIT"); - if(InItbiz!=nullptr && instrcutLibbiz!=nullptr) - { - if(deviceEngine.getState() ) + instrcutLibOhm= getCmdByCheckName(0,"电阻"); + if(deviceEngine.getState()) { //设置电阻值+ instrcutLibOhm= getCmdByCheckName(0,"电阻"); if(instrcutLibOhm!=nullptr){ QStringList ohmList = instrcutLibOhm->instruct_config.split(";"); - int idxohm= getIndexByHeader(sLabel,QStrTranQStrList("阻抗")); + int idxohm= getIndexByHeader(constsLable,QStrTranQStrList("阻抗")); + if(sParam=="输入电阻"){ + if(!this->showDialog("输入电阻","请接入电阻测试线")){continue;} + idxohm= getIndexByHeader(constsLable,QStrTranQStrList("标称值")); + } + if(idxohm!=-1) { QString onmname="50Ω"; QString CmdOhm; onmname=dataRes[i][idxohm]; - if(onmname=="50Ω"){CmdOhm=ohmList[0];}else{CmdOhm=ohmList[1];}; - newCmd = transCmd(CmdOhm,sLabel,dataRes[i],true); + if(onmname=="50Ω"){CmdOhm=ohmList[0];} + else if(onmname=="75Ω"){CmdOhm=ohmList[1];} + else{ + if(ohmList.count()>2){CmdOhm=ohmList[2];}else{CmdOhm=ohmList[1];}; + } + newCmd = transCmd(CmdOhm,constsLable,constDataRes,true); deviceEngine.sendData(newCmd); } } - //读取配置指令 - - QStringList sList = InItbiz->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - }; - - } - - if(InItstan!=nullptr && instrcutLibstan!=nullptr) - { - if(standardEngine.getState()) - { - //读取配置指令 - QStringList sList = InItstan->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - } - - } + } if(sParam=="频带宽度"){TextCount=2;}; for (int d=0;dinstruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "config cmds:" << newCmd; - } - } - } - newCmd = transCmd(instrcutLibbiz->instruct_read,sLabel,dataRes[i]); - if(newCmd!=""){ - qDebug() << "query cmds:" << newCmd; + SendDevice(instrcutLibbiz,&deviceEngine); + sRet=ReadDevice(instrcutLibbiz,&deviceEngine); + if(sParam=="输入电阻"){ + BaseCommonApi::SaveLogInfo(1,QString("数字万用表控制")); + VisaCommonEngine tempEngine=getVisaCommbyRoleName("数字多用表"); //角色 + InstructionLib *instrcutLibNum=getCmdByRoleName("数字多用表",sParam); + sRet=ReadDevice(instrcutLibNum,&tempEngine); + } + if(sParam=="校准信号"){ + idx= getIndexByHeader(constsLable,QStrTranQStrList("项目")); + if(dataRes[i][idx]=="频率"){ + if(!this->showDialog("输入电阻","请接入频率测试线")){continue;} + BaseCommonApi::SaveLogInfo(1,QString("通用计数器控制")); + VisaCommonEngine tempEngine=getVisaCommbyRoleName("通用计数器"); //角色 + InstructionLib *instrcutLibNum=getCmdByRoleName("通用计数器",sParam); + SendDevice(instrcutLibbiz,&deviceEngine); + sRet=ReadDevice(instrcutLibNum,&tempEngine); + } + } + //测试结果单位转换 + if(sRet!=""){ + idx= getIndexByHeader(constsLable,QStrTranQStrList("单位")); + //ValueUnit + if(idx!=-1) + { + ValueUnit=dataRes[i][idx]; + }else + { + QStringList temp; + temp.append("标准值"); + temp.append("标称值"); + int idx= getIndexByHeader(constsLable,temp); + if(idx!=-1) + ItemUnitSplit(dataRes[i][idx],ValueUnit,ValueUnit); - sRet = deviceEngine.queryData(newCmd); - idx= getIndexByHeader(sLabel,QStrTranQStrList("单位")); - //ValueUnit - if(idx!=-1) - { - ValueUnit=dataRes[i][idx]; - }else - { - QStringList temp; - temp.append("标准值"); - temp.append("标称值"); - int idx= getIndexByHeader(sLabel,temp); - if(idx!=-1) - ItemUnitSplit(dataRes[i][idx],ValueUnit,ValueUnit); - - } - dStdValue = transUnit(sRet,ValueUnit); - - } - } - + } + dStdValue = transUnit(sRet,ValueUnit); } - - autoAdujstData(sLabel,i,dStdValue,dataRes); + autoAdujstData(constsLable,i,dStdValue,dataRes); CheckBackColorUpdate(false,i); + closeCmd(); Delay_MSec(2000); + } //CLOSE 被检设备 - 标准设备 - BaseCommonApi::SaveLogInfo(1,QString("CLOSE")); - InstructionLib *Closebiz; - InstructionLib *Closestan; - Closebiz= getCmdByCheckName(0,"CLOSE"); - Closestan= getCmdByCheckName(1,"CLOSE"); - if(Closestan!=nullptr && instrcutLibstan!=nullptr) - { - if(standardEngine.getState()) - { - //读取配置指令 - QStringList sList = Closestan->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - if(newCmd!=""){ - standardEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - } - } - // - if(Closebiz!=nullptr && instrcutLibbiz!=nullptr) - { - if(deviceEngine.getState()) - { - //读取配置指令 - QStringList sList = Closebiz->instruct_config.split(";"); - if(sList.length()>0){ - for (QString& sCmd : sList){ - newCmd = transCmd(sCmd,sLabel,dataRes[i]); - - if(newCmd!=""){ - deviceEngine.sendData(newCmd); - qDebug() << "standard cmds:" << newCmd; - } - } - } - }; - - } } - caliDataList->insert(sLabel,dataRes); + caliDataList->insert(constsLable,dataRes); } + closeDevice(); } } void CheckWindow::Delay_MSec(unsigned int msec) @@ -2065,10 +2176,13 @@ void CheckWindow::on_pushButton_stop_clicked() { + Teststate=SyncRunStatus::Stopped; + if(iEquipType==5){ if(timerChart->isActive()) timerChart->stop(); } + } void CheckWindow::on_pushButton_clicked() @@ -2307,6 +2421,42 @@ } //QWidget::keyPressEvent(ev); } +void CheckWindow::SendDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran){ + //发送仪器 进一步封装 + QString newCmd=""; + if(Visa->getState()){ + if(Inst!=nullptr){ + QStringList sList = Inst->instruct_config.split(";"); + if(sList.length()>0){ + for (QString& sCmd : sList){ + newCmd = transCmd(sCmd,constsLable,constDataRes,IsUnitTran); + if(newCmd!=""){ + QString str=Visa->commType; + Visa->sendData(newCmd); + qDebug() << "config cmds:" << newCmd; + } + } + } + } +} +} +QString CheckWindow::ReadDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran){ + //读取仪器 进一步封装 + QString newCmd=""; + QString result=""; + if(Visa->getState()){ + if(Inst!=nullptr){ + newCmd = transCmd(Inst->instruct_read,constsLable,constDataRes,IsUnitTran); + if(newCmd!=""){ + qDebug() << "query cmds:" << newCmd; + result = Visa->queryData(newCmd); + } + } + } + return result; +} + + void CheckWindow::CreateCharts(){ deleteItem(ui->horizontalLayoutChart); @@ -2545,3 +2695,4 @@ caliDataList->insert(sLabel,dataRes); } } + diff --git a/softwareDirectory/AutoVerScheme/checkwindow.h b/softwareDirectory/AutoVerScheme/checkwindow.h index d559ac9..04f5425 100644 --- a/softwareDirectory/AutoVerScheme/checkwindow.h +++ b/softwareDirectory/AutoVerScheme/checkwindow.h @@ -24,6 +24,7 @@ int type; QString deviceName; QString state; + QString rolenName; VerificationProgramConfigInterface programInterface; QList cmdList; }; @@ -81,6 +82,7 @@ void addGageData(bool bAdd=true); void on_pushButton_next_clicked(); + void onComboBoxCurrTextChanged(QString value,QString device_id,int row); QMap readDataFromFile(QString filePath); void RefreshTime_Slot(); void on_pushButtonGetTemp_clicked(); @@ -88,7 +90,7 @@ private: void getCheckDevice(bool bInit=true); void getCheckMethod(); - void initDeviceInfo(QString sId); + void initDeviceInfo(QList sId); void deleteItem(QLayout *layout); void initCheckTable(int idx); InstructionLib* getCmdByCheckName(int idx,QString name); @@ -119,6 +121,13 @@ QStringList QStrTranQStrList(QString value); void changeDevice(int idx); void keyPressEvent(QKeyEvent *ev); + QString GetdeviceidByRole(QString device_id); + InstructionLib* getCmdByRoleName(QString RoleName,QString name); + VisaCommonEngine getVisaCommbyRoleName(QString RoleName); + QString ReadDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran=false); + void SendDevice(InstructionLib* Inst,VisaCommonEngine* Visa,bool IsUnitTran=false); + void InItcmd(); + void closeCmd(); void CreateCharts(); private: Ui::CheckWindow *ui; @@ -132,6 +141,8 @@ VisaCommonEngine deviceEngine; VisaCommonEngine standardEngine; VisaCommonEngine engine;; + QMap VisaStanEngineList; + QList measureCa3lList; QList measureCalList; SaveDeviceMeasureInfo measureInfo; QMap> *caliDataList; @@ -146,6 +157,7 @@ QMap unitTypeTransList; QMap cmdPlaceHolderList; + QList StandarIdList; QString standardId; int currConnectIdx; QList pageButtons; @@ -159,8 +171,16 @@ QString curDeviceId=""; int curDevciceIdx=-1; int nextGageIndex=-1; + + QList DeviceMeasureEquipmentCatorycatory; + QList RoleList; + + QString constsLable; + QStringList constDataRes; + QChartView *chartView; QTimer* timerChart; + SyncRunStatus Teststate; }; #endif // CHECKWINDOW_H diff --git a/softwareDirectory/AutoVerScheme/checkwindow.ui b/softwareDirectory/AutoVerScheme/checkwindow.ui index d2bfbac..a753c93 100644 --- a/softwareDirectory/AutoVerScheme/checkwindow.ui +++ b/softwareDirectory/AutoVerScheme/checkwindow.ui @@ -939,6 +939,11 @@ 检定有效期 + + + 角色信息 + + @@ -1142,6 +1147,11 @@ + 角色 + + + + 设备名称 @@ -1795,13 +1805,25 @@ + 角色 + + + + Arial + 10 + + + + + 设备名称 - 12 - 75 - true + Arial + 10 + 50 + false @@ -1811,9 +1833,10 @@ - 12 - 75 - true + Arial + 10 + 50 + false @@ -1941,6 +1964,9 @@ true + + color:orange + 出厂编号: @@ -2221,8 +2247,8 @@ showMethod() - 153 - 234 + 726 + 760 884 @@ -2237,8 +2263,8 @@ showCheck() - 1095 - 571 + 1187 + 581 1328 @@ -2253,8 +2279,8 @@ showMethodWidget() - 61 - 91 + 713 + 121 3 @@ -2269,8 +2295,8 @@ showResult() - 55 - 91 + 580 + 121 -1 diff --git a/softwareDirectory/AutoVerScheme/visacommonengine.cpp b/softwareDirectory/AutoVerScheme/visacommonengine.cpp index 39dfed2..e3541d0 100644 --- a/softwareDirectory/AutoVerScheme/visacommonengine.cpp +++ b/softwareDirectory/AutoVerScheme/visacommonengine.cpp @@ -2,10 +2,13 @@ #include -VisaCommonEngine::VisaCommonEngine() +VisaCommonEngine::VisaCommonEngine() : serial(new QSerialPort) { } +VisaCommonEngine::~VisaCommonEngine() +{ +} /*VisaCommonEngine::~VisaCommonEngine() { @@ -167,9 +170,9 @@ QStringList sList = sAddr.split(";"); if(sList.length()==5){ //设置串口名 - serial.setPortName(sList[0]); + serial->setPortName(sList[0]); //设置波特率 - serial.setBaudRate(sList[1].toInt()); + serial->setBaudRate(sList[1].toInt()); //设置奇偶校验 QSerialPort::Parity parity=QSerialPort::NoParity; if(sList[2]=="None") @@ -178,14 +181,14 @@ parity = QSerialPort::OddParity; else if(sList[2]=="Even") parity = QSerialPort::EvenParity; - serial.setParity(parity); + serial->setParity(parity); //设置数据位数 QSerialPort::DataBits bits=QSerialPort::Data7; if(sList[3]=="7") bits=QSerialPort::Data7; else if(sList[3]=="8") bits=QSerialPort::Data8; - serial.setDataBits(bits); + serial->setDataBits(bits); //设置停止位 QSerialPort::StopBits stop =QSerialPort::OneStop; @@ -197,11 +200,11 @@ stop=QSerialPort::TwoStop; else if(sList[4]=="OnePointFive") stop=QSerialPort::OneAndHalfStop; - serial.setStopBits(stop); + serial->setStopBits(stop); //设置流控制 //serial.setFlowControl(QSerialPort::NoFlowControl); //打开串口 - if(serial.open(QIODevice::ReadWrite)){ + if(serial->open(QIODevice::ReadWrite)){ commState = true; return true; } @@ -217,7 +220,7 @@ status = viClose(defaultRM); commState = false; }else{ - serial.close(); + serial->close(); commState = false; } } @@ -241,11 +244,11 @@ } return ""; }else{ - serial.clear(); + serial->clear(); sendData(sCmd); QString strRet; QByteArray buf; - buf = serial.readAll(); + buf = serial->readAll(); if(!buf.isEmpty()) { strRet=QString::fromLatin1(buf); @@ -257,6 +260,7 @@ bool VisaCommonEngine::sendData(QString sCmd) { + QString srr=commType; //strcpy(stringinput, strData.toLatin1().data()); //strcpy(stringinput, "*IDN?\n"); if(commType=="Visa"){ @@ -270,7 +274,7 @@ } return true; }else{ - serial.write(sCmd.toLatin1()); + serial->write(sCmd.toLatin1()); return true; } } diff --git a/softwareDirectory/AutoVerScheme/visacommonengine.h b/softwareDirectory/AutoVerScheme/visacommonengine.h index 15108f7..dabfcad 100644 --- a/softwareDirectory/AutoVerScheme/visacommonengine.h +++ b/softwareDirectory/AutoVerScheme/visacommonengine.h @@ -10,6 +10,7 @@ { public: VisaCommonEngine(); + ~VisaCommonEngine(); //~VisaCommonEngine(); QString queryData(QString sCmd); bool sendData(QString sCmd); @@ -20,6 +21,8 @@ QStringList getVisaAddrs(); QStringList getSerialAddrs(); QString getdeviceIdninfo(QString sAddr); + QString commType="Visa"; + QString role; private: //visa ViSession defaultRM; @@ -30,10 +33,10 @@ unsigned char buffer[100]; char stringinput[512]; ViConstRsrc remoteAddr=""; - QString commType="Visa"; + QByteArray utf8Bytes; bool commState=false; - QSerialPort serial; + QSerialPort *serial; };