communication.wxml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <navigation-bar background="{{themeMode === 'dark' ? '#111827' : '#FFF'}}"></navigation-bar>
  2. <view wx:if="{{toastText}}" class="page-toast page-toast--{{toastType}} {{themeClass}}">
  3. {{toastText}}
  4. </view>
  5. <scroll-view class="scrollarea {{themeClass}}" scroll-y type="list">
  6. <view class="page-shell">
  7. <view wx:if="{{isNoProtocol}}" class="panel communication-panel">
  8. <view class="panel-header panel-header--with-actions">
  9. <view class="panel-icon icon-send">
  10. <image class="panel-icon-image" src="/assets/icons/send-white.png" mode="aspectFit" />
  11. </view>
  12. <view class="panel-title">串口通讯发送</view>
  13. <view class="panel-actions communication-actions">
  14. <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" bindtap="sendSerialFrame">发送</view>
  15. <view class="panel-action-button" bindtap="switchSerialMode">{{serialModeToggleText}}</view>
  16. <view class="panel-action-button" bindtap="clearSerialInput">清空</view>
  17. </view>
  18. </view>
  19. <view class="comm-send-body">
  20. <textarea
  21. class="comm-send-input comm-send-input--{{serialMode}}"
  22. maxlength="-1"
  23. auto-height
  24. placeholder="{{serialMode === 'hex' ? '01 03 00 00 00 02' : '文本'}}"
  25. value="{{serialInputText}}"
  26. bindinput="onSerialInput"
  27. />
  28. <view class="comm-send-meta">
  29. <view class="comm-send-state">{{serialModeLabel}} · {{connectedDevice ? '已连接' : '未连接'}}</view>
  30. <view class="comm-send-length">{{serialPreviewLengthText}}</view>
  31. </view>
  32. <view wx:if="{{serialPreviewHex}}" class="comm-preview">
  33. <view class="comm-preview-label">预览</view>
  34. <view class="comm-preview-value">{{serialPreviewHex}}</view>
  35. </view>
  36. </view>
  37. </view>
  38. <view wx:if="{{isModbusProtocol}}" class="panel communication-panel">
  39. <view class="panel-header panel-header--with-actions">
  40. <view class="panel-icon icon-control">
  41. <image class="panel-icon-image" src="/assets/icons/control-white.png" mode="aspectFit" />
  42. </view>
  43. <view class="panel-title">标准 Modbus</view>
  44. <view class="panel-actions communication-actions">
  45. <view
  46. class="panel-action-button {{protocolMultipleDialog.visible ? 'is-disabled' : ''}}"
  47. bindtap="sendProtocolFrame"
  48. >发送</view>
  49. <view wx:if="{{showProtocolMultipleButton}}" class="panel-action-button" bindtap="openProtocolMultipleDialog">多值</view>
  50. </view>
  51. </view>
  52. <view class="protocol-form">
  53. <view class="protocol-row">
  54. <view class="protocol-label">功能码</view>
  55. <picker mode="selector" range="{{protocolCommands}}" range-key="label" value="{{commandIndex}}" bindchange="onProtocolCommandChange">
  56. <view class="picker-value protocol-value-picker">{{protocolCommandLabel}}</view>
  57. </picker>
  58. </view>
  59. <view class="protocol-row">
  60. <view class="protocol-label">从机地址</view>
  61. <input class="protocol-input protocol-row-input" maxlength="2" value="{{slaveAddress}}" bindinput="onProtocolInput" data-field="slaveAddress" />
  62. </view>
  63. <view class="protocol-row">
  64. <view class="protocol-label">起始地址</view>
  65. <input class="protocol-input protocol-row-input" maxlength="4" value="{{registerAddress}}" bindinput="onProtocolInput" data-field="registerAddress" />
  66. </view>
  67. <view wx:if="{{showCommandValue}}" class="protocol-row">
  68. <view class="protocol-label">{{commandValueLabel}}</view>
  69. <input class="protocol-input protocol-row-input" value="{{commandValue}}" bindinput="onProtocolInput" data-field="commandValue" />
  70. </view>
  71. <view wx:if="{{showCoilValue}}" class="protocol-row coil-row">
  72. <view class="protocol-label">线圈</view>
  73. <view class="coil-control">
  74. <switch checked="{{coilEnabled}}" color="#0f766e" bindchange="onProtocolCoilChange" />
  75. <text>{{coilEnabled ? 'ON' : 'OFF'}}</text>
  76. </view>
  77. </view>
  78. <view wx:if="{{showRegisterQuantity}}" class="protocol-row">
  79. <view class="protocol-label">寄存器数</view>
  80. <input class="protocol-input protocol-row-input" value="{{commandRegisterQuantity}}" bindinput="onProtocolInput" data-field="commandRegisterQuantity" />
  81. </view>
  82. <view class="generated-frame">
  83. <view class="generated-title">帧</view>
  84. <view class="generated-value">{{generatedHex || '--'}}</view>
  85. </view>
  86. <view wx:if="{{protocolResponseText}}" class="generated-frame generated-frame--response">
  87. <view class="generated-title">回复</view>
  88. <view class="generated-value">{{protocolResponseText}}</view>
  89. </view>
  90. </view>
  91. </view>
  92. <view wx:if="{{isStorageAccessProtocol}}" class="panel communication-panel">
  93. <view class="panel-header panel-header--with-actions">
  94. <view class="panel-icon icon-chip">
  95. <image class="panel-icon-image" src="/assets/icons/chip-white.png" mode="aspectFit" />
  96. </view>
  97. <view class="panel-title">存储访问协议</view>
  98. <view class="panel-actions communication-actions">
  99. <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" bindtap="syncStorageAccessCodeInfo">同步</view>
  100. <view class="panel-action-button" bindtap="switchStorageAccessCommandMode">{{storageAccessCommandLabel}}</view>
  101. <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" bindtap="sendStorageAccessProtocolFrame">执行</view>
  102. </view>
  103. </view>
  104. <view class="protocol-form">
  105. <view class="storage-code-info-inline">
  106. <view class="storage-code-info-top">
  107. <text class="storage-code-info-model">{{storageCodeInfoCard.model}}</text>
  108. </view>
  109. <view class="storage-code-info-bottom">
  110. <text class="storage-code-info-chip">{{storageCodeInfoCard.chipModel}}</text>
  111. <view class="storage-code-info-metrics">
  112. <view wx:for="{{storageCodeInfoCard.metricItems}}" wx:for-item="item" wx:key="text" class="storage-code-info-metric">{{item.text}}</view>
  113. </view>
  114. </view>
  115. </view>
  116. <view class="protocol-row">
  117. <view class="protocol-label">区域</view>
  118. <view wx:if="{{storageAccessAreaLocked}}" class="picker-value protocol-value-picker">{{storageAccessAreaLabel}}</view>
  119. <picker wx:else mode="selector" range="{{storageAccessAreaOptions}}" range-key="label" value="{{storageAccessAreaIndex}}" bindchange="onStorageAccessAreaChange">
  120. <view class="picker-value protocol-value-picker">{{storageAccessAreaLabel}}</view>
  121. </picker>
  122. </view>
  123. <view class="protocol-row">
  124. <view class="protocol-label">地址</view>
  125. <input class="protocol-input protocol-row-input" maxlength="{{storageAccessAddressMaxLength || 8}}" value="{{storageAccessAddress}}" bindinput="onStorageAccessInput" data-field="storageAccessAddress" />
  126. </view>
  127. <view class="protocol-row">
  128. <view class="protocol-label">长度</view>
  129. <input class="protocol-input protocol-row-input" maxlength="4" value="{{storageAccessLength}}" bindinput="onStorageAccessInput" data-field="storageAccessLength" />
  130. </view>
  131. <view wx:if="{{storageAccessShowWriteData}}" class="protocol-row">
  132. <view class="protocol-label">数据</view>
  133. <input class="protocol-input protocol-row-input" value="{{storageAccessDataText}}" bindinput="onStorageAccessInput" data-field="storageAccessDataText" placeholder="01 02 03 04" />
  134. </view>
  135. <view class="generated-frame">
  136. <view class="generated-title">{{storageAccessTitleText || '读取命令'}}</view>
  137. <view class="generated-value">{{storageAccessPreviewHexText || '--'}}</view>
  138. <view wx:if="{{storageAccessPreviewText}}" class="generated-meta">{{storageAccessPreviewText}}</view>
  139. </view>
  140. <view class="storage-special-section">
  141. <view class="storage-special-section-title">特殊指令</view>
  142. </view>
  143. <view class="storage-special-actions">
  144. <view
  145. wx:for="{{storageAccessSpecialCommands}}"
  146. wx:key="key"
  147. wx:if="{{!item.hidden}}"
  148. class="panel-action-button storage-special-button {{connectedDevice ? '' : 'is-disabled'}}"
  149. data-command="{{item.key}}"
  150. bindtap="sendStorageAccessSpecialCommand"
  151. >
  152. {{item.label}}
  153. </view>
  154. </view>
  155. </view>
  156. </view>
  157. <view class="panel communication-panel">
  158. <view class="panel-header panel-header--with-actions">
  159. <view class="panel-icon icon-history">
  160. <image class="panel-icon-image" src="/assets/icons/history-white.png" mode="aspectFit" />
  161. </view>
  162. <view class="panel-title">收发日志</view>
  163. <view class="panel-actions communication-actions">
  164. <view class="panel-action-button" bindtap="switchLogMode">{{logModeToggleText}}</view>
  165. <view class="panel-action-button" bindtap="clearCommunicationLogs">清空</view>
  166. </view>
  167. </view>
  168. <view wx:if="{{!logs.length}}" class="empty-log">暂无日志</view>
  169. <scroll-view wx:else class="log-scroll" scroll-y type="list">
  170. <view
  171. wx:for="{{logs}}"
  172. wx:for-item="item"
  173. wx:key="id"
  174. class="log-row log-row--{{item.direction}}"
  175. >
  176. <view class="log-meta">
  177. <view class="log-tags">
  178. <view class="log-direction">{{item.direction}}</view>
  179. <view wx:if="{{item.note}}" class="log-note">{{item.note}}</view>
  180. </view>
  181. <view class="log-time">{{item.time}}</view>
  182. </view>
  183. <view class="log-payload log-payload--{{logMode}}">{{item.displayText || '--'}}</view>
  184. </view>
  185. </scroll-view>
  186. </view>
  187. </view>
  188. </scroll-view>
  189. <view wx:if="{{protocolMultipleDialog.visible}}" class="generic-dialog-mask {{themeClass}}" bindtap="closeProtocolMultipleDialog">
  190. <view class="generic-dialog protocol-multiple-dialog" catchtap="noop">
  191. <view class="generic-dialog-header">
  192. <view class="generic-dialog-title">{{protocolMultipleDialog.title || '多寄存器'}}</view>
  193. <view class="generic-dialog-close" bindtap="closeProtocolMultipleDialog">×</view>
  194. </view>
  195. <view class="generic-dialog-body">
  196. <view class="protocol-multiple-row">
  197. <view class="protocol-multiple-head">
  198. <view class="protocol-multiple-title">数量</view>
  199. <input class="value-input protocol-multiple-length-input" value="{{commandRegisterQuantity}}" bindinput="onProtocolMultipleQuantityChange" />
  200. </view>
  201. </view>
  202. <view
  203. wx:for="{{protocolMultipleValues}}"
  204. wx:for-item="register"
  205. wx:for-index="index"
  206. wx:key="name"
  207. wx:if="{{protocolMultipleExpanded || index < 3}}"
  208. class="protocol-multiple-row"
  209. >
  210. <view class="protocol-multiple-head">
  211. <view class="protocol-multiple-title">{{register.name}}</view>
  212. <picker mode="selector" range="{{protocolDataTypeOptions}}" range-key="label" value="{{register.dataTypeIndex}}" data-index="{{index}}" bindchange="onProtocolMultipleTypeChange">
  213. <view class="picker-value protocol-multiple-type">{{protocolDataTypeOptions[register.dataTypeIndex].label}}</view>
  214. </picker>
  215. </view>
  216. <view wx:if="{{register.showTextLength}}" class="protocol-multiple-text-length">
  217. <view class="protocol-label">长度</view>
  218. <input class="value-input protocol-multiple-length-input" data-index="{{index}}" value="{{register.textByteLength}}" bindinput="onProtocolMultipleTextLengthInput" />
  219. </view>
  220. <input
  221. class="value-input protocol-multiple-input {{register.dataType === 'text' ? 'protocol-multiple-input--text' : ''}}"
  222. placeholder="写入值"
  223. data-index="{{index}}"
  224. value="{{register.inputValue}}"
  225. bindinput="onProtocolMultipleValueInput"
  226. />
  227. </view>
  228. <view wx:if="{{protocolMultipleValues.length > 3}}" class="generic-draft-actions">
  229. <view class="panel-action-button" bindtap="toggleProtocolMultipleExpanded">{{protocolMultipleExpanded ? '收起' : '展开'}}</view>
  230. </view>
  231. </view>
  232. <view class="generic-draft-actions">
  233. <view class="panel-action-button" bindtap="closeProtocolMultipleDialog">关闭</view>
  234. <view class="panel-action-button is-active" data-source="dialog" bindtap="sendProtocolFrame">发送</view>
  235. </view>
  236. </view>
  237. </view>