PageTest.qml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. import QtQuick 2.15
  2. import QtQuick.Layouts 1.3
  3. import QtQuick.Controls 2.14
  4. import QtQuick.Controls.Styles 1.2
  5. import TService 1.0
  6. Item{
  7. id: root
  8. //anchors.fill: parent
  9. //width:1024
  10. //height: 768
  11. //anchors.centerIn: parent
  12. property var pagetype:rootitem.Page_Type_Testing
  13. property string title_str:"手动测试"
  14. property double pressvalue: 1.22
  15. property bool bSelfTest_Started: false
  16. property string selfTest_State_str:""
  17. property string selfTest_Result_str:""
  18. function show_pressure(pressure_str){
  19. lcd_pressure.text = pressure_str;
  20. }
  21. function show_selftestState(str){
  22. selfTest_State_str = str
  23. }
  24. function show_selftestResult(str){
  25. selfTest_Result_str = str
  26. }
  27. function selftestStop(){
  28. var ret1 = testService.tstop(0);
  29. if(ret1){
  30. bSelfTest_Started = false;
  31. //selftest_result.text = ""
  32. selftest_button.text = "开始"
  33. readbutton.enabled = true;
  34. adjustbutton.enabled = true;
  35. //timer.stop()
  36. }
  37. }
  38. // Component{
  39. // id:componet
  40. DynamicGroupBox{
  41. id:groupbox
  42. //x:width
  43. //x:0
  44. anchors.centerIn: parent
  45. anchors.fill: parent
  46. title: title_str
  47. Column{
  48. spacing: 10
  49. anchors.centerIn: parent
  50. DynamicGroupBox{
  51. id:relays_control
  52. title: "继电器控制"
  53. width: 800
  54. height: 300
  55. GridLayout{
  56. anchors.centerIn: parent
  57. columns: 4
  58. rows:3
  59. columnSpacing: 80
  60. rowSpacing: 30
  61. UserSwitch{
  62. id:switch1
  63. text: "粗调阀1关"
  64. onCheckedChanged: {
  65. //console.log("switch 1 onCheckedChanged")
  66. switch1.text = switch1.checked ? "粗调阀1开":"粗调阀1关"
  67. }
  68. onClicked: {
  69. //console.log("switch 1 clicked")
  70. if(switch1.checked){
  71. testService.valve_open(TestService.Valve_ID_ROUGH_0)
  72. }else{
  73. testService.valve_close(TestService.Valve_ID_ROUGH_0)
  74. }
  75. }
  76. }
  77. UserSwitch{
  78. id:switch2
  79. text: "粗调阀2关"
  80. onCheckedChanged: {
  81. switch2.text = switch2.checked ? "粗调阀2开":"粗调阀2关"
  82. }
  83. onClicked: {
  84. if(switch2.checked){
  85. testService.valve_open(TestService.Valve_ID_ROUGH_1)
  86. }else{
  87. testService.valve_close(TestService.Valve_ID_ROUGH_1)
  88. }
  89. }
  90. }
  91. UserSwitch{
  92. id:switch3
  93. text: "粗调阀3关"
  94. onCheckedChanged: {
  95. switch3.text = switch3.checked ? "粗调阀3开":"粗调阀3关"
  96. }
  97. onClicked: {
  98. if(switch3.checked){
  99. testService.valve_open(TestService.Valve_ID_ROUGH_2)
  100. }else{
  101. testService.valve_close(TestService.Valve_ID_ROUGH_2)
  102. }
  103. }
  104. }
  105. UserSwitch{
  106. id:switch4
  107. text: "校准阀 关"
  108. onCheckedChanged: {
  109. switch4.text = switch4.checked ? "校准阀 开":"校准阀 关"
  110. }
  111. onClicked: {
  112. if(switch4.checked){
  113. testService.valve_open(TestService.Valve_ID_CALIBRATION)
  114. }else{
  115. testService.valve_close(TestService.Valve_ID_CALIBRATION)
  116. }
  117. }
  118. }
  119. UserSwitch{
  120. id:switch5
  121. text: "传感阀 关"
  122. onCheckedChanged: {
  123. switch5.text = switch5.checked ? "传感阀 开":"传感阀 关"
  124. }
  125. onClicked: {
  126. if(switch5.checked){
  127. testService.valve_open(TestService.Valve_ID_PRESSURESENSOR)
  128. }else{
  129. testService.valve_close(TestService.Valve_ID_PRESSURESENSOR)
  130. }
  131. }
  132. }
  133. UserSwitch{
  134. id:switch6
  135. text: "真空阀 关"
  136. onCheckedChanged: {
  137. switch6.text = switch6.checked ? "真空阀 开":"真空阀 关"
  138. }
  139. onClicked: {
  140. if(switch6.checked){
  141. testService.valve_open(TestService.Valve_ID_VACUUM)
  142. }else{
  143. testService.valve_close(TestService.Valve_ID_VACUUM)
  144. }
  145. }
  146. }
  147. UserSwitch{
  148. id:switch7
  149. text: "泄气阀 关"
  150. onCheckedChanged: {
  151. switch7.text = switch7.checked ? "泄气阀 开":"泄气阀 关"
  152. }
  153. onClicked: {
  154. if(switch7.checked){
  155. testService.valve_open(TestService.Valve_ID_VENT)
  156. }else{
  157. testService.valve_close(TestService.Valve_ID_VENT)
  158. }
  159. }
  160. }
  161. UserSwitch{
  162. id:switch8
  163. text: "进气阀 关"
  164. onCheckedChanged: {
  165. switch8.text = switch8.checked ? "进气阀 开":"进气阀 关"
  166. }
  167. onClicked: {
  168. if(switch8.checked){
  169. testService.valve_open(TestService.Valve_ID_INTAKE)
  170. }else{
  171. testService.valve_close(TestService.Valve_ID_INTAKE)
  172. }
  173. }
  174. }
  175. UserSwitch{
  176. id:switchall
  177. text: "全关"
  178. onCheckedChanged: {
  179. switchall.text = switch8.checked ? "全关":"全开"
  180. if(switchall.checked){
  181. testService.valve_open(TestService.Valve_ID_All)
  182. switch1.checked=true
  183. switch2.checked=true
  184. switch3.checked=true
  185. switch4.checked=true
  186. switch5.checked=true
  187. switch6.checked=true
  188. switch7.checked=true
  189. switch8.checked=true
  190. }else{
  191. testService.valve_close(TestService.Valve_ID_All)
  192. switch1.checked=false
  193. switch2.checked=false
  194. switch3.checked=false
  195. switch4.checked=false
  196. switch5.checked=false
  197. switch6.checked=false
  198. switch7.checked=false
  199. switch8.checked=false
  200. }
  201. }
  202. }
  203. }
  204. }
  205. DynamicGroupBox{
  206. id:adjust_control
  207. title: "调节阀控制"
  208. width: 800
  209. height: 100
  210. Row{
  211. anchors.verticalCenter: parent.verticalCenter
  212. anchors.left: parent.left
  213. spacing: 20
  214. Text {
  215. id: text1
  216. //anchors.top: parent.top
  217. //anchors.bottom: parent.bottom
  218. //anchors.centerIn: parent
  219. anchors.verticalCenter: parent.verticalCenter
  220. text: qsTr("调压阀:")
  221. font.pixelSize: 20
  222. }
  223. UserButton {
  224. id: adjustbutton;
  225. text: "调压";
  226. font.pixelSize: 20
  227. anchors.verticalCenter: parent.verticalCenter
  228. implicitWidth: 100
  229. implicitHeight: 60
  230. onClicked: {
  231. //var str_number = voltage.text
  232. var num = Number(voltage.text)
  233. if((num>0) && (num<1000)){
  234. testService.adjust_Pressure(voltage.text)
  235. }else{
  236. console.log("input voltage invalid")
  237. log.show("Voltage invalid, please retry")
  238. }
  239. }
  240. }
  241. InputLine{
  242. id:voltage
  243. paraName: "Voltage:"
  244. paraLength: 60
  245. anchors.verticalCenter: parent.verticalCenter
  246. validator:RegExpValidator {
  247. regExp: /[0-9]*/
  248. }
  249. onTextChanged: {
  250. //root.manufacture = text
  251. }
  252. }
  253. }
  254. }
  255. DynamicGroupBox{
  256. id:pressure
  257. title: "实时压力"
  258. width: 800
  259. height: 100
  260. Row{
  261. anchors.verticalCenter: parent.verticalCenter
  262. anchors.left: parent.left
  263. spacing: 20
  264. Timer {
  265. id: timer;
  266. interval: 1000;//设置定时器定时时间为500ms,默认1000ms
  267. repeat: true //是否重复定时,默认为false
  268. running: false //是否开启定时,默认是false,当为true的时候,进入此界面就开始定时
  269. triggeredOnStart: false // 是否开启定时就触发onTriggered,一些特殊用户可以用来设置初始值。
  270. onTriggered: {
  271. lcd_pressure.text = testService.read_PressureValue();
  272. }
  273. //restart ,start,stop,定时器的调用方式,顾名思义
  274. }
  275. UserButton {
  276. id: readbutton;
  277. text: "开始";
  278. font.pixelSize: 20
  279. anchors.verticalCenter: parent.verticalCenter
  280. implicitWidth: 100
  281. implicitHeight: 60
  282. onEnabledChanged: {
  283. if(timer.running){
  284. timer.stop()
  285. text= "开始"
  286. }else{
  287. //timer.start()
  288. //text= "停止"
  289. }
  290. }
  291. onClicked: {
  292. if(timer.running){
  293. timer.stop()
  294. text= "开始"
  295. }else{
  296. timer.start()
  297. text= "停止"
  298. }
  299. //lcd_pressure.text = pressvalue.toFixed(3).toString()
  300. }
  301. }
  302. Rectangle{
  303. id:pressureWindow
  304. //anchors.fill: parent
  305. anchors.verticalCenter: parent.verticalCenter
  306. width: 120
  307. height: 40
  308. //color: "white"
  309. radius: 4
  310. LCDNumber{
  311. id:lcd_pressure
  312. anchors.centerIn: parent
  313. //anchors.verticalCenter: parent.verticalCenter
  314. text: "5.00"
  315. fontsize: 40
  316. }
  317. }
  318. Text {
  319. id: kpa
  320. anchors.left: lcd_pressure.right
  321. anchors.verticalCenter: parent.verticalCenter
  322. text: qsTr("kPa")
  323. //font: 40
  324. font.bold: true
  325. font.pixelSize: 25
  326. }
  327. }
  328. }
  329. DynamicGroupBox{
  330. id:selftest
  331. title: "系统自测"
  332. width: 800
  333. height: 100
  334. Row{
  335. anchors.verticalCenter: parent.verticalCenter
  336. anchors.left: parent.left
  337. spacing: 30
  338. UserButton {
  339. id: selftest_button;
  340. text: "开始";
  341. font.pixelSize: 20
  342. //height: 40
  343. //width: 160
  344. implicitWidth: 100
  345. implicitHeight: 60
  346. onClicked: {
  347. //var str_number = voltage.text
  348. if(false == bSelfTest_Started){
  349. //bSelfTest_Started = true;
  350. //selftest_result.text= "测试通过"
  351. if(timer.running){
  352. timer.stop()
  353. }
  354. var ret = testService.tselfstart(0, 0)
  355. if(ret){
  356. bSelfTest_Started = true;
  357. readbutton.enabled = false;
  358. adjustbutton.enabled = false;
  359. text = "停止"
  360. selfTest_State_str=""
  361. selfTest_Result_str=""
  362. //timer.start()
  363. }else{
  364. }
  365. }else{
  366. var ret1 = testService.tstop(0);
  367. if(ret1){
  368. bSelfTest_Started = false;
  369. //selftest_result.text = ""
  370. text = "开始"
  371. readbutton.enabled = true;
  372. adjustbutton.enabled = true;
  373. //timer.stop()
  374. }
  375. }
  376. }
  377. }
  378. Text {
  379. id: selftest_state
  380. anchors.verticalCenter: parent.verticalCenter
  381. text: qsTr("自测状态:")+selfTest_State_str
  382. font.pixelSize: 20
  383. }
  384. Text {
  385. id: selftest_result
  386. anchors.verticalCenter: parent.verticalCenter
  387. text: qsTr("自测结果:")+selfTest_Result_str
  388. font.pixelSize: 20
  389. }
  390. }
  391. }
  392. }
  393. }
  394. // }
  395. }