RSS
当前位置 :| 主页>编程实例>

S7-200自由口通讯VB程序

来源: 作者: 时间:2007-10-16 Tag: 点击:

End Sub

Private Sub Form_Load()
   Instruction = &H11
   Address_R = "0100"
   Address_W = "0100"
   Address_B = "0100"
   Bit = "00"
   Lenth = 2
   SetLenth = 2
   MSComm1.CommPort = 1
   MSComm1.Settings = "9600,n,8,1"
   MSComm1.PortOpen = True
    If (Err) Then
       MsgBox "端口打开错误", vbOKOnly, "系统信息"
    End If
   MSComm1.RThreshold = 20
   MSComm1.InputMode = 1
   MSComm1.InBufferCount = 0
End Sub



Private Sub MSComm1_OnComm()
  Dim Temp() As Byte
  Dim Read(0 To 32) As Byte
  Dim BBC As Byte
  Dim XorByte As Byte
  Dim BBC_Temp As Byte
  Dim Value As Double
  Dim Trans(1 To 8) As Byte
  Dim TransValue As Double
 
  Value = 0
  XorByte = 0
  Temp = MSComm1.Input

字串9


  If ReadPlc = True Then
 
  If Temp(LBound(Temp)) = 103 And Temp(LBound(Temp) + 1) = 1 Then         '如果起始正确
     
      For i = 0 To 20
        Read(i) = Temp(i)
      Next i
     
      For i = 2 To 17                     '计算校验码
         XorByte = XorByte Xor Read(i)
      Next i
     
      For i = 2 To 19
        If Read(i) > &H40 Then
           Read(i) = Read(i) - &H37
        Else
           Read(i) = Read(i) - &H30 字串4
        End If
      Next
      BBC_Temp = Read(19) + Read(18) * &H10
      If XorByte = BBC_Temp Then
     
        For i = 2 To Lenth * 2 + 1
         
          Value = Value * &H10 + Read(i)
        Next i
      Text3.Text = Value
      End If
  End If
  Else
     If Temp(0) = 103 And Temp(1) = 2 Then
       MsgBox "参数设定成功", vbOKOnly, "系统提示"
     End If
  End If
End Sub
字串8


上一页 1 2 3 4 5下一页
Google
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册