123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725 |
- 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<max; i++){
- var number= Math.round(Math.random()*100)
- number *= 10
- var obj={}
- obj.pressure=number
- modelData.append(obj)
- }
- }
- TabView {
- id:tabview
- width: record.tableWidth
- height: 265
- GraphButton{
- id:graphButton
- x:870
- y:-25
- width: 48
- height: 24
- onUserClicked: {
- var tab = tabview.getTab(tabview.currentIndex)
- var axisxMax = tab.item.modelData.count
- switch(comboBox7.currentText){
- case"低压":
- var axisyMax = 50
- var axisyMin = 0
- break
- case "高压":
- axisyMax = 1000
- axisyMin = 0
- break
- case "负压":
- axisyMax = 50
- axisyMin = -10
- }
- generateCurve.show(0,axisxMax,axisyMin,axisyMax,tab.item.modelData,tab.title,"横轴时间(秒) 纵轴压力(kPa)")
- }
- }
- Tab {
- title: "压力记录"
- active: true
- RecordTable{
- // Component.onCompleted: {
- // record.dataRandomSet(modelData,10)
- // }
- }
- }
- }
- }
- }
- }
- }
- }
|