Skip to content

Commit be89cc8

Browse files
committed
增加获取参数功能
1 parent 886b15c commit be89cc8

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/App.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ import {
5656
import { useDark, useToggle } from '@vueuse/core'
5757
const isDark = useDark()
5858
const toggleDark = useToggle(isDark)
59-
let switchVal = ref(isDark.value)
60-
let isConnected = ref(false)
59+
const switchVal = ref(isDark.value)
60+
const isConnected = ref(false)
6161
6262
function UseDarkMode() {
6363
WaveGenChart.darkMode(isDark.value);
@@ -74,9 +74,13 @@ function connectDevice() {
7474
}
7575
}
7676
function receiveMessage(message: any) {
77-
if (message.data[0] == '{') {
77+
if (message.data[0] == '{' && message.data[2] == 'a') {
7878
var data = JSON.parse(message.data);
7979
OSChart.refreshData(data);
80+
} else if(message.data[0] == '{' && message.data[2] == 'p'){
81+
var data = JSON.parse(message.data);
82+
console.log(data.param);
83+
WaveGen.changeParam(data.param);
8084
} else {
8185
console.log(message.data);
8286
}
@@ -85,7 +89,7 @@ function receiveMessage(message: any) {
8589
8690
onMounted(() => {
8791
UseDarkMode();
88-
switchVal = ref(isDark.value);
92+
switchVal.value = isDark.value;
8993
});
9094
9195
</script>

src/components/WaveGen.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</el-form-item>
3030
<el-form-item>
3131
<el-button type="primary" @click="onSubmit" style="width: 45%; margin-right: 5%;">立即设置</el-button>
32-
<el-button style="width: 45%; margin-left: 5%;">取消</el-button>
32+
<el-button @click="getParam" style="width: 45%; margin-left: 5%;">获取参数</el-button>
3333
</el-form-item>
3434
</el-form>
3535
</div>
@@ -72,7 +72,6 @@ const form = reactive({
7272
duty: ref(50),
7373
uMaxValue: ref(3.3),
7474
biasVoltage: ref(1.65),
75-
7675
})
7776
7877
const sendData = (data: string) => {
@@ -94,6 +93,18 @@ const onSubmit = () => {
9493
WaveGenChart.refreshData();
9594
console.log('submit!')
9695
}
96+
const getParam = () => {
97+
sendData("GP");
98+
console.log('获取参数');
99+
}
100+
const changeParam = (param: Object) => {
101+
uMaxValue.value = param.U;
102+
biasVoltage.value = param.B;
103+
duty.value = param.D;
104+
freq.value = param.F;
105+
waveType.value = String(param.W);
106+
WaveGenChart.refreshData();
107+
}
97108
const waveTypeChange = (value: string) => {
98109
console.log("W" + value);
99110
form.waveType = value;
@@ -124,6 +135,7 @@ export default {
124135
duty,
125136
uMaxValue,
126137
biasVoltage,
138+
changeParam,
127139
props1: {
128140
msg: String
129141
}

0 commit comments

Comments
 (0)