关 闭

新闻中心

EEPW首页 > 工控自动化 > 设计应用 > 基于VB6.0的工控机与智能流量积算仪的串口通信

基于VB6.0的工控机与智能流量积算仪的串口通信

作者:牛辉,孟华,侯建明 时间:2008-06-13 来源:中国工控网 收藏

  3.2 通信功能的编程实现

本文引用地址:https://www.eepw.com.cn/article/84182.htm

  程序框图如下:

图2 程序框图

串口初始化:1.CommPort = 1
1.SThreshold = 1
1.Settings = 9600,N,8,1
MSComm1.InBufferSize = 1024
MSComm1.OutBufferSize = 1024
MSComm1.InputMode = comInputModeBinary
打开串口并定时发送数据命令:Private Sub Timer1_Timer()
Dim bytearray(0 To 7) As Byte
bytearray(0) = &H1
bytearray(1) = &H3
bytearray(2) = &H0
bytearray(3) = &H2
bytearray(4) = &H0
bytearray(5) = &H8
bytearray(6) = &HE5
bytearray(7) = &HCC
MSComm1.InputLen = 21
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
If MSComm1.PortOpen = True Then
MSComm1.Output = bytearray
End If
End Sub
接受数据:Private Sub MSComm1_OnComm()
Do
DoEvents
Loop Until MSComm1.InBufferCount = 21
Dim dataread() As Byte
Dim tempdata As Variant
Dim str As String
If MSComm1.CommEvent = comEvReceive Then
tempdata = MSComm1.Input
ReDim dataread(UBound(tempdata)) As Byte
For i = 0 To UBound(tempdata)
dataread(i) = tempdata(i)
End Sub
同理利用以上程序框图和通信协议可以完成下图的所有功能:

图3 基于的D08-8CZM型流量积算仪

4、结束语

  利用6.0的MSComm 控件和协议,实现了与带RS-232输出的智能数字流量积算仪之间的功能,使其能够实时的采集瞬时流量,并成功的应用于底吹氩流量闭环控制系统。这种通信方式灵活方便,结构简单,可靠性高,完全达到了预期的要求,具有较好的实际价值和使用性。


上一页 1 2 下一页

评论


相关推荐

技术专区

关闭