⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frms7200com-1.frm

📁 VB与S7200的PPI通信
💻 FRM
📖 第 1 页 / 共 2 页
字号:
         Caption         =   "Mcon-On"
         Height          =   375
         Index           =   1
         Left            =   2040
         TabIndex        =   13
         Top             =   360
         Width           =   975
      End
      Begin VB.Label Label6 
         AutoSize        =   -1  'True
         Caption         =   "Mx   .y"
         Height          =   180
         Left            =   1200
         TabIndex        =   17
         Top             =   240
         Width           =   630
      End
   End
   Begin VB.Timer tmrRead 
      Enabled         =   0   'False
      Interval        =   1000
      Left            =   10680
      Top             =   2760
   End
   Begin MSCommLib.MSComm mscommPLC 
      Left            =   7680
      Top             =   360
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
      InBufferSize    =   512
   End
   Begin VB.CommandButton cmdWrite 
      Caption         =   "WriteAll"
      Height          =   375
      Left            =   240
      TabIndex        =   9
      Top             =   1560
      Width           =   975
   End
   Begin VB.TextBox Text1 
      Height          =   270
      Left            =   2160
      TabIndex        =   8
      Text            =   "250"
      Top             =   1132
      Width           =   855
   End
   Begin VB.ComboBox cobType 
      Height          =   300
      Left            =   720
      TabIndex        =   7
      Text            =   "Combo1"
      Top             =   240
      Width           =   2415
   End
   Begin VB.TextBox Text9 
      Height          =   270
      Left            =   2160
      TabIndex        =   3
      Text            =   "30"
      Top             =   645
      Width           =   855
   End
   Begin VB.TextBox Text2 
      Height          =   270
      Left            =   720
      TabIndex        =   1
      Text            =   "1000"
      Top             =   645
      Width           =   735
   End
   Begin VB.CommandButton cmdRead 
      Caption         =   "READ ALL"
      Height          =   375
      Left            =   240
      TabIndex        =   0
      Top             =   1080
      Width           =   975
   End
   Begin VB.TextBox Text3 
      Height          =   2295
      Left            =   3480
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   2
      Text            =   "FrmS7200Com-1.frx":F84A
      Top             =   240
      Width           =   7695
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "Label1"
      Height          =   180
      Left            =   240
      TabIndex        =   11
      Top             =   2040
      Width           =   540
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "Label2"
      Height          =   180
      Left            =   240
      TabIndex        =   10
      Top             =   2340
      Width           =   540
   End
   Begin VB.Label Label5 
      AutoSize        =   -1  'True
      Caption         =   "数据"
      Height          =   180
      Index           =   3
      Left            =   240
      TabIndex        =   6
      Top             =   300
      Width           =   360
   End
   Begin VB.Label Label5 
      AutoSize        =   -1  'True
      Caption         =   "地址"
      Height          =   180
      Index           =   0
      Left            =   240
      TabIndex        =   5
      Top             =   690
      Width           =   360
   End
   Begin VB.Label Label5 
      AutoSize        =   -1  'True
      Caption         =   "数量"
      Height          =   180
      Index           =   2
      Left            =   1560
      TabIndex        =   4
      Top             =   690
      Width           =   360
   End
End
Attribute VB_Name = "frmTest"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

'******************************************************************
'功能:读取西门子PPI协议
'编程:麻树波
'Email:msb.sf@163.com
'QQ:105714583
'这写代码 希望大家完善
'******************************************************************


Private Declare Sub Sleep Lib "kernel32" (ByVal dwseconds As Long)

Dim rcv_Data(110)        As Long
Dim rcv_array()          As Byte

Private Sub CmdReadVW_Click()
    Text3 = ""
    S7200_Vw_read mscommPLC, Text2, Text9
End Sub
Private Sub cmdWriteMbyte_Click()
    s7200_M_writebyte mscommPLC, txtM(0), txtM(1)
End Sub

Private Sub Command1_Click()
    tmrRead.Enabled = Not tmrRead.Enabled
    If tmrRead.Enabled Then Command1.Caption = "EN"
    If Not tmrRead.Enabled Then Command1.Caption = "disEN"
End Sub

Private Sub Form_Load()

    mscommPLC.CommPort = 1
    mscommPLC.Settings = "9600,e,8,1"
    mscommPLC.RThreshold = 1
    mscommPLC.InputMode = comInputModeBinary
    mscommPLC.PortOpen = True

    cobType.AddItem "vb"
    cobType.AddItem "vw"
    cobType.AddItem "vd"
    cobType.AddItem "v"
    cobType.AddItem "m"
    cobType.AddItem "mb"
    cobType.AddItem "sm"
    cobType.AddItem "i"
    cobType.AddItem "ib"
    cobType.AddItem "q"
    cobType.AddItem "qb"
    cobType.AddItem "s"
    cobType.ListIndex = 1

    Text3 = ""


End Sub

Private Sub cmdRead_Click()
    Dim Data_type        As String
    Dim Memo_type26      As String
    Dim Memo_type27      As String
    Dim read_len22       As String
    Dim dizhi            As String
    Dim DataC24          As String
    Dim str_read(0 To 32) As Byte
    Dim i                As Integer
    Dim Temp_FCS         As Variant
    Dim mm               As String
    Dim str_val(0 To 5)  As Byte

    dizhi = Text2.Text
    Data_type = cobType.Text
    DataC24 = "&H" & Hex(CStr(Text9))

    If Data_type = "s" Then
        Memo_type26 = &H0
        Memo_type27 = &H4
        read_len22 = &H1
    End If
    If Data_type = "sm" Then
        Memo_type26 = &H0
        Memo_type27 = &H5
        read_len22 = &H1
    End If
    If Data_type = "i" Then
        Memo_type26 = &H0
        Memo_type27 = &H81
        read_len22 = &H1
    End If
    If Data_type = "ib" Then
        Memo_type26 = &H0
        Memo_type27 = &H81
        read_len22 = &H2
    End If
    If Data_type = "q" Then
        Memo_type26 = &H0
        Memo_type27 = &H82
        read_len22 = &H1
    End If
    If Data_type = "qb" Then
        Memo_type26 = &H0
        Memo_type27 = &H82
        read_len22 = &H2
    End If
    If Data_type = "m" Then
        Memo_type26 = &H0
        Memo_type27 = &H83
        read_len22 = &H1
    End If
    If Data_type = "mb" Then
        Memo_type26 = &H0
        Memo_type27 = &H83
        read_len22 = &H2
    End If

    If Data_type = "v" Then
        Memo_type26 = &H1
        Memo_type27 = &H84
        read_len22 = &H1
    End If
    If Data_type = "vb" Then
        Memo_type26 = &H1
        Memo_type27 = &H84
        read_len22 = &H2

    End If
    If Data_type = "vw" Then
        Memo_type26 = &H1
        Memo_type27 = &H84
        read_len22 = &H4

    End If
    If Data_type = "vd" Then
        Memo_type26 = &H1
        Memo_type27 = &H84
        read_len22 = &H8
    End If

    str_read(0) = &H68
    str_read(1) = &H1B
    str_read(2) = &H1B
    str_read(3) = &H68
    str_read(4) = &H2
    str_read(5) = &H0
    str_read(6) = &H6C
    str_read(7) = &H32
    str_read(8) = &H1
    str_read(9) = &H0
    str_read(10) = &H0
    str_read(11) = &H0
    str_read(12) = &H0
    str_read(13) = &H0
    str_read(14) = &HE
    str_read(15) = &H0
    str_read(16) = &H0
    str_read(17) = &H4
    str_read(18) = &H1
    str_read(19) = &H12
    str_read(20) = &HA
    str_read(21) = &H10
    str_read(22) = read_len22
    str_read(23) = &H0
    str_read(24) = DataC24
    str_read(25) = &H0
    str_read(26) = Memo_type26
    str_read(27) = Memo_type27
    str_read(28) = &H0
    str_read(29) = (Str(dizhi) * 8) \ 256
    str_read(30) = (Str(dizhi) * 8) Mod 256

    For i = 4 To 30
        Temp_FCS = Temp_FCS + str_read(i)
    Next i
    str_read(31) = Temp_FCS Mod 256
    str_read(32) = &H16
    mscommPLC.Output = str_read


    Text3.Text = ""
    Comm_OK mscommPLC

End Sub

Private Sub mscommPLC_OnComm()

    Dim rcv_len          As Long
    Dim i                As Long
    Dim j                As Long
    Dim data_L           As String
    Dim data_H           As String

    '   Sleep (100)
    rcv_array = mscommPLC.Input
    rcv_len = UBound(rcv_array)

    If rcv_len >= 28 Then
        If rcv_array(0) = &H68 And rcv_array(rcv_len) = &H16 Then
            j = 0
            For i = 0 To rcv_array(16) - 5 Step 2          '获取数据
                data_L = Hex(rcv_array(25 + i + 1))
                data_H = Hex(rcv_array(25 + i))

                If Len(data_L) < 2 Then data_L = "0" & data_L
                rcv_Data(j) = Val("&H" + data_H + data_L)

                Text3.Text = Text3.Text & "VW" & Text2 + j & "=" & rcv_Data(j) & "  "
                j = j + 1
            Next
        End If

        If rcv_array(0) = &HE5 And rcv_array(rcv_len) = &H16 Then
            j = 0
            For i = 0 To rcv_array(17) - 5 Step 2          '获取数据
                data_L = Hex(rcv_array(26 + i + 1))
                data_H = Hex(rcv_array(26 + i))

                If Len(data_L) < 2 Then data_L = "0" & data_L
                rcv_Data(j) = Val("&H" + data_H + data_L)

                Text3.Text = Text3.Text & "VW" & Text2 + j & "=" & rcv_Data(j) & "  "
                j = j + 1
            Next
        End If

    End If

End Sub

Private Sub cmdWrite_Click()
    Dim mm()             As Long
    Dim i

    ReDim mm(Text9) As Long
    For i = 0 To Text9
        mm(i) = Int(Text1.Text) + i
        'Text4 = Text4 & mm(i) & "  "
    Next
    s7200_VW_WRITE mscommPLC, Text2.Text, Text9.Text, mm()

End Sub
Private Sub cmdMcon_Click(Index As Integer)
    s7200_M_set mscommPLC, txtM(0), txtM(1), CByte(Index)
End Sub



Private Sub tmrRead_Timer()
    Text3 = ""
    Dim i                As Long
    S7200_Vw_read mscommPLC, Text2, Text9
    For i = 0 To 31
        txtSj(i) = rcv_Data(i)
    Next
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -