|
@@ -899,6 +899,7 @@ export default {
|
|
// // this.deptBudgetList.inOutType = '退库'
|
|
// // this.deptBudgetList.inOutType = '退库'
|
|
// this.deptBudgetList.inOutTypeKey = '1'
|
|
// this.deptBudgetList.inOutTypeKey = '1'
|
|
// }
|
|
// }
|
|
|
|
+ this.openPort()
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
async closePort() {
|
|
async closePort() {
|
|
@@ -907,15 +908,23 @@ export default {
|
|
},
|
|
},
|
|
async openPort() {
|
|
async openPort() {
|
|
console.log('openPort', navigator)
|
|
console.log('openPort', navigator)
|
|
- if ('serial' in navigator) {
|
|
|
|
- // The Web Serial API is supported.
|
|
|
|
- console.log('the Web Serial API is supported.')
|
|
|
|
- console.log(this.param)
|
|
|
|
- const port = await navigator.serial.requestPort()
|
|
|
|
- await port.open({
|
|
|
|
- baudRate: this.param,
|
|
|
|
- }) // set baud rate
|
|
|
|
- this.reader = port.readable.getReader()
|
|
|
|
|
|
+ if ('serial' in navigator) {
|
|
|
|
+ if (!this.$store.state.app.reader) {
|
|
|
|
+ // The Web Serial API is supported.
|
|
|
|
+ console.log('the Web Serial API is supported.')
|
|
|
|
+ console.log(this.param)
|
|
|
|
+ const port = await navigator.serial.requestPort()
|
|
|
|
+ await port.open({
|
|
|
|
+ baudRate: this.param,
|
|
|
|
+ }) // set baud rate
|
|
|
|
+ this.reader = port.readable.getReader()
|
|
|
|
+ console.log('beforeReader', port)
|
|
|
|
+ console.log('beforeReader', this.reader)
|
|
|
|
+ this.$store.dispatch('app/setReader', this.reader)
|
|
|
|
+ } else {
|
|
|
|
+ console.log('afterport', this.$store.state.app.reader)
|
|
|
|
+ this.reader = this.$store.state.app.reader
|
|
|
|
+ }
|
|
// 监听来自串行设备的数据
|
|
// 监听来自串行设备的数据
|
|
while (true) {
|
|
while (true) {
|
|
const { value, done } = await this.reader.read()
|
|
const { value, done } = await this.reader.read()
|