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

📄 write_frm.frm

📁 西门子 通信程序 vb与西门子PLc通讯程序源码
💻 FRM
字号:
VERSION 5.00
Begin VB.Form WRITE_FRM 
   Caption         =   "SCHREIBEN/WRITE"
   ClientHeight    =   5355
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7440
   LinkTopic       =   "Form1"
   ScaleHeight     =   5355
   ScaleWidth      =   7440
   StartUpPosition =   3  'Windows-Standard
   Begin VB.Frame Frame1 
      Caption         =   "data type"
      Height          =   3855
      Left            =   120
      TabIndex        =   16
      Top             =   240
      Width           =   3375
      Begin VB.OptionButton IDDATATYPE 
         Caption         =   "Eingang/Input"
         Enabled         =   0   'False
         Height          =   255
         Index           =   0
         Left            =   360
         TabIndex        =   24
         Top             =   600
         Width           =   2895
      End
      Begin VB.OptionButton IDDATATYPE 
         Caption         =   "Ausgang/Output"
         Height          =   255
         Index           =   1
         Left            =   360
         TabIndex        =   23
         Top             =   960
         Width           =   2895
      End
      Begin VB.OptionButton IDDATATYPE 
         Caption         =   "Merker/Flag"
         Height          =   255
         Index           =   2
         Left            =   360
         TabIndex        =   22
         Top             =   1320
         Width           =   2895
      End
      Begin VB.OptionButton IDDATATYPE 
         Caption         =   "Timer"
         Enabled         =   0   'False
         Height          =   255
         Index           =   3
         Left            =   360
         TabIndex        =   21
         Top             =   1680
         Width           =   2895
      End
      Begin VB.OptionButton IDDATATYPE 
         Caption         =   "Z鋒ler/Counter"
         Height          =   255
         Index           =   4
         Left            =   360
         TabIndex        =   20
         Top             =   2040
         Width           =   2895
      End
      Begin VB.OptionButton IDDATATYPE 
         Caption         =   "Sondermerker/Special flag"
         Height          =   255
         Index           =   5
         Left            =   360
         TabIndex        =   19
         Top             =   2400
         Width           =   2895
      End
      Begin VB.OptionButton IDDATATYPE 
         Caption         =   "Variablenspeicher/Variable Memory"
         Height          =   255
         Index           =   6
         Left            =   360
         TabIndex        =   18
         Top             =   2760
         Width           =   2895
      End
      Begin VB.OptionButton IDDATATYPE 
         Caption         =   "Datenbaustein/Datablock"
         Height          =   255
         Index           =   7
         Left            =   360
         TabIndex        =   17
         Top             =   3120
         Width           =   2895
      End
   End
   Begin VB.CommandButton IDWRITE 
      Caption         =   "schreiben/write"
      Height          =   375
      Left            =   5040
      TabIndex        =   15
      Top             =   4560
      Width           =   1455
   End
   Begin VB.CommandButton IDCANCEL 
      Caption         =   "zur點k/cancel"
      Height          =   375
      Left            =   240
      TabIndex        =   14
      Top             =   4560
      Width           =   1335
   End
   Begin VB.Frame Frame4 
      BackColor       =   &H00C0C0C0&
      Caption         =   "Verbindung/connection"
      Height          =   615
      Left            =   3600
      TabIndex        =   9
      Top             =   240
      Width           =   3375
      Begin VB.OptionButton VERB 
         Caption         =   "4"
         Height          =   255
         Index           =   3
         Left            =   2040
         TabIndex        =   13
         Top             =   240
         Width           =   495
      End
      Begin VB.OptionButton VERB 
         Caption         =   "3"
         Height          =   255
         Index           =   2
         Left            =   1440
         TabIndex        =   12
         Top             =   240
         Width           =   495
      End
      Begin VB.OptionButton VERB 
         Caption         =   "2"
         Height          =   255
         Index           =   1
         Left            =   840
         TabIndex        =   11
         Top             =   240
         Width           =   495
      End
      Begin VB.OptionButton VERB 
         Caption         =   "1"
         Height          =   255
         Index           =   0
         Left            =   360
         TabIndex        =   10
         Top             =   240
         Width           =   495
      End
   End
   Begin VB.Frame Frame3 
      Height          =   1335
      Left            =   3600
      TabIndex        =   4
      Top             =   1080
      Width           =   3375
      Begin VB.TextBox IDBLOCKNO 
         Height          =   285
         Left            =   1920
         TabIndex        =   6
         Top             =   240
         Width           =   975
      End
      Begin VB.TextBox IDNO 
         Height          =   285
         Left            =   1920
         TabIndex        =   5
         Top             =   600
         Width           =   975
      End
      Begin VB.Label Label1 
         Caption         =   "DB Nr/Datablok "
         Height          =   255
         Left            =   480
         TabIndex        =   8
         Top             =   240
         Width           =   1215
      End
      Begin VB.Label Label2 
         Caption         =   "nummer/no"
         Height          =   255
         Left            =   480
         TabIndex        =   7
         Top             =   600
         Width           =   1455
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Wert/value"
      Height          =   1455
      Left            =   3600
      TabIndex        =   0
      Top             =   2640
      Width           =   3375
      Begin VB.TextBox ID_VALUE 
         Height          =   375
         Left            =   240
         TabIndex        =   25
         Top             =   360
         Width           =   1575
      End
      Begin VB.OptionButton IDOUTPUT 
         Caption         =   "hex"
         Height          =   255
         Index           =   0
         Left            =   2400
         TabIndex        =   3
         Top             =   240
         Width           =   855
      End
      Begin VB.OptionButton IDOUTPUT 
         Caption         =   "decimal"
         Height          =   255
         Index           =   1
         Left            =   2400
         TabIndex        =   2
         Top             =   600
         Width           =   855
      End
      Begin VB.OptionButton IDOUTPUT 
         Caption         =   "binary"
         Height          =   255
         Index           =   2
         Left            =   2400
         TabIndex        =   1
         Top             =   960
         Width           =   855
      End
   End
End
Attribute VB_Name = "WRITE_FRM"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Function binstr2value(s As String) As Long
Dim v As Long
Dim w As Long
Dim i, j As Long

v = 0
w = 1

j = Len(s)
For i = 1 To j
    If (Mid$(s, i, 1) = "1") Then v = v Or w
    w = w * 2
Next i
binstr2value = v
End Function
Private Sub GetValue()
Dim msg

On Error GoTo error_handler

Select Case OutputTypeIdx
Case 0
    If ((DataTypeIdx = 3) Or (DataTypeIdx = 4)) Then
        value_word(0) = Val("&H" + ID_VALUE.Text)
    Else
        value_byte(0) = Val("&H" + ID_VALUE.Text)
    End If
        
Case 1
    If ((DataTypeIdx = 3) Or (DataTypeIdx = 4)) Then
        value_word(0) = ID_VALUE.Text
    Else
        value_byte(0) = ID_VALUE.Text
    End If

Case 2
    str = ID_VALUE.Text
    If ((DataTypeIdx = 3) Or (DataTypeIdx = 4)) Then
        value_word(0) = binstr2value(str)
    Else
        value_byte(0) = binstr2value(str)
    End If
End Select

Exit Sub

error_handler:
msg = "value not correct"
MsgBox msg
Resume Next

End Sub

Private Sub ShowValue()
Dim i, j, k As Long
Dim s As String
Dim s1 As String


AMOUNT = 1
For i = 0 To (AMOUNT - 1)
    s = ""
    
    If ((DataTypeIdx = 3) Or (DataTypeIdx = 4)) Then
        Select Case OutputTypeIdx
        Case 0
            s1 = Hex(value_word(i))
        Case 1
            s1 = value_word(i)
        Case 2
            j = 1
            s1 = ""
            While (j < 65536)
                k = j And value_word(i)
                If (k <> 0) Then
                    s1 = s1 + "1"
                    Else
                    s1 = s1 + "0"
                End If
                j = j * 2
            Wend
        End Select
    Else
        Select Case OutputTypeIdx
        Case 0
            s1 = Hex(value_byte(i))
        Case 1
            s1 = value_byte(i)
        Case 2
            j = 1
            s1 = ""
            While (j < 256)
                k = j And value_byte(i)
                If (k <> 0) Then
                    s1 = s1 + "1"
                    Else
                    s1 = s1 + "0"
                End If
                j = j * 2
            Wend
        
        End Select
    
    End If
    s = s + s1
    ID_VALUE.Text = (s)

Next i


End Sub

Private Sub Form_Activate()
VERB(VerbIdx).value = True
IDOUTPUT(OutputTypeIdx).value = True

If (DataTypeIdx = 0) Then DataTypeIdx = 1
IDDATATYPE(DataTypeIdx).value = True
ID_VALUE.Text = 0

IDBLOCKNO.Text = BLOCKNO
IDNO.Text = no
End Sub


Private Sub IDBLOCKNO_Change()
Dim msg

On Error GoTo error_handler
BLOCKNO = IDBLOCKNO.Text
Exit Sub

error_handler:
IDBLOCKNO.Text = BLOCKNO
msg = "value not correct"
MsgBox msg
Resume Next
End Sub

Private Sub IDDATATYPE_Click(Index As Integer)
DataTypeIdx = Index
End Sub

Private Sub IDCANCEL_Click()
WRITE_FRM.Visible = False
End Sub

Private Sub IDNO_Change()
Dim msg

On Error GoTo error_handler
no = IDNO.Text
Exit Sub

error_handler:
IDNO.Text = no
msg = "value not correct"
MsgBox msg
Resume Next

End Sub

Private Sub IDOUTPUT_Click(Index As Integer)
OutputTypeIdx = Index

Call ShowValue
End Sub


Private Sub IDWRITE_Click()
Dim i, j, k As Long
Dim s As String
Dim s1 As String


Call GetValue
AMOUNT = 1
res = new_ss(VerbIdx + 1)
If (res = 0) Then
Select Case DataTypeIdx
    Case 0
        res = 33028
    Case 1
#If S7_200 Then
        res = as200_a_field_write(no, AMOUNT, value_byte(0))
#End If
#If S7_300 Then
        res = a_field_write(no, AMOUNT, value_byte(0))
#End If
    Case 2
#If S7_200 Then
        res = as200_m_field_write(no, AMOUNT, value_byte(0))
#End If
#If S7_300 Then
        res = m_field_write(no, AMOUNT, value_byte(0))
#End If
    Case 3
        res = 33028
    Case 4
#If S7_200 Then
        res = as200_z_field_write(no, AMOUNT, value_word(0))
#End If
#If S7_300 Then
        Call swab_buffer(value_word(0), 512)
        res = z_field_write(no, AMOUNT, value_word(0))
        Call swab_buffer(value_word(0), 512)
#End If
    Case 5
#If S7_200 Then
        res = as200_sm_field_write(no, AMOUNT, value_byte(0))
#End If
#If S7_300 Then
        res = 33028
#End If
        res = 33028
    Case 6
#If S7_200 Then
        res = as200_vs_field_write(no, AMOUNT, value_byte(0))
#End If
#If S7_300 Then
        res = 33028
#End If
    Case 7
#If S7_200 Then
        res = 33028
#End If
#If S7_300 Then
        res = d_field_write(BLOCKNO, no, AMOUNT, value_byte(0))
#End If
End Select
End If

Call ShowValue

If (res <> 0) Then
   ERROR_FRM.Show 1, Me
End If

End Sub

Private Sub VERB_Click(Index As Integer)
VerbIdx = Index
End Sub

⌨️ 快捷键说明

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