PageTest.qml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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. /*
  23. function show_selftestState(str){
  24. selfTest_State_str = str
  25. }
  26. function show_selftestResult(str){
  27. selfTest_Result_str = str
  28. }
  29. function show_selftestDetail(str){
  30. selfTest_Detail_str = str
  31. }
  32. function selftestStop(){
  33. var ret1 = testService.tstop(0);
  34. if(ret1){
  35. bSelfTest_Started = false;
  36. //selftest_result.text = ""
  37. selftest_button.text = "开始"
  38. readbutton.enabled = true;
  39. adjustbutton.enabled = true;
  40. //timer.stop()
  41. }
  42. }
  43. */
  44. // Component{
  45. // id:componet
  46. DynamicGroupBox{
  47. id:groupbox
  48. //x:width
  49. //x:0
  50. anchors.centerIn: parent
  51. anchors.fill: parent
  52. title: title_str
  53. Column{
  54. spacing: 10
  55. anchors.centerIn: parent
  56. DynamicGroupBox{
  57. id:relays_control
  58. title: "电磁阀控制"
  59. width: 800
  60. height: 100
  61. Row{
  62. anchors.centerIn: parent
  63. //columns: 4
  64. //rows:1
  65. //columnSpacing: 80
  66. //rowSpacing: 30
  67. spacing: 60
  68. UserSwitch{
  69. id:switch1
  70. text: "进气阀关"
  71. onCheckedChanged: {
  72. //console.log("switch 1 onCheckedChanged")
  73. switch1.text = switch1.checked ? "进气阀开":"进气阀关"
  74. if(switch1.checked){
  75. testService.valve_open(TestService.Valve_ID_INTAKE)
  76. }else{
  77. testService.valve_close(TestService.Valve_ID_INTAKE)
  78. }
  79. }
  80. onClicked: {
  81. //console.log("switch 1 clicked")
  82. }
  83. }
  84. UserSwitch{
  85. id:switch2
  86. text: "真空阀关"
  87. onCheckedChanged: {
  88. switch2.text = switch2.checked ? "真空阀开":"真空阀关"
  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. onClicked: {
  96. }
  97. }
  98. UserSwitch{
  99. id:switch3
  100. text: "泄气阀关"
  101. onCheckedChanged: {
  102. switch3.text = switch3.checked ? "泄气阀开":"泄气阀关"
  103. if(switch3.checked){
  104. testService.valve_open(TestService.Valve_ID_VENT)
  105. }else{
  106. testService.valve_close(TestService.Valve_ID_VENT)
  107. }
  108. }
  109. onClicked: {
  110. }
  111. }
  112. UserSwitch{
  113. id:switch4
  114. text: "全部关"
  115. onCheckedChanged: {
  116. switch4.text = switch4.checked ? "全部开":"全部关"
  117. if(switch4.checked){
  118. testService.valve_open(TestService.Valve_ID_All)
  119. }else{
  120. testService.valve_close(TestService.Valve_ID_All)
  121. }
  122. }
  123. onClicked: {
  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.fill: parent
  217. //anchors.verticalCenter: parent.verticalCenter
  218. anchors.verticalCenter: parent.verticalCenter
  219. //anchors.left: parent.left
  220. layoutDirection: Qt.LeftToRight
  221. spacing: 20
  222. Timer {
  223. id: timer;
  224. interval: 1000;//设置定时器定时时间为500ms,默认1000ms
  225. repeat: true //是否重复定时,默认为false
  226. running: false //是否开启定时,默认是false,当为true的时候,进入此界面就开始定时
  227. triggeredOnStart: false // 是否开启定时就触发onTriggered,一些特殊用户可以用来设置初始值。
  228. onTriggered: {
  229. lcd_pressure.text = testService.read_PressureValue()
  230. }
  231. //restart ,start,stop,定时器的调用方式,顾名思义
  232. }
  233. UserButton {
  234. id: readbutton;
  235. text: "开始";
  236. font.pixelSize: 20
  237. //anchors.verticalCenter: parent.verticalCenter
  238. implicitWidth: 120
  239. implicitHeight: 45
  240. onEnabledChanged: {
  241. if(timer.running){
  242. timer.stop()
  243. text= "开始"
  244. }else{
  245. //timer.start()
  246. //text= "停止"
  247. }
  248. }
  249. onClicked: {
  250. if(timer.running){
  251. timer.stop()
  252. text= "开始"
  253. }else{
  254. timer.start()
  255. text= "停止"
  256. }
  257. //lcd_pressure.text = pressvalue.toFixed(3).toString()
  258. }
  259. }
  260. Rectangle{
  261. id:pressureWindow
  262. //anchors.fill: parent
  263. //anchors.verticalCenter: parent.verticalCenter
  264. width: 120
  265. height: 40
  266. //color: "white"
  267. radius: 4
  268. LCDNumber{
  269. id:lcd_pressure
  270. anchors.centerIn: parent
  271. //anchors.verticalCenter: parent.verticalCenter
  272. text: "5.00"
  273. fontsize: 40
  274. }
  275. }
  276. Text {
  277. id: kpa
  278. //anchors.left: pressureWindow.right
  279. anchors.verticalCenter: parent.verticalCenter
  280. text: qsTr("kPa")
  281. //font: 40
  282. font.bold: true
  283. font.pixelSize: 25
  284. }
  285. UserButton {
  286. id: zerobutton;
  287. text: "传感器标零";
  288. font.pixelSize: 20
  289. //anchors.verticalCenter: parent.verticalCenter
  290. implicitWidth: 120
  291. implicitHeight: 45
  292. onClicked: {
  293. testService.pressure_zero()
  294. }
  295. }
  296. }
  297. }
  298. /*
  299. DynamicGroupBox{
  300. id:selftest
  301. title: "系统自测"
  302. width: 800
  303. height: 100
  304. Row{
  305. anchors.verticalCenter: parent.verticalCenter
  306. anchors.left: parent.left
  307. spacing: 30
  308. UserButton {
  309. id: selftest_button;
  310. text: "开始";
  311. font.pixelSize: 20
  312. //height: 40
  313. //width: 160
  314. implicitWidth: 120
  315. implicitHeight: 45
  316. onClicked: {
  317. //var str_number = voltage.text
  318. if(false == bSelfTest_Started){
  319. //bSelfTest_Started = true;
  320. //selftest_result.text= "测试通过"
  321. if(timer.running){
  322. timer.stop()
  323. }
  324. var ret = testService.tselfstart(0, 0)
  325. if(ret){
  326. bSelfTest_Started = true;
  327. readbutton.enabled = false;
  328. adjustbutton.enabled = false;
  329. text = "停止"
  330. selfTest_State_str=""
  331. selfTest_Result_str=""
  332. //timer.start()
  333. }else{
  334. }
  335. }else{
  336. var ret1 = testService.tstop(0);
  337. if(ret1){
  338. bSelfTest_Started = false;
  339. //selftest_result.text = ""
  340. text = "开始"
  341. readbutton.enabled = true;
  342. adjustbutton.enabled = true;
  343. //timer.stop()
  344. }
  345. }
  346. }
  347. }
  348. Text {
  349. id: selftest_state
  350. anchors.verticalCenter: parent.verticalCenter
  351. text: qsTr("自测状态:")+selfTest_State_str
  352. font.pixelSize: 20
  353. }
  354. Text {
  355. id: selftest_result
  356. anchors.verticalCenter: parent.verticalCenter
  357. text: qsTr("自测结果:")+selfTest_Result_str
  358. font.pixelSize: 20
  359. }
  360. Text {
  361. id: selftest_Detail
  362. anchors.verticalCenter: parent.verticalCenter
  363. text: selfTest_Detail_str
  364. font.pixelSize: 16
  365. //lineHeight: Text.ProportionalHeight //设置行间距
  366. lineHeight: 0.5 //行间距比例 最大 1
  367. wrapMode: Text.WordWrap //换行
  368. fontSizeMode: Text.Fit //固定 Text 显示大小->字体自动变化的模式选中还有几种看文档
  369. minimumPixelSize: 10 //设置自动变化最小字体大小
  370. }
  371. }
  372. }
  373. */
  374. }
  375. }
  376. // }
  377. }