vb与仪表通讯(RS485)

已锁定

CCL-CCL

西门子1847工业学习平台

  • 帖子

    8
  • 精华

    0
  • 被关注

    15

论坛等级:游侠

注册时间:2011-11-15

普通 普通 如何晋级?

vb与仪表通讯(RS485)

817

1

2015-03-15 23:09:29

本人现在想用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
希望大家帮帮小弟急用!!还有就是怎样显示读取数据
vb与仪表通讯(RS485) 已锁定
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC S7-300/400

共有54622条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。