发布于 2008-07-01 18:09:51
0楼
我最近刚做了一个这样的项目,上次在北京还向城斑,有谁共鸣两位斑竹请教过,以下是打开和关闭串口的代码,通过诊断窗口来调试比较方便,你可以监视到所有的收发信息,不要使用Msgbox来做。其它代码还未来得急整理,整体使用效果还不错。
Sub procedure20
,打开串口
Dim objMSComm1
Dim tagConnection
Set objMSComm1 = HMIRuntime.Screens("Main").ScreenItems("MSComm1")
Set tagConnection = HMIRuntime.Tags("Connection")
If objMSComm1.PortOpen = False Then
objMSComm1.Commport = 1
objMSComm1.Settings = "9600,e,7,1"
objMSComm1.InputLen = 0
objMSComm1.PortOpen = True
tagConnection.Write(True)
HMIRuntime.Trace("Port open." & vbCrLf)
Else
HMIRuntime.Trace("Port is already opened." & vbCrLf)
End If
End Sub
Sub procedure1()
‘关闭串口
Dim objMSComm1, tagConnection
Set objMSComm1 = HMIRuntime.Screens("Main").ScreenItems("MSComm1")
Set tagConnection = HMIRuntime.Tags("Connection")
If objMSComm1.PortOpen = True Then
objMSComm1.PortOpen = False
tagConnection.Write(False)
HMIRuntime.Trace("Port close." & vbCrLf)
End If
End Sub