ManualMode.qml 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. import QtQuick 2.11
  2. import QtQuick.Controls 1.4
  3. import QtQuick.Layouts 1.14
  4. import "modbus.js" as ModbusJs
  5. Item {
  6. Loader{
  7. id:loader
  8. anchors.fill: parent
  9. anchors.margins: 5
  10. }
  11. function show(){
  12. if(loader.sourceComponent === null){
  13. loader.sourceComponent = componet
  14. }
  15. loader.item.show()
  16. }
  17. function exit(){
  18. if(loader.sourceComponent !== null){
  19. loader.item.exit()
  20. }
  21. }
  22. Component{
  23. id:componet
  24. GroupBox{
  25. id:groupbox
  26. x:width
  27. title: "人工模式"
  28. property int pressureCnt:0
  29. property var dataArray: []
  30. property int curveDisplayAxisxMax:60
  31. property bool finish
  32. function checkButtonClick(){
  33. console.log("自检启动")
  34. sensorTimer.running = false
  35. var ret = ModbusJs.checkModebusDevice(controlSerial,sensorSerial,log)
  36. if(ret === false){
  37. log.show("自检错误")
  38. sensorTimer.running = false
  39. }
  40. else{
  41. log.show("自检正常")
  42. sensorTimer.running = true
  43. }
  44. }
  45. function closeButtonClick(){
  46. ModbusJs.closeAllValve(controlSerial)
  47. console.log("关闭所有阀门")
  48. groupbox.finish = false
  49. comboBox1.currentIndex = 0
  50. comboBox2.currentIndex = 0
  51. comboBox3.currentIndex = 0
  52. comboBox4.currentIndex = 0
  53. comboBox5.currentIndex = 0
  54. comboBox6.currentIndex = 0
  55. comboBox7.currentIndex = 0
  56. comboBox8.currentIndex = 0
  57. groupbox.finish = true
  58. }
  59. Timer{
  60. id:componetTimer
  61. repeat: false
  62. interval: 1000
  63. onTriggered: {
  64. groupbox.finish = true
  65. comboBox1.currentIndex = 0
  66. comboBox2.currentIndex = 0
  67. comboBox3.currentIndex = 0
  68. comboBox4.currentIndex = 0
  69. comboBox5.currentIndex = 0
  70. comboBox6.currentIndex = 0
  71. comboBox7.currentIndex = 0
  72. comboBox8.currentIndex = 0
  73. var ret = ModbusJs.checkModebusDevice(controlSerial,sensorSerial,log)
  74. if(ret === false)
  75. log.show("自检错误")
  76. else{
  77. log.show("自检正常")
  78. ModbusJs.closeAllValve(controlSerial)
  79. sensorTimer.running = true
  80. }
  81. //1000 会造成启动慢 延迟赋值
  82. gauge.maximumValue = 1
  83. }
  84. }
  85. function pressureDisplayInput(number){
  86. pressureCnt++
  87. if(pressureCnt <= (curveDisplayAxisxMax+1)){
  88. dataArray.push(number)
  89. curveDisplay.spline.append(pressureCnt-1,number)
  90. }
  91. else{
  92. dataArray.push(number)
  93. dataArray.shift()
  94. curveDisplay.spline.clear()
  95. for(var i=0; i<(curveDisplayAxisxMax+1); i++){
  96. curveDisplay.spline.append(i,dataArray[i])
  97. }
  98. }
  99. gauge.value = parseInt(number)
  100. gauge.realValue = number
  101. }
  102. Timer{
  103. id:sensorTimer
  104. repeat: true
  105. triggeredOnStart: false
  106. interval: 1000
  107. onTriggered: {
  108. if(comboBox7.currentText === "低压"){
  109. var obj = ModbusJs.lowPressureSensorReadReq(sensorSerial)
  110. if(obj.ret === false){
  111. log.show(comboBox7.currentText+"传感器"+"通讯错误")
  112. }
  113. else{
  114. pressureDisplayInput(obj.pressureNumber)
  115. }
  116. }
  117. else if(comboBox7.currentText === "高压"){
  118. obj = ModbusJs.highPressureSensorReadReq(sensorSerial)
  119. if(obj.ret === false){
  120. log.show(comboBox7.currentText+"传感器"+"通讯错误")
  121. }
  122. else{
  123. pressureDisplayInput(obj.pressureNumber)
  124. }
  125. }
  126. else if(comboBox7.currentText === "负压"){
  127. obj = ModbusJs.negativePressureSensorReadReq(sensorSerial)
  128. if(obj.ret === false){
  129. log.show(comboBox7.currentText+"传感器"+"通讯错误")
  130. }
  131. else{
  132. pressureDisplayInput(obj.pressureNumber)
  133. }
  134. }
  135. if(comboBox7.currentText !== "关闭"){
  136. if(recordButton.text === "停止压力记录" && obj.ret === true ){
  137. var tab = tabview.getTab(tabview.currentIndex)
  138. var modelData = tab.item.modelData
  139. var table={}
  140. table.pressure=obj.pressureNumber
  141. modelData.append(table)
  142. }
  143. }
  144. }
  145. }
  146. function show(){
  147. animationShow.running = true
  148. componetTimer.start()
  149. }
  150. function exit(){
  151. sensorTimer.stop()
  152. sensorTimer.running = false
  153. animationExit.running = true
  154. groupbox.finish = false
  155. ModbusJs.closeAllValve(controlSerial)
  156. }
  157. //加载任务动画效果
  158. NumberAnimation {
  159. id: animationShow
  160. target: groupbox
  161. property: "x"
  162. from: groupbox.x
  163. to: 0
  164. duration: 500
  165. }
  166. NumberAnimation {
  167. id: animationExit
  168. target: groupbox
  169. property: "x"
  170. from: groupbox.x
  171. to: 1024
  172. duration: 500
  173. }
  174. Column{
  175. anchors.left: parent.left
  176. anchors.leftMargin: 2
  177. anchors.top: parent.top
  178. anchors.topMargin: 10
  179. spacing: 0
  180. Rectangle{
  181. width: 980
  182. height: 75
  183. color: "white"
  184. radius: 6
  185. GridLayout {
  186. id : grid
  187. anchors.fill: parent
  188. anchors.margins: 10
  189. columns: 6
  190. rows: 2
  191. columnSpacing: 10
  192. rowSpacing: 8
  193. Row{
  194. spacing: 5
  195. Text {
  196. anchors.verticalCenter: parent.verticalCenter
  197. text: qsTr("测试口:")
  198. font.bold: true
  199. font.pixelSize: 13
  200. }
  201. UserComboBox{
  202. id:comboBox1
  203. anchors.verticalCenter: parent.verticalCenter
  204. width: 145
  205. height: 25
  206. bgColor:"#D2D5D9"
  207. model: ["关闭所有测试口","呼吸阀正压测试口","安全阀测试口", "人口盖测试口","罐体耐压测试口","真空阀测试口","呼吸阀负压测试口"]
  208. onActivated: {
  209. if(groupbox.finish === false)
  210. return
  211. switch(currentText){
  212. case "关闭所有测试口":
  213. ModbusJs.turnOffAllTestIO(controlSerial)
  214. break
  215. case "呼吸阀正压测试口":
  216. ModbusJs.turnOffAllTestIO(controlSerial)
  217. ModbusJs.pbreathValveTestIo(controlSerial,true)
  218. break
  219. case "安全阀测试口":
  220. ModbusJs.turnOffAllTestIO(controlSerial)
  221. ModbusJs.safeValveTestIo(controlSerial,true)
  222. break
  223. case "人口盖测试口":
  224. ModbusJs.turnOffAllTestIO(controlSerial)
  225. ModbusJs.peopleCoverHoleValveTestIO(controlSerial,true)
  226. break
  227. case "罐体耐压测试口":
  228. ModbusJs.turnOffAllTestIO(controlSerial)
  229. ModbusJs.tankValveTestIO(controlSerial,true)
  230. break
  231. case "真空阀测试口":
  232. ModbusJs.turnOffAllTestIO(controlSerial)
  233. ModbusJs.vacuoValveTestIO(controlSerial,true)
  234. break
  235. case "呼吸阀负压测试口":
  236. ModbusJs.turnOffAllTestIO(controlSerial)
  237. ModbusJs.nbreathValveTestIo(controlSerial,true)
  238. break
  239. }
  240. }
  241. }
  242. }
  243. Row{
  244. spacing: 5
  245. Text {
  246. anchors.verticalCenter: parent.verticalCenter
  247. text: qsTr("正压罐进气阀:")
  248. font.bold: true
  249. font.pixelSize: 13
  250. }
  251. UserComboBox{
  252. id:comboBox2
  253. anchors.verticalCenter: parent.verticalCenter
  254. width: 50
  255. height: 25
  256. bgColor:"#D2D5D9"
  257. model: ["关","开"]
  258. onActivated: {
  259. if(groupbox.finish === false)
  260. return
  261. if(currentText === "关"){
  262. ModbusJs.positivePressureTankInputCtrl(controlSerial,false)
  263. }
  264. else{
  265. ModbusJs.positivePressureTankInputCtrl(controlSerial,true)
  266. }
  267. }
  268. }
  269. }
  270. Row{
  271. spacing: 5
  272. Text {
  273. anchors.verticalCenter: parent.verticalCenter
  274. text: qsTr("正压罐泄气阀:")
  275. font.bold: true
  276. font.pixelSize: 13
  277. }
  278. UserComboBox{
  279. id:comboBox3
  280. anchors.verticalCenter: parent.verticalCenter
  281. width: 50
  282. height: 25
  283. bgColor:"#D2D5D9"
  284. model: ["关","开"]
  285. onActivated: {
  286. if(groupbox.finish === false)
  287. return
  288. if(currentText === "关"){
  289. ModbusJs.positivePressureTankOutputCtrl(controlSerial,false)
  290. }
  291. else{
  292. ModbusJs.positivePressureTankOutputCtrl(controlSerial,true)
  293. }
  294. }
  295. }
  296. }
  297. Row{
  298. spacing: 5
  299. Text {
  300. anchors.verticalCenter: parent.verticalCenter
  301. text: qsTr("负压罐进气阀:")
  302. font.bold: true
  303. font.pixelSize: 13
  304. }
  305. UserComboBox{
  306. id:comboBox4
  307. anchors.verticalCenter: parent.verticalCenter
  308. width: 50
  309. height: 25
  310. bgColor:"#D2D5D9"
  311. model: ["关","开"]
  312. onActivated: {
  313. if(groupbox.finish === false)
  314. return
  315. if(currentText === "关"){
  316. ModbusJs.negativePressureTankInputCtrl(controlSerial,false)
  317. }
  318. else{
  319. ModbusJs.negativePressureTankInputCtrl(controlSerial,true)
  320. }
  321. }
  322. }
  323. }
  324. Row{
  325. spacing: 5
  326. Text {
  327. anchors.verticalCenter: parent.verticalCenter
  328. text: qsTr("负压罐泄气阀:")
  329. font.bold: true
  330. font.pixelSize: 13
  331. }
  332. UserComboBox{
  333. id:comboBox5
  334. anchors.verticalCenter: parent.verticalCenter
  335. width: 50
  336. height: 25
  337. bgColor:"#D2D5D9"
  338. model: ["关","开"]
  339. onActivated: {
  340. if(groupbox.finish === false)
  341. return
  342. if(currentText === "关"){
  343. ModbusJs.negativePressureTankOutputCtrl(controlSerial,false)
  344. }
  345. else{
  346. ModbusJs.negativePressureTankOutputCtrl(controlSerial,true)
  347. }
  348. }
  349. }
  350. }
  351. Row{
  352. spacing: 5
  353. Text {
  354. anchors.verticalCenter: parent.verticalCenter
  355. text: qsTr("负压泵:")
  356. font.bold: true
  357. font.pixelSize: 13
  358. }
  359. UserComboBox{
  360. id:comboBox6
  361. anchors.verticalCenter: parent.verticalCenter
  362. width: 50
  363. height: 25
  364. bgColor:"#D2D5D9"
  365. model: ["关","开"]
  366. onActivated: {
  367. if(groupbox.finish === false)
  368. return
  369. if(currentText === "关"){
  370. ModbusJs.negativePumpPowerCtrl(controlSerial,false)
  371. }
  372. else{
  373. ModbusJs.negativePumpPowerCtrl(controlSerial,true)
  374. }
  375. }
  376. }
  377. }
  378. Row{
  379. spacing: 5
  380. Text {
  381. anchors.verticalCenter: parent.verticalCenter
  382. text: qsTr("压力传感器:")
  383. font.bold: true
  384. font.pixelSize: 13
  385. }
  386. UserComboBox{
  387. id:comboBox7
  388. signal textChange(var currentText)
  389. anchors.verticalCenter: parent.verticalCenter
  390. width: 118
  391. height: 25
  392. bgColor:"#D2D5D9"
  393. model: ["关闭","高压","低压","负压"]
  394. onActivated: {
  395. if(groupbox.finish === false){
  396. gauge.maximumValue = 1
  397. return
  398. }
  399. comboBox7Timer.restart()
  400. }
  401. Timer{
  402. id:comboBox7Timer
  403. repeat: false
  404. interval: 500
  405. onTriggered: {
  406. comboBox7.comboBox7fun(comboBox7.currentText)
  407. }
  408. }
  409. function comboBox7fun(currentText){
  410. if(currentText === "关闭"){
  411. gauge.maximumValue = 1
  412. gauge.tickmarkStepSize = 5
  413. gauge.labelStepSize = 5
  414. ModbusJs.pressureSensorCtrl(controlSerial,"关闭")
  415. }
  416. if(currentText === "低压"){
  417. gauge.maximumValue = 50
  418. gauge.tickmarkStepSize = 5
  419. gauge.labelStepSize = 5
  420. ModbusJs.pressureSensorCtrl(controlSerial,"低压")
  421. }
  422. else if(currentText === "高压"){
  423. gauge.maximumValue = 1000
  424. gauge.tickmarkStepSize = 100
  425. gauge.labelStepSize = 100
  426. ModbusJs.pressureSensorCtrl(controlSerial,"高压")
  427. }
  428. else{
  429. gauge.maximumValue = 5
  430. gauge.tickmarkStepSize = 5
  431. gauge.labelStepSize = 5
  432. ModbusJs.pressureSensorCtrl(controlSerial,"负压")
  433. }
  434. }
  435. }
  436. }
  437. Row{
  438. spacing: 5
  439. Text {
  440. anchors.verticalCenter: parent.verticalCenter
  441. text: qsTr("粗调开关:")
  442. font.bold: true
  443. font.pixelSize: 13
  444. }
  445. UserComboBox{
  446. id:comboBox8
  447. anchors.verticalCenter: parent.verticalCenter
  448. width: 76
  449. height: 25
  450. bgColor:"#D2D5D9"
  451. model: ["关","开"]
  452. onActivated: {
  453. if(groupbox.finish === false)
  454. return
  455. if(currentText === "关"){
  456. ModbusJs.bigTuningValveControl(controlSerial,false)
  457. }
  458. else{
  459. ModbusJs.bigTuningValveControl(controlSerial,true)
  460. }
  461. }
  462. }
  463. }
  464. UserButton{
  465. id:recordButton
  466. width: 100
  467. height: 25
  468. checkable: true
  469. text:checked === false ?"开启压力记录":"停止压力记录"
  470. onTextChanged: {
  471. if(text === "停止压力记录"){
  472. var tab = tabview.getTab(tabview.currentIndex)
  473. var modelData = tab.item.modelData
  474. modelData.clear()
  475. }
  476. }
  477. }
  478. UserButton{
  479. id:checkButton
  480. width: 100
  481. height: 25
  482. checkable: false
  483. text:"自检"
  484. signal userClick()
  485. onPressed: {
  486. bgcolor="#0B7FFF"
  487. }
  488. onReleased: {
  489. bgcolor = "black"
  490. }
  491. onClicked: {
  492. userClick()
  493. }
  494. Component.onCompleted: {
  495. userClick.connect(groupbox.checkButtonClick)
  496. }
  497. }
  498. UserButton{
  499. id:closeButton
  500. width: 100
  501. height: 25
  502. checkable: false
  503. text:"关闭全部阀门"
  504. signal userClick()
  505. onPressed: {
  506. bgcolor="#0B7FFF"
  507. }
  508. onReleased: {
  509. bgcolor = "black"
  510. }
  511. onClicked: {
  512. userClick()
  513. }
  514. Component.onCompleted: {
  515. userClick.connect(groupbox.closeButtonClick)
  516. }
  517. }
  518. }
  519. }
  520. Row{
  521. x:-10
  522. CurveDisplay{
  523. id:curveDisplay
  524. anchors.verticalCenter: parent.verticalCenter
  525. width: 600
  526. height: 300
  527. axisxMax:curveDisplayAxisxMax
  528. axisxMin:0
  529. axisyMax:{
  530. if(comboBox7.currentText === "低压")
  531. return 50
  532. if(comboBox7.currentText === "高压")
  533. return 1000
  534. if(comboBox7.currentText === "负压")
  535. return 5
  536. return 1
  537. }
  538. axisyMin:{
  539. if(comboBox7.currentText === "负压")
  540. return -10
  541. return 0
  542. }
  543. name:"横轴时间(秒) 纵轴压力(kPa)"
  544. }
  545. Rectangle{
  546. width: (300-18)*0.75
  547. height: 300-18
  548. color: "white"
  549. radius: 6
  550. anchors.verticalCenter: parent.verticalCenter
  551. Gauge {
  552. id:gauge
  553. width: parent.width
  554. height: parent.width
  555. anchors.centerIn: parent
  556. value: 0.0
  557. //realValue:0.0
  558. maximumValue: 1
  559. minimumValue: {
  560. if(comboBox7.currentText === "负压")
  561. return -10
  562. return 0
  563. }
  564. // tickmarkStepSize:{
  565. // if(comboBox7.currentText === "高压")
  566. // return 100
  567. // return 5
  568. // }
  569. // labelStepSize:{
  570. // if(comboBox7.currentText === "高压")
  571. // return 100
  572. // return 5
  573. // }
  574. Behavior on value { NumberAnimation { duration: 1000 }}
  575. }
  576. }
  577. Item {
  578. width: 338-150
  579. height: 300
  580. anchors.verticalCenter: parent.verticalCenter
  581. Rectangle{
  582. anchors.fill: parent
  583. anchors.margins: 10
  584. color: "white"
  585. radius: 6
  586. Knob{
  587. anchors.fill: parent
  588. }
  589. }
  590. }
  591. }
  592. //记录
  593. Row{
  594. id:record
  595. spacing: 10
  596. property int tableWidth:980
  597. function dataRandomSet(modelData,max){
  598. for(var i=0;i<max; i++){
  599. var number= Math.round(Math.random()*100)
  600. number *= 10
  601. var obj={}
  602. obj.pressure=number
  603. modelData.append(obj)
  604. }
  605. }
  606. TabView {
  607. id:tabview
  608. width: record.tableWidth
  609. height: 265
  610. GraphButton{
  611. id:graphButton
  612. x:870
  613. y:-25
  614. width: 48
  615. height: 24
  616. onUserClicked: {
  617. var tab = tabview.getTab(tabview.currentIndex)
  618. var axisxMax = tab.item.modelData.count
  619. switch(comboBox7.currentText){
  620. case"低压":
  621. var axisyMax = 50
  622. var axisyMin = 0
  623. break
  624. case "高压":
  625. axisyMax = 1000
  626. axisyMin = 0
  627. break
  628. case "负压":
  629. axisyMax = 50
  630. axisyMin = -10
  631. }
  632. generateCurve.show(0,axisxMax,axisyMin,axisyMax,tab.item.modelData,tab.title,"横轴时间(秒) 纵轴压力(kPa)")
  633. }
  634. }
  635. Tab {
  636. title: "压力记录"
  637. active: true
  638. RecordTable{
  639. // Component.onCompleted: {
  640. // record.dataRandomSet(modelData,10)
  641. // }
  642. }
  643. }
  644. }
  645. }
  646. }
  647. }
  648. }
  649. }