PageTest.qml 16 KB

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