PageTest.qml 16 KB

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