|
@@ -7,7 +7,10 @@
|
|
|
<!-- 任务、消息、提醒、超期 -->
|
|
|
<Panel :data-list="panelList"
|
|
|
@click="gotoNewRw"></Panel>
|
|
|
- <img style='width:100%;margin-top:10px;' src="../../../public/img/tmt.gif" alt="">
|
|
|
+ <button @click="openPort">测试</button>
|
|
|
+ <button @click="closePort">关闭</button>
|
|
|
+ <div>{{text}}</div>
|
|
|
+ <!-- <img style='width:100%;margin-top:10px;' src="../../../public/img/tmt.gif" alt=""> -->
|
|
|
</div>
|
|
|
</div>
|
|
|
<div id="mapXY"></div>
|
|
@@ -29,6 +32,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+// import serialport from 'serialport'
|
|
|
// 统计图start
|
|
|
import maintenance from './components/maintenance'
|
|
|
import shipCertificate from './components/shipCertificate'
|
|
@@ -110,7 +114,8 @@ export default {
|
|
|
news: 0
|
|
|
},
|
|
|
vesselBankFlag: sessionStorage.getItem('ws-pf_vesselBankFlag'),
|
|
|
- shezhiVal: ''
|
|
|
+ shezhiVal: '',
|
|
|
+ text:"数据"
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
@@ -525,6 +530,43 @@ export default {
|
|
|
} else {
|
|
|
this.$router.push({ name: 'workNotification', query: { types: data } })
|
|
|
}
|
|
|
+ },
|
|
|
+ async openPort(){
|
|
|
+ if ("serial" in navigator) {
|
|
|
+ // The Web Serial API is supported.
|
|
|
+ console.log("the Web Serial API is supported.");
|
|
|
+ const port = await navigator.serial.requestPort();
|
|
|
+ await port.open({ baudRate: 9600 }); // set baud rate
|
|
|
+ const reader = port.readable.getReader();
|
|
|
+ // 监听来自串行设备的数据
|
|
|
+ while (true) {
|
|
|
+ const { value, done } = await reader.read();
|
|
|
+ console.log(value,done);
|
|
|
+ if (done) {
|
|
|
+ // 允许稍后关闭串口。
|
|
|
+ reader.releaseLock();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ var result="";
|
|
|
+ if(value.length < 5){
|
|
|
+ debugger
|
|
|
+ }
|
|
|
+ for(var i=0;i<value.length;i++){
|
|
|
+ result += String.fromCharCode(value[i])
|
|
|
+ }
|
|
|
+ this.text = result
|
|
|
+ // value 是一个 Uint8Array
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async closePort(){
|
|
|
+
|
|
|
+ const port = await navigator.serial.requestPort();
|
|
|
+ await port.open({ baudRate: 9600 }); // set baud rate
|
|
|
+ const reader = port.readable.getReader();
|
|
|
+ reader.cancel()
|
|
|
+ port.close();
|
|
|
}
|
|
|
}
|
|
|
}
|