vb.net - 循环启动时串行通信停止工作
问题描述
如果我启动一个循环,我的串行数据通信有问题,它不会更新我的体重秤的数据。我不知道如何继续通信以及运行循环。我的代码逻辑将在循环中,因此我可以检查整数中的值并将其与串行数据中的数据(称重秤)进行比较
Private Sub conWeight_DataReceived(sender As System.Object, e As System.IO.Ports.SerialDataReceivedEventArgs) Handles conWeight.DataReceived
receivedText(conWeight.ReadExisting())
End Sub
Private Sub receivedText(ByVal [text] As String)
If Me.lblWeight.InvokeRequired Then
Dim x As New SetTextCallback(AddressOf receivedText)
Me.Invoke(x, New Object() {(text)})
Else
Dim reverseString As String = [text]
Dim revString As String = StrReverse(reverseString)
Dim clean As String
clean = revString.Replace("=", "")
Me.lblWeight.Text = clean 'append text
End If
End Sub
'this is part with loop
If binWeight = 0 Then
targetweight = CInt(txtbSilo1.Text) + CInt(txtbSilo2.Text) + CInt(txtbSilo3.Text) + CInt(txtbSilo4.Text)
If CInt(txtbSilo1.Text) > 0 Then
currentWeight = CInt(txtbSilo1.Text)
frmAutomaticControl.conControl.Open()
frmAutomaticControl.conControl.Write("motr1")
frmAutomaticControl.conControl.Close()
MsgBox("check")
Do
If binWeight >= currentWeight Then
frmAutomaticControl.conControl.Open()
frmAutomaticControl.conControl.Write("moto1")
frmAutomaticControl.conControl.Close()
Exit Do
End If
Loop
Else
End If
BunifuFlatButton1.Enabled = True
Else
MsgBox("Empty The Bin")
End If
解决方案
只是几个想法。1. 将那部分代码扔到后台工作人员中。2. 将其放入一个 application.doevents 中。3. 创建一个全局变量,该变量将捕获循环每次迭代的输出,然后将其提供给它需要去的地方。
推荐阅读
- python - 使用openpyx打开下载的excel表格,只有在自己再次保存后才能使用
- java - 在 React Native 中隐藏键盘
- node.js - node-nlp 如何提取电子邮件、电话、网址?
- esper - Esper - 将多行中的值连接到列表
- spring-boot - 在 sigkill 上进行 Spring Boot 清理
- sql - 根据 Select Order By Results 更新 OrderID?
- correlation - 如何测量由层次聚类产生的两个聚类树之间的相似性?
- c++ - 为什么我收到来自谷歌的错误请求?
- php - 在 MacOs Mojave 上安装 xdebug - 找不到“php.h”文件
- bash - 如何使用临时命令从 bash 中读取 ansible 变量值?