PageTest.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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.verticalCenter: parent.verticalCenter
  215. anchors.left: parent.left
  216. spacing: 20
  217. Timer {
  218. id: timer;
  219. interval: 1000;//设置定时器定时时间为500ms,默认1000ms
  220. repeat: true //是否重复定时,默认为false
  221. running: false //是否开启定时,默认是false,当为true的时候,进入此界面就开始定时
  222. triggeredOnStart: false // 是否开启定时就触发onTriggered,一些特殊用户可以用来设置初始值。
  223. onTriggered: {
  224. lcd_pressure.text = testService.read_PressureValue()
  225. }
  226. //restart ,start,stop,定时器的调用方式,顾名思义
  227. }
  228. UserButton {
  229. id: readbutton;
  230. text: "开始";
  231. font.pixelSize: 20
  232. anchors.verticalCenter: parent.verticalCenter
  233. implicitWidth: 120
  234. implicitHeight: 45
  235. onEnabledChanged: {
  236. if(timer.running){
  237. timer.stop()
  238. text= "开始"
  239. }else{
  240. //timer.start()
  241. //text= "停止"
  242. }
  243. }
  244. onClicked: {
  245. if(timer.running){
  246. timer.stop()
  247. text= "开始"
  248. }else{
  249. timer.start()
  250. text= "停止"
  251. }
  252. //lcd_pressure.text = pressvalue.toFixed(3).toString()
  253. }
  254. }
  255. Rectangle{
  256. id:pressureWindow
  257. //anchors.fill: parent
  258. anchors.verticalCenter: parent.verticalCenter
  259. width: 120
  260. height: 40
  261. //color: "white"
  262. radius: 4
  263. LCDNumber{
  264. id:lcd_pressure
  265. anchors.centerIn: parent
  266. //anchors.verticalCenter: parent.verticalCenter
  267. text: "5.00"
  268. fontsize: 40
  269. }
  270. }
  271. Text {
  272. id: kpa
  273. anchors.left: lcd_pressure.right
  274. anchors.verticalCenter: parent.verticalCenter
  275. text: qsTr("kPa")
  276. //font: 40
  277. font.bold: true
  278. font.pixelSize: 25
  279. }
  280. UserButton {
  281. id: zerobutton;
  282. text: "传感器标零";
  283. font.pixelSize: 20
  284. anchors.verticalCenter: parent.verticalCenter
  285. implicitWidth: 120
  286. implicitHeight: 45
  287. onClicked: {
  288. testService.pressure_zero()
  289. }
  290. }
  291. }
  292. }
  293. DynamicGroupBox{
  294. id:selftest
  295. title: "系统自测"
  296. width: 800
  297. height: 100
  298. Row{
  299. anchors.verticalCenter: parent.verticalCenter
  300. anchors.left: parent.left
  301. spacing: 30
  302. UserButton {
  303. id: selftest_button;
  304. text: "开始";
  305. font.pixelSize: 20
  306. //height: 40
  307. //width: 160
  308. implicitWidth: 120
  309. implicitHeight: 45
  310. onClicked: {
  311. //var str_number = voltage.text
  312. if(false == bSelfTest_Started){
  313. //bSelfTest_Started = true;
  314. //selftest_result.text= "测试通过"
  315. if(timer.running){
  316. timer.stop()
  317. }
  318. var ret = testService.tselfstart(0, 0)
  319. if(ret){
  320. bSelfTest_Started = true;
  321. readbutton.enabled = false;
  322. adjustbutton.enabled = false;
  323. text = "停止"
  324. selfTest_State_str=""
  325. selfTest_Result_str=""
  326. //timer.start()
  327. }else{
  328. }
  329. }else{
  330. var ret1 = testService.tstop(0);
  331. if(ret1){
  332. bSelfTest_Started = false;
  333. //selftest_result.text = ""
  334. text = "开始"
  335. readbutton.enabled = true;
  336. adjustbutton.enabled = true;
  337. //timer.stop()
  338. }
  339. }
  340. }
  341. }
  342. Text {
  343. id: selftest_state
  344. anchors.verticalCenter: parent.verticalCenter
  345. text: qsTr("自测状态:")+selfTest_State_str
  346. font.pixelSize: 20
  347. }
  348. Text {
  349. id: selftest_result
  350. anchors.verticalCenter: parent.verticalCenter
  351. text: qsTr("自测结果:")+selfTest_Result_str
  352. font.pixelSize: 20
  353. }
  354. Text {
  355. id: selftest_Detail
  356. anchors.verticalCenter: parent.verticalCenter
  357. text: selfTest_Detail_str
  358. font.pixelSize: 16
  359. //lineHeight: Text.ProportionalHeight //设置行间距
  360. lineHeight: 0.5 //行间距比例 最大 1
  361. wrapMode: Text.WordWrap //换行
  362. fontSizeMode: Text.Fit //固定 Text 显示大小->字体自动变化的模式选中还有几种看文档
  363. minimumPixelSize: 10 //设置自动变化最小字体大小
  364. }
  365. }
  366. }
  367. }
  368. }
  369. // }
  370. }