WINCC串口通信不能传送二进制数据? 点击:176 | 回复:1



YaCai

    
  • 精华:0帖
  • 求助:0帖
  • 帖子:1帖 | 2回
  • 年度积分:0
  • 历史总积分:548
  • 注册:2017年3月30日
发表于:2019-02-26 14:02:49
楼主

我用MSCOMM在WINCC中进行串口通讯,现在收发文本信息没问题。但是无法收发二进制数据,请教各位?

以下是OnCom的代码,定义bytInput为bytInput()或objMSComm.InputMode =1时,程序立即无效。(既不报错,也无反应)

Sub OnComm(ByVal Item)                                                  

 Dim bytInput,intInputLen

 Dim aa,bb,cc,dd,addr,strLen,strCRC

 Dim staus,objMSComm

 Dim CurrentTime,tNow

   Set objMSComm = HMIRuntime.Screens("AX").ScreenItems("COM") 

   Select Case objMSComm.CommEvent '分析接收事件的类型

            Case 2 'comEvReceive    '值为2,收到 Rthreshold 个字符。

                If Not objMSComm.PortOpen Then  '串口关闭则打开

                    objMSComm.CommPort = 3

                    objMSComm.Settings = "9600,N,8,1"

                    objMSComm.PortOpen = True

                End If

              '此处添加处理接收的代码

               objMSComm.InputMode = 0 'comInputModeBinary                 

               intInputLen = objMSComm.InBufferCount  '接收区计数  

               Redim bytInput(intInputLen) '重新定义数组

               bytInput = objMSComm.input                 

   End Select  

  ' objMSComm.output=bytInput()

If bytInput<>"" Then  

    Set aa=HMIRuntime.Tags("接收数量")

    aa.Write intInputLen

    Set aa=HMIRuntime.Tags("接收字符")

    aa.Write bytInput 





YaCai

  • 精华:0帖
  • 求助:0帖
  • 帖子:1帖 | 2回
  • 年度积分:0
  • 历史总积分:548
  • 注册:2017年3月30日
发表于:2019-02-26 14:11:36
1楼

我在VB6中是测试成功了的。不知VBS和VB有什么区别,或WINCC中有啥特殊的地方?


热门招聘
相关主题

官方公众号

智造工程师