您现在所在的是:

三菱Mitsubishi

回帖:0个,阅读:1489 [上一页] [1] [下一页]
1654
wenyu
文章数:250
年度积分:50
历史总积分:1654
注册时间:2002/3/14
发站内信
发表于:2002/3/17 10:03:00
#0楼
各位专家:我参考别人编写的VB通过三菱PLC的采集程序,不是很明白,请各位帮帮手,万分感谢!(问题点在程序后打问号的),还有我想问一下多串口通讯采用什么形式比较好?用VB自带控件能胜任吗?用DLL(如:MOXA的PCMM.DLL)是否更好一些?谢谢!!!
Public Function ForcingM(PlcPort As Integer, ByVal m_no As Integer, ByVal Is_On As Boolean) As Boolean
  Dim oldtime As Long
  Dim newtime As Long
  Dim senddata As String
  Dim ReturnStr As String * 256
  Dim Addr As Integer
  Dim aa As Integer
  Dim i As Integer
  Dim ll As Integer
  Dim XiaBiao As Integer
  Dim FlagTime As Boolean
  Dim mbit(4) As String * 1
  ForcingM = False
   
  '清空缓冲区
  aa = sio_flush(PlcPort, 2)
 Addr = &H800 + m_no                ?什么意思?为什么要+&H800?
 For i = 0 To 3
   mbit(i) = Hex(Addr And &HF)       ?什么意思?为什么要AND &HF?
   Addr = Int(Addr / 16)              ?
 Next
 senddata = Chr$(&H2)
 If Is_On Then
    senddata = senddata & "7"
 Else
    senddata = senddata & "8"
 End If
 senddata = senddata & mbit(1)         ?
 senddata = senddata & mbit(0)         ?
 senddata = senddata & mbit(3)         ?
 senddata = senddata & mbit(2)         ?
 senddata = senddata & Chr$(&H3)
   aa = 0
   For i = 2 To 7
     aa = aa + Asc(Mid(senddata, i, 1))      ?什么意思?
     aa = aa And &HFF                         ?
   Next
   
 senddata = senddata & Hex(Int(aa / 16) And &HF)    ?什么意思?
 senddata = senddata & Hex(aa And &HF)               ?
   '把命令发送
   aa = sio_write(PlcPort, senddata, Len(senddata))
   
   '查看缓冲区
   oldtime = timeGetTime
   FlagTime = False
   Do
     aa = sio_iqueue(PlcPort)
     newtime = timeGetTime
     If (newtime < oldtime) Then
        oldtime = 0
     Else
        If (newtime - oldtime) > 1000 Then
            FlagTime = True
        End If
     End If

   Loop While aa <> 1 And FlagTime = False
   
   If FlagTime = Tr

关于我们 | 联系我们 | 广告服务 | 本站动态 | 友情链接 | 法律声明 | 非法和不良信息举报

工控网客服热线:0755-86369299
版权所有 工控网 Copyright©2024 Gkong.com, All Rights Reserved

31.2002