main.qml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. import QtQuick 2.11
  2. import QtQuick.Controls 1.4
  3. import SerialUi 1.0
  4. //import SerialPort 1.0
  5. import ReportWord 1.0
  6. import QtTest 1.14
  7. import FileIO 1.0
  8. import "modbus.js" as ModbusJs
  9. ApplicationWindow {
  10. id: window
  11. visible: true
  12. width: 1010
  13. height: 700
  14. title: qsTr("阀门试验")
  15. property bool lampState:false
  16. property bool virtualkeyboard:true
  17. maximumHeight: height
  18. maximumWidth: width
  19. minimumHeight: height
  20. minimumWidth: width
  21. menuBar: ChooseValve{
  22. id:choosevalve
  23. onChoose: {
  24. if(text === "安全阀"){
  25. breatheValve.exit()
  26. vacuoValve.exit()
  27. peopleCoverHoleValve.exit()
  28. tankValve.exit()
  29. calibrationMode.exit()
  30. sealSelfTest.exit()
  31. safeValve.show()
  32. ModbusJs.closeAllValve(controlSerial)
  33. }
  34. else if(text === "呼吸阀"){
  35. safeValve.exit()
  36. vacuoValve.exit()
  37. peopleCoverHoleValve.exit()
  38. tankValve.exit()
  39. calibrationMode.exit()
  40. sealSelfTest.exit()
  41. breatheValve.show()
  42. ModbusJs.closeAllValve(controlSerial)
  43. }
  44. else if(text === "真空阀"){
  45. safeValve.exit()
  46. breatheValve.exit()
  47. peopleCoverHoleValve.exit()
  48. tankValve.exit()
  49. calibrationMode.exit()
  50. vacuoValve.show()
  51. sealSelfTest.exit()
  52. ModbusJs.closeAllValve(controlSerial)
  53. }
  54. else if(text === "人孔盖"){
  55. safeValve.exit()
  56. breatheValve.exit()
  57. vacuoValve.exit()
  58. tankValve.exit()
  59. calibrationMode.exit()
  60. sealSelfTest.exit()
  61. peopleCoverHoleValve.show()
  62. ModbusJs.closeAllValve(controlSerial)
  63. }
  64. else if(text === "罐体"){
  65. safeValve.exit()
  66. breatheValve.exit()
  67. vacuoValve.exit()
  68. peopleCoverHoleValve.exit()
  69. calibrationMode.exit()
  70. sealSelfTest.exit()
  71. tankValve.show()
  72. ModbusJs.closeAllValve(controlSerial)
  73. }
  74. else if(text === "密封自检"){
  75. safeValve.exit()
  76. breatheValve.exit()
  77. vacuoValve.exit()
  78. peopleCoverHoleValve.exit()
  79. calibrationMode.exit()
  80. tankValve.exit()
  81. sealSelfTest.show()
  82. ModbusJs.closeAllValve(controlSerial)
  83. }
  84. else if(text === "标定模式"){
  85. safeValve.exit()
  86. breatheValve.exit()
  87. vacuoValve.exit()
  88. peopleCoverHoleValve.exit()
  89. tankValve.exit()
  90. calibrationMode.show()
  91. }
  92. }
  93. }
  94. SafeValve{
  95. id:safeValve
  96. anchors.fill: parent
  97. }
  98. BreatheValve{
  99. id:breatheValve
  100. anchors.fill: parent
  101. }
  102. VacuoValve{
  103. id:vacuoValve
  104. anchors.fill: parent
  105. }
  106. PeopleCoverHoleValve{
  107. id:peopleCoverHoleValve
  108. anchors.fill: parent
  109. }
  110. TankValve{
  111. id:tankValve
  112. anchors.fill: parent
  113. }
  114. SealSelfTest{
  115. id:sealSelfTest
  116. anchors.fill: parent
  117. }
  118. Calibration{
  119. anchors.fill: parent
  120. id:calibrationMode
  121. }
  122. Component.onCompleted: {
  123. breatheValve.show()
  124. }
  125. GenerateCurve{
  126. id:generateCurve
  127. z:100
  128. }
  129. SerialUi{
  130. id:controlSerial
  131. property bool connected: false
  132. // onTimeout:{
  133. // log.show("control modbus通讯接收超时")
  134. // }
  135. onCheckError: {
  136. //log.show("control modbus通讯接收数据校验错误")
  137. }
  138. Component.onCompleted: {
  139. //(QString port, QString baudrate, QString databits, QString parity, QString stopbits)
  140. connected = controlSerial.serialConnect("COM4","9600","8","0","1")
  141. if(connected === false){
  142. log.show("打开控制串口COM4失败")
  143. }
  144. else{
  145. console.log("打开控制串口COM4成功")
  146. timer.start()
  147. }
  148. }
  149. }
  150. Timer{
  151. id:timer
  152. interval: 1000
  153. repeat: false
  154. onTriggered: {
  155. console.log("关闭所有阀门")
  156. ModbusJs.closeAllValve(controlSerial)
  157. }
  158. }
  159. SerialUi{
  160. id:sensorSerial
  161. property bool connected: false
  162. // onTimeout:{
  163. // log.show("sensor modbus通讯接收超时")
  164. // }
  165. onCheckError: {
  166. // log.show("sensor modbus通讯接收数据校验错误")
  167. }
  168. Component.onCompleted: {
  169. //(QString port, QString baudrate, QString databits, QString parity, QString stopbits)
  170. connected = sensorSerial.serialConnect("COM3","9600","8","2","1")
  171. if(connected === false){
  172. log.show("打开传感器串口COM3失败")
  173. }
  174. else{
  175. console.log("打开传感器串口COM3成功")
  176. }
  177. }
  178. }
  179. FileIO{
  180. id:fileio
  181. }
  182. //wait 超时专用
  183. SignalSpy {
  184. id: spy
  185. target: controlSerial
  186. signalName: "spy"
  187. }
  188. Log{
  189. id:log
  190. z:10
  191. width: 300
  192. height: 50
  193. anchors.centerIn: parent
  194. }
  195. Log{
  196. id:reportProgressLog
  197. z:10
  198. width: 300
  199. height: 50
  200. anchors.centerIn: parent
  201. }
  202. ReportPicture{
  203. id:reportPicture
  204. }
  205. ReportPicture{
  206. id:reportPicture0
  207. }
  208. ReportPicture{
  209. id:reportPicture1
  210. }
  211. ReportPicture{
  212. id:reportPicture2
  213. }
  214. ReportPicture{
  215. id:reportPicture3
  216. }
  217. ReportPicture{
  218. id:reportPicture4
  219. }
  220. ReportPicture{
  221. id:reportPicture5
  222. }
  223. ReportPicture{
  224. id:reportPicture6
  225. }
  226. ReportPicture{
  227. id:reportPicture7
  228. }
  229. ReportPicture{
  230. id:reportPicture8
  231. }
  232. ReportPicture{
  233. id:reportPicture9
  234. }
  235. ReportPicture{
  236. id:reportPicture10
  237. }
  238. ReportPicture{
  239. id:reportPicture11
  240. }
  241. ReportPicture{
  242. id:reportPicture12
  243. }
  244. ReportPicture{
  245. id:reportPicture13
  246. }
  247. ReportPicture{
  248. id:reportPicture14
  249. }
  250. ReportWord{
  251. id:reportWord
  252. onReportProgress: {
  253. if(text === "close")
  254. reportProgressLog.exit()
  255. else
  256. reportProgressLog.show(text)
  257. }
  258. }
  259. function pad_with_zeroes(number, length) {
  260. var my_string = '' + number;
  261. while (my_string.length < length) {
  262. my_string = '0' + my_string;
  263. }
  264. return my_string;
  265. }
  266. function getWordSaveFileName( para){
  267. var date = new Date;
  268. var year = date.getFullYear()
  269. var month = pad_with_zeroes(date.getMonth()+1,2)
  270. var day = pad_with_zeroes(date.getDate(),2)
  271. var hour = pad_with_zeroes(date.getHours(),2)
  272. var minute = pad_with_zeroes(date.getMinutes(),2)
  273. var second = pad_with_zeroes(date.getSeconds(),2)
  274. var time = year+month+day+hour+minute+second
  275. return "file:///"+time+"_"+para
  276. }
  277. }