本人现在想用VB开发来读取多块多功能仪表的相关数据,因为本人是VB菜鸟还不断在自学中所有遇到困难较多希望大家帮帮忙,最好有源代码(CRC校验可以取消)
以下是本人写的有问题请大家指导:
Private Sub Form_Load()
MSComm1.CommPort = 6
MSComm1.SThreshold = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.InBufferSize = 40
MSComm1.OutBufferSize = 10
MSComm1.InputMode = comInputModeBinary
End Sub
Private Sub Command1_Click(Index As Integer)
MSComm1.PortOpen = False
End
End Sub
Private Sub Command2_Click(Index As Integer)
If (MSComm1.PortOpen = False) Then
MSComm1.PortOpen = True
End If
End Sub
Private Sub Timer1_Timer()
Dim No(4) As Byte
Dim Data As Double
Dim Buf() As Byte
Dim ByteOut(7) As Byte
MSComm1.InputLen = 0
Buf = MSComm1.Input
MSComm1.InputLen = 1
ByteOut(0) = &H1
ByteOut(1) = &H3
ByteOut(2) = &H0
ByteOut(3) = &H0
ByteOut(4) = &H0
ByteOut(5) = &H2
ByteOut(6) = &H31
ByteOut(7) = &HDB
MSComm1.Output = ByteOut(0) & ByteOut(1) & ByteOut(2) & ByteOut(3) & ByteOut(4) & ByteOut(5) & ByteOut(6) & ByteOut(7)
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 9
'从输入缓冲区读数据
Buf = MSComm1.Input
If Buf(0) <> 1 Then
MsgBox "地址错误!", vbCritical + vbOKOnly, "系统信息"
Exit Sub
End If
Buf = MSComm1.Input
If Buf(0) <> 3 Then
MsgBox "命令错误!", vbCritical + vbOKOnly, "系统信息"
Exit Sub
End If
Buf = MSComm1.Input
If Buf(0) <> 4 Then
MsgBox "长度错误!", vbCritical + vbOKOnly, "系统信息"
Exit Sub
End If
Buf = MSComm1.Input
No(1) = Buf(0)
Buf = MSComm1.Input
No(2) = Buf(0)
Buf = MSComm1.Input
No(3) = Buf(0)
Buf = MSComm1.Input
No(4) = Buf(0)
Buf = MSComm1.Input
Buf = MSComm1.Input
End Sub
希望大家帮帮小弟急用!!还有就是怎样显示读取数据
最佳答案
http://yunpan.cn/cZmRnXV97MdBN (提取码:4d17)
参考这个,wincc vbs串口通讯。
数据处理到脚本中了,那么定义你使用的软件内部变量(wincc就是wincc内部变量),然后脚本中把数据写入到变量中。
wincc 定义内部变量tag, vbs写数据到wincc的变量中:
hmiruntime.tags("tag").write mytag‘mytag是脚本中保存串口读来处理后的数据的变量。
提问者对于答案的评价:
OK
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc227517.html