标题: 各位专家:我参考别人编写的VB通过三菱PLC的采集
sanling
游客




UID 652
精华 0
积分 3860
帖子 3860
威望 0
金钱 7720
阅读权限 1
注册 2008-4-16
状态 离线
发表于 2008-4-16 23:08  资料  短消息  加为好友 

各位专家:我参考别人编写的VB通过三菱PLC的采集

各位专家:我参考别人编写的VB通过三菱PLC的采集各位专家:我参考别人编写的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 = True Then       '超时       GoTo err     End If          '从缓冲区里取值,并把缓冲区清空     ll = sio_read(PlcPort, ReturnStr, aa)     If ll <> 1 Then        GoTo err     End If '   Data61 = Val("&H" & Mid(ReturnStr, 6, 1))    If Asc(Mid(ReturnStr, 1, 1)) <> 6 Then          ?是否是确认收到数据(ACK)?      GoTo err    End If     '   aa = sio_close(PlcPort)    ForcingM = True    Exit Function  err:  '  sio_close (PlcPort)    End Function 工控搜索  查找 PLC 工控搜索  查找 三菱 工控搜索  查找 三菱PLC

顶部
[广告]
 


Google

当前时区 GMT+8, 现在时间是 2008-9-7 13:13
粤ICP备07500170号

By Discuz! 5.5.0 © 2007-2008
Processed in 0.052202 second(s), 6 queries , Gzip enabled

清除 Cookies - 联系我们 - Autooo! Inc. - Archiver - 繁体中文