import QtQuick 2.11 import QtQuick.Controls 1.4 import QtQuick.Layouts 1.14 import "modbus.js" as ModbusJs Item { Loader{ id:loader anchors.fill: parent anchors.margins: 5 } function show(){ if(loader.sourceComponent === null){ loader.sourceComponent = componet } loader.item.show() } function exit(){ if(loader.sourceComponent !== null){ loader.item.exit() } } Component{ id:componet GroupBox{ id:groupbox x:width title: "人工模式" property int pressureCnt:0 property var dataArray: [] property int curveDisplayAxisxMax:60 property bool finish function checkButtonClick(){ console.log("自检启动") sensorTimer.running = false var ret = ModbusJs.checkModebusDevice(controlSerial,sensorSerial,log) if(ret === false){ log.show("自检错误") sensorTimer.running = false } else{ log.show("自检正常") sensorTimer.running = true } } function closeButtonClick(){ ModbusJs.closeAllValve(controlSerial) console.log("关闭所有阀门") groupbox.finish = false comboBox1.currentIndex = 0 comboBox2.currentIndex = 0 comboBox3.currentIndex = 0 comboBox4.currentIndex = 0 comboBox5.currentIndex = 0 comboBox6.currentIndex = 0 comboBox7.currentIndex = 0 comboBox8.currentIndex = 0 groupbox.finish = true } Timer{ id:componetTimer repeat: false interval: 1000 onTriggered: { groupbox.finish = true comboBox1.currentIndex = 0 comboBox2.currentIndex = 0 comboBox3.currentIndex = 0 comboBox4.currentIndex = 0 comboBox5.currentIndex = 0 comboBox6.currentIndex = 0 comboBox7.currentIndex = 0 comboBox8.currentIndex = 0 var ret = ModbusJs.checkModebusDevice(controlSerial,sensorSerial,log) if(ret === false) log.show("自检错误") else{ log.show("自检正常") ModbusJs.closeAllValve(controlSerial) sensorTimer.running = true } //1000 会造成启动慢 延迟赋值 gauge.maximumValue = 1 } } function pressureDisplayInput(number){ pressureCnt++ if(pressureCnt <= (curveDisplayAxisxMax+1)){ dataArray.push(number) curveDisplay.spline.append(pressureCnt-1,number) } else{ dataArray.push(number) dataArray.shift() curveDisplay.spline.clear() for(var i=0; i<(curveDisplayAxisxMax+1); i++){ curveDisplay.spline.append(i,dataArray[i]) } } gauge.value = parseInt(number) gauge.realValue = number } Timer{ id:sensorTimer repeat: true triggeredOnStart: false interval: 1000 onTriggered: { if(comboBox7.currentText === "低压"){ var obj = ModbusJs.lowPressureSensorReadReq(sensorSerial) if(obj.ret === false){ log.show(comboBox7.currentText+"传感器"+"通讯错误") } else{ pressureDisplayInput(obj.pressureNumber) } } else if(comboBox7.currentText === "高压"){ obj = ModbusJs.highPressureSensorReadReq(sensorSerial) if(obj.ret === false){ log.show(comboBox7.currentText+"传感器"+"通讯错误") } else{ pressureDisplayInput(obj.pressureNumber) } } else if(comboBox7.currentText === "负压"){ obj = ModbusJs.negativePressureSensorReadReq(sensorSerial) if(obj.ret === false){ log.show(comboBox7.currentText+"传感器"+"通讯错误") } else{ pressureDisplayInput(obj.pressureNumber) } } if(comboBox7.currentText !== "关闭"){ if(recordButton.text === "停止压力记录" && obj.ret === true ){ var tab = tabview.getTab(tabview.currentIndex) var modelData = tab.item.modelData var table={} table.pressure=obj.pressureNumber modelData.append(table) } } } } function show(){ animationShow.running = true componetTimer.start() } function exit(){ sensorTimer.stop() sensorTimer.running = false animationExit.running = true groupbox.finish = false ModbusJs.closeAllValve(controlSerial) } //加载任务动画效果 NumberAnimation { id: animationShow target: groupbox property: "x" from: groupbox.x to: 0 duration: 500 } NumberAnimation { id: animationExit target: groupbox property: "x" from: groupbox.x to: 1024 duration: 500 } Column{ anchors.left: parent.left anchors.leftMargin: 2 anchors.top: parent.top anchors.topMargin: 10 spacing: 0 Rectangle{ width: 980 height: 75 color: "white" radius: 6 GridLayout { id : grid anchors.fill: parent anchors.margins: 10 columns: 6 rows: 2 columnSpacing: 10 rowSpacing: 8 Row{ spacing: 5 Text { anchors.verticalCenter: parent.verticalCenter text: qsTr("测试口:") font.bold: true font.pixelSize: 13 } UserComboBox{ id:comboBox1 anchors.verticalCenter: parent.verticalCenter width: 145 height: 25 bgColor:"#D2D5D9" model: ["关闭所有测试口","呼吸阀正压测试口","安全阀测试口", "人口盖测试口","罐体耐压测试口","真空阀测试口","呼吸阀负压测试口"] onActivated: { if(groupbox.finish === false) return switch(currentText){ case "关闭所有测试口": ModbusJs.turnOffAllTestIO(controlSerial) break case "呼吸阀正压测试口": ModbusJs.turnOffAllTestIO(controlSerial) ModbusJs.pbreathValveTestIo(controlSerial,true) break case "安全阀测试口": ModbusJs.turnOffAllTestIO(controlSerial) ModbusJs.safeValveTestIo(controlSerial,true) break case "人口盖测试口": ModbusJs.turnOffAllTestIO(controlSerial) ModbusJs.peopleCoverHoleValveTestIO(controlSerial,true) break case "罐体耐压测试口": ModbusJs.turnOffAllTestIO(controlSerial) ModbusJs.tankValveTestIO(controlSerial,true) break case "真空阀测试口": ModbusJs.turnOffAllTestIO(controlSerial) ModbusJs.vacuoValveTestIO(controlSerial,true) break case "呼吸阀负压测试口": ModbusJs.turnOffAllTestIO(controlSerial) ModbusJs.nbreathValveTestIo(controlSerial,true) break } } } } Row{ spacing: 5 Text { anchors.verticalCenter: parent.verticalCenter text: qsTr("正压罐进气阀:") font.bold: true font.pixelSize: 13 } UserComboBox{ id:comboBox2 anchors.verticalCenter: parent.verticalCenter width: 50 height: 25 bgColor:"#D2D5D9" model: ["关","开"] onActivated: { if(groupbox.finish === false) return if(currentText === "关"){ ModbusJs.positivePressureTankInputCtrl(controlSerial,false) } else{ ModbusJs.positivePressureTankInputCtrl(controlSerial,true) } } } } Row{ spacing: 5 Text { anchors.verticalCenter: parent.verticalCenter text: qsTr("正压罐泄气阀:") font.bold: true font.pixelSize: 13 } UserComboBox{ id:comboBox3 anchors.verticalCenter: parent.verticalCenter width: 50 height: 25 bgColor:"#D2D5D9" model: ["关","开"] onActivated: { if(groupbox.finish === false) return if(currentText === "关"){ ModbusJs.positivePressureTankOutputCtrl(controlSerial,false) } else{ ModbusJs.positivePressureTankOutputCtrl(controlSerial,true) } } } } Row{ spacing: 5 Text { anchors.verticalCenter: parent.verticalCenter text: qsTr("负压罐进气阀:") font.bold: true font.pixelSize: 13 } UserComboBox{ id:comboBox4 anchors.verticalCenter: parent.verticalCenter width: 50 height: 25 bgColor:"#D2D5D9" model: ["关","开"] onActivated: { if(groupbox.finish === false) return if(currentText === "关"){ ModbusJs.negativePressureTankInputCtrl(controlSerial,false) } else{ ModbusJs.negativePressureTankInputCtrl(controlSerial,true) } } } } Row{ spacing: 5 Text { anchors.verticalCenter: parent.verticalCenter text: qsTr("负压罐泄气阀:") font.bold: true font.pixelSize: 13 } UserComboBox{ id:comboBox5 anchors.verticalCenter: parent.verticalCenter width: 50 height: 25 bgColor:"#D2D5D9" model: ["关","开"] onActivated: { if(groupbox.finish === false) return if(currentText === "关"){ ModbusJs.negativePressureTankOutputCtrl(controlSerial,false) } else{ ModbusJs.negativePressureTankOutputCtrl(controlSerial,true) } } } } Row{ spacing: 5 Text { anchors.verticalCenter: parent.verticalCenter text: qsTr("负压泵:") font.bold: true font.pixelSize: 13 } UserComboBox{ id:comboBox6 anchors.verticalCenter: parent.verticalCenter width: 50 height: 25 bgColor:"#D2D5D9" model: ["关","开"] onActivated: { if(groupbox.finish === false) return if(currentText === "关"){ ModbusJs.negativePumpPowerCtrl(controlSerial,false) } else{ ModbusJs.negativePumpPowerCtrl(controlSerial,true) } } } } Row{ spacing: 5 Text { anchors.verticalCenter: parent.verticalCenter text: qsTr("压力传感器:") font.bold: true font.pixelSize: 13 } UserComboBox{ id:comboBox7 signal textChange(var currentText) anchors.verticalCenter: parent.verticalCenter width: 118 height: 25 bgColor:"#D2D5D9" model: ["关闭","高压","低压","负压"] onActivated: { if(groupbox.finish === false){ gauge.maximumValue = 1 return } comboBox7Timer.restart() } Timer{ id:comboBox7Timer repeat: false interval: 500 onTriggered: { comboBox7.comboBox7fun(comboBox7.currentText) } } function comboBox7fun(currentText){ if(currentText === "关闭"){ gauge.maximumValue = 1 gauge.tickmarkStepSize = 5 gauge.labelStepSize = 5 ModbusJs.pressureSensorCtrl(controlSerial,"关闭") } if(currentText === "低压"){ gauge.maximumValue = 50 gauge.tickmarkStepSize = 5 gauge.labelStepSize = 5 ModbusJs.pressureSensorCtrl(controlSerial,"低压") } else if(currentText === "高压"){ gauge.maximumValue = 1000 gauge.tickmarkStepSize = 100 gauge.labelStepSize = 100 ModbusJs.pressureSensorCtrl(controlSerial,"高压") } else{ gauge.maximumValue = 5 gauge.tickmarkStepSize = 5 gauge.labelStepSize = 5 ModbusJs.pressureSensorCtrl(controlSerial,"负压") } } } } Row{ spacing: 5 Text { anchors.verticalCenter: parent.verticalCenter text: qsTr("粗调开关:") font.bold: true font.pixelSize: 13 } UserComboBox{ id:comboBox8 anchors.verticalCenter: parent.verticalCenter width: 76 height: 25 bgColor:"#D2D5D9" model: ["关","开"] onActivated: { if(groupbox.finish === false) return if(currentText === "关"){ ModbusJs.bigTuningValveControl(controlSerial,false) } else{ ModbusJs.bigTuningValveControl(controlSerial,true) } } } } UserButton{ id:recordButton width: 100 height: 25 checkable: true text:checked === false ?"开启压力记录":"停止压力记录" onTextChanged: { if(text === "停止压力记录"){ var tab = tabview.getTab(tabview.currentIndex) var modelData = tab.item.modelData modelData.clear() } } } UserButton{ id:checkButton width: 100 height: 25 checkable: false text:"自检" signal userClick() onPressed: { bgcolor="#0B7FFF" } onReleased: { bgcolor = "black" } onClicked: { userClick() } Component.onCompleted: { userClick.connect(groupbox.checkButtonClick) } } UserButton{ id:closeButton width: 100 height: 25 checkable: false text:"关闭全部阀门" signal userClick() onPressed: { bgcolor="#0B7FFF" } onReleased: { bgcolor = "black" } onClicked: { userClick() } Component.onCompleted: { userClick.connect(groupbox.closeButtonClick) } } } } Row{ x:-10 CurveDisplay{ id:curveDisplay anchors.verticalCenter: parent.verticalCenter width: 600 height: 300 axisxMax:curveDisplayAxisxMax axisxMin:0 axisyMax:{ if(comboBox7.currentText === "低压") return 50 if(comboBox7.currentText === "高压") return 1000 if(comboBox7.currentText === "负压") return 5 return 1 } axisyMin:{ if(comboBox7.currentText === "负压") return -10 return 0 } name:"横轴时间(秒) 纵轴压力(kPa)" } Rectangle{ width: (300-18)*0.75 height: 300-18 color: "white" radius: 6 anchors.verticalCenter: parent.verticalCenter Gauge { id:gauge width: parent.width height: parent.width anchors.centerIn: parent value: 0.0 //realValue:0.0 maximumValue: 1 minimumValue: { if(comboBox7.currentText === "负压") return -10 return 0 } // tickmarkStepSize:{ // if(comboBox7.currentText === "高压") // return 100 // return 5 // } // labelStepSize:{ // if(comboBox7.currentText === "高压") // return 100 // return 5 // } Behavior on value { NumberAnimation { duration: 1000 }} } } Item { width: 338-150 height: 300 anchors.verticalCenter: parent.verticalCenter Rectangle{ anchors.fill: parent anchors.margins: 10 color: "white" radius: 6 Knob{ anchors.fill: parent } } } } //记录 Row{ id:record spacing: 10 property int tableWidth:980 function dataRandomSet(modelData,max){ for(var i=0;i