PageTest.qml 16 KB

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