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

📄 frmbitonoff.frm

📁 此为交通信号机
💻 FRM
字号:
VERSION 5.00
Begin VB.Form FrmBitOnOff 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "位强制开/关"
   ClientHeight    =   2355
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   3795
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2355
   ScaleWidth      =   3795
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command1 
      Caption         =   "返回"
      Height          =   495
      Left            =   1440
      TabIndex        =   6
      Top             =   1440
      Width           =   975
   End
   Begin VB.CommandButton CmdBitOff 
      Height          =   495
      Left            =   2640
      Picture         =   "FrmBitOnOff.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   1440
      Width           =   1095
   End
   Begin VB.CommandButton CmdBitOn 
      Height          =   495
      Left            =   120
      MouseIcon       =   "FrmBitOnOff.frx":0442
      Picture         =   "FrmBitOnOff.frx":0884
      Style           =   1  'Graphical
      TabIndex        =   2
      Top             =   1440
      Width           =   1095
   End
   Begin VB.TextBox TxtBitAddress 
      Height          =   375
      Left            =   1440
      TabIndex        =   1
      Top             =   480
      Width           =   1095
   End
   Begin VB.Label Label3 
      Caption         =   "关断"
      Height          =   255
      Left            =   2760
      TabIndex        =   5
      Top             =   1080
      Width           =   495
   End
   Begin VB.Label Label2 
      Caption         =   "开通"
      Height          =   255
      Left            =   480
      TabIndex        =   4
      Top             =   1080
      Width           =   495
   End
   Begin VB.Label Label1 
      Caption         =   "位地址:"
      Height          =   255
      Left            =   1680
      TabIndex        =   0
      Top             =   120
      Width           =   735
   End
End
Attribute VB_Name = "FrmBitOnOff"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub CmdBitOff_Click()
       Dim Sum As Integer
       Dim instring As String
       Dim sumstring As String
       Dim sumstring2 As String
       Dim time1
       
       
       '判断有无起始地址
         If TxtBitAddress.Text = "" Then
              response = MsgBox("无起始地址!", 48, title)
              TxtBitAddress.SetFocus
              GoTo end1:
          Else
         End If
         
       
       
        '将地址调整为4位
      If Len(TxtBitAddress.Text) <> 4 Then
            Select Case Len(TxtBitAddress.Text)
               Case 1
                   TxtBitAddress.Text = "0" + "0" + "0" + TxtBitAddress.Text
               Case 2
                   TxtBitAddress.Text = "0" + "0" + TxtBitAddress.Text
               Case 3
                   TxtBitAddress.Text = "0" + TxtBitAddress.Text
            End Select
       End If
       
       '地址和校验
       Sum = &H38
       For i = 1 To 4
       Sum = Sum + Asc(Mid(TxtBitAddress.Text, i, 1))
       Next i
       
      
       
      
       Sum = Sum + 3
       sumstring = Hex(Sum)
       sumstring2 = Right(sumstring, 2)
       
       
        
       FrmMain.MSComm1.PortOpen = True
       FrmMain.MSComm1.Output = Chr(&H2) + Chr(&H38)   'STX  CMD 8
       FrmMain.MSComm1.Output = TxtBitAddress.Text
       FrmMain.MSComm1.Output = Chr(3)            'ETX
       FrmMain.MSComm1.Output = sumstring2        'SUM
       
          '接收应答:
           time1 = Timer
           Do
           DoEvents
           Loop Until FrmMain.MSComm1.InBufferCount >= 1 Or (Timer - time1) > 10
           instring = FrmMain.MSComm1.Input
           
           If (Timer - time1) > 10 Then
               MsgBox "PLC没有响应!"
           Else
               If instring = Chr(6) Then
                  MsgBox "数据传输成功!"
               Else
                 If instring = Chr(&H15) Then
                  MsgBox "数据传输失败!请重试"
                 Else
                 End If
               End If
            End If
           FrmMain.MSComm1.PortOpen = False
end1:
       
End Sub

Private Sub CmdBitOn_Click()
       Dim Sum As Integer
       Dim instring As String
       Dim sumstring As String
       Dim sumstring2 As String
       Dim time1
       
       
       '判断有无起始地址
         If TxtBitAddress.Text = "" Then
              response = MsgBox("无起始地址!", 48, title)
              TxtBitAddress.SetFocus
              GoTo end1:
          Else
         End If
         
       
       
        '将地址调整为4位
      If Len(TxtBitAddress.Text) <> 4 Then
            Select Case Len(TxtBitAddress.Text)
               Case 1
                   TxtBitAddress.Text = "0" + "0" + "0" + TxtBitAddress.Text
               Case 2
                   TxtBitAddress.Text = "0" + "0" + TxtBitAddress.Text
               Case 3
                   TxtBitAddress.Text = "0" + TxtBitAddress.Text
            End Select
       End If
       
       '地址和校验
       Sum = &H37
       For i = 1 To 4
       Sum = Sum + Asc(Mid(TxtBitAddress.Text, i, 1))
       Next i
       
      
       
      
       Sum = Sum + 3
       sumstring = Hex(Sum)
       sumstring2 = Right(sumstring, 2)
       
       
        
       FrmMain.MSComm1.PortOpen = True
       FrmMain.MSComm1.Output = Chr(&H2) + Chr(&H37)   'STX  CMD 7
       FrmMain.MSComm1.Output = TxtBitAddress.Text
       FrmMain.MSComm1.Output = Chr(3)            'ETX
       FrmMain.MSComm1.Output = sumstring2        'SUM
       
          '接收应答:
           time1 = Timer
           Do
           DoEvents
           Loop Until FrmMain.MSComm1.InBufferCount >= 1 Or (Timer - time1) > 10
           instring = FrmMain.MSComm1.Input
           
           If (Timer - time1) > 10 Then
               MsgBox "PLC没有响应!"
           Else
               If instring = Chr(6) Then
                  MsgBox "数据传输成功!"
               Else
                 If instring = Chr(&H15) Then
                  MsgBox "数据传输失败!请重试"
                 Else
                 End If
               End If
            End If
           FrmMain.MSComm1.PortOpen = False
end1:
       
End Sub

Private Sub Command1_Click()
         FrmBitOnOff.Hide
End Sub

Private Sub Form_Load()
 
         Left = (Screen.Width - Width) / 2
         Top = (Screen.Height - Height) / 2
End Sub

Private Sub TxtBitAddress_Change()
    TxtBitAddress.Text = UCase(TxtBitAddress.Text)
End Sub

⌨️ 快捷键说明

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