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

📄 form1.frm

📁 getmywish结合visual basic60和msdn帮助
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   8445
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   9750
   LinkTopic       =   "Form1"
   ScaleHeight     =   8445
   ScaleWidth      =   9750
   StartUpPosition =   3  '窗口缺省
   Begin MSCommLib.MSComm Comm2 
      Left            =   5760
      Top             =   2280
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      CommPort        =   2
      DTREnable       =   -1  'True
      InputLen        =   1
      RThreshold      =   1
   End
   Begin VB.TextBox Text6 
      Height          =   270
      Left            =   1440
      TabIndex        =   21
      Text            =   "Text6"
      Top             =   1200
      Width           =   4695
   End
   Begin VB.TextBox Text5 
      Height          =   270
      Left            =   1440
      TabIndex        =   19
      Text            =   "Text5"
      Top             =   720
      Width           =   2655
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   2040
      TabIndex        =   16
      Text            =   "Text1"
      Top             =   120
      Width           =   855
   End
   Begin VB.CommandButton Command1 
      Caption         =   "开始采集"
      Height          =   375
      Left            =   3600
      TabIndex        =   15
      Top             =   120
      Width           =   1095
   End
   Begin MSCommLib.MSComm Comm1 
      Left            =   2880
      Top             =   2160
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
      InputLen        =   1
      RThreshold      =   1
   End
   Begin VB.Timer Timer1 
      Left            =   4320
      Top             =   2160
   End
   Begin VB.TextBox Text4 
      Height          =   375
      Left            =   1680
      TabIndex        =   13
      Text            =   "Text4"
      Top             =   1680
      Width           =   1335
   End
   Begin VB.TextBox Text3 
      Height          =   270
      Index           =   7
      Left            =   5040
      TabIndex        =   9
      Text            =   "Text3"
      Top             =   3960
      Width           =   1095
   End
   Begin VB.TextBox Text3 
      Height          =   270
      Index           =   6
      Left            =   3480
      TabIndex        =   8
      Text            =   "Text3"
      Top             =   3960
      Width           =   1095
   End
   Begin VB.TextBox Text3 
      Height          =   270
      Index           =   5
      Left            =   1920
      TabIndex        =   7
      Text            =   "Text3"
      Top             =   3960
      Width           =   1095
   End
   Begin VB.TextBox Text3 
      Height          =   270
      Index           =   4
      Left            =   360
      TabIndex        =   6
      Text            =   "Text3"
      Top             =   3960
      Width           =   1095
   End
   Begin VB.TextBox Text3 
      Height          =   270
      Index           =   3
      Left            =   5040
      TabIndex        =   5
      Text            =   "Text3"
      Top             =   3000
      Width           =   1095
   End
   Begin VB.TextBox Text3 
      Height          =   270
      Index           =   2
      Left            =   3480
      TabIndex        =   4
      Text            =   "Text3"
      Top             =   3000
      Width           =   1095
   End
   Begin VB.TextBox Text3 
      Height          =   270
      Index           =   1
      Left            =   1920
      TabIndex        =   3
      Text            =   "Text3"
      Top             =   3000
      Width           =   1095
   End
   Begin VB.TextBox Text3 
      Height          =   270
      Index           =   0
      Left            =   360
      TabIndex        =   2
      Text            =   "Text3"
      Top             =   3000
      Width           =   1095
   End
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   4440
      TabIndex        =   1
      Text            =   "Text2"
      Top             =   1680
      Width           =   1335
   End
   Begin VB.Label Label9 
      Caption         =   "Label9"
      Height          =   735
      Left            =   5160
      TabIndex        =   23
      Top             =   240
      Width           =   1215
   End
   Begin VB.Label Label8 
      Caption         =   "Label8"
      Height          =   495
      Left            =   3480
      TabIndex        =   22
      Top             =   3360
      Width           =   2775
   End
   Begin VB.Label Label7 
      Caption         =   "接收命令:"
      Height          =   255
      Index           =   1
      Left            =   360
      TabIndex        =   20
      Top             =   1200
      Width           =   975
   End
   Begin VB.Label Label7 
      Caption         =   "输出命令:"
      Height          =   255
      Index           =   0
      Left            =   360
      TabIndex        =   18
      Top             =   720
      Width           =   975
   End
   Begin VB.Label Label1 
      Caption         =   "模块地址:"
      Height          =   255
      Left            =   960
      TabIndex        =   17
      Top             =   240
      Width           =   975
   End
   Begin VB.Label Label3 
      Caption         =   "出错次数:"
      Height          =   255
      Left            =   3360
      TabIndex        =   14
      Top             =   1800
      Width           =   975
   End
   Begin VB.Label Label6 
      Caption         =   "采集次数:"
      Height          =   255
      Left            =   360
      TabIndex        =   12
      Top             =   1800
      Width           =   1095
   End
   Begin VB.Label Label5 
      Caption         =   "channel 4-7"
      Height          =   255
      Left            =   360
      TabIndex        =   11
      Top             =   3600
      Width           =   1815
   End
   Begin VB.Label Label4 
      Caption         =   "channel 0-3"
      Height          =   255
      Left            =   360
      TabIndex        =   10
      Top             =   2760
      Width           =   1815
   End
   Begin VB.Label Label2 
      Caption         =   "采集数据:"
      Height          =   255
      Left            =   360
      TabIndex        =   0
      Top             =   2400
      Width           =   975
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim cmdstring As String
Dim ChannelData(7) As Single
Dim ModuleAddress As Integer
Dim Instring2
Dim Instring1
Dim LRC As String
Dim cmdstring2 As String
Dim start
Dim stopbiao
Dim enq
Dim ans
Dim nok



Private Sub Comm1_Oncomm()
    Static ErrorTimes As Long
    Dim ReceiveString  As String
    Dim i As Integer
    Dim LRC_Test As String
    Dim temp As Long
Select Case Comm1.CommEvent
    Case comEvReceive
    ReceiveString = Comm1.Input
    Instring1 = Instring1 + ReceiveString
       If ReceiveString = Chr$(10) Then
           If (Mid(Instring1, 4, 2) = "04") Then
           Label9.Caption = "受到"
    Text6.Text = Instring1
    End If
    End If
    
    For i = 0 To 7
        ChannelData(i) = Val("&H" + Mid(ReceiveString, 8 + 4 * i, 4)) / 10
        Text3(i).Text = ChannelData(i)
    Next i
    
    'LRC check
    For i = 0 To 18
        temp = temp - Val("&H" + Mid(ReceiveString, 2 + 2 * i, 2))
    Next i
    
    LRC_Test = Right(Hex$(temp), 2)
    If (LRC_Test <> Mid(ReceiveString, 40, 2)) Then
        ErrorTimes = ErrorTimes + 1
    End If
    Text2.Text = ErrorTimes
    End Select
    


End Sub

Private Sub Comm2_OnComm()
'Static ErrorTimes As Long
    Dim ReceiveString2  As String
    Dim i2 As Integer
    Dim LRC_Test2 As String
    Dim temp2 As Long
    Dim Instrin2 As String
Select Case Comm2.CommEvent
    Case comEvReceive
        ReceiveString2 = Comm2.Input
        Instring2 = Instring2 + ReceiveString2
       If ReceiveString2 = Chr$(10) Then
           If (Mid(Instring2, 4, 2) = "04") Then
           Label8.Caption = "04"
    'cmdstring2 = ":" + "43" + "043344334433443344" + "BB" + Chr$(13) + Chr$(10)
     cmdstring2 = ":430400000008B" + Chr$(13) + Chr$(10)
':430400000008B1
Comm2.Output = cmdstring2
         '  Timer2.Enabled = True
           
       Label8.Caption = "09"
           
           
           End If
           

   End If
   ' ReceiveString2 = Comm2.Input
   ' Label8.Caption = ReceiveString2
    
'    For i2 = 0 To 7
'        ChannelData(i) = Val("&H" + Mid(ReceiveString2, 8 + 4 * i, 4)) / 10
'        Text3(i).Text = ChannelData(i)
'    Next i
'
'    'LRC check
'    For i = 0 To 18
'        temp = temp - Val("&H" + Mid(ReceiveString, 2 + 2 * i, 2))
'    Next i
'
'    LRC_Test = Right(Hex$(temp), 2)
'    If (LRC_Test <> Mid(ReceiveString, 40, 2)) Then
'        ErrorTimes = ErrorTimes + 1
'    End If
'    Text2.Text = ErrorTimes
End Select

End Sub

Private Sub Command1_Click()
    Dim temp As Integer
    start = ":"
    enq = "04"
    ModuleAddress = Val(Text1.Text)
    temp = -(ModuleAddress + 4 + 8)
    LRC = Right("00" + Hex$(temp), 2)
    'cmdstring = ":" + Right("0" + Hex$(ModuleAddress), 2) + "0400000008" + LRC + Chr$(13) + Chr$(10)
    cmdstring = start + Right("0" + Hex$(ModuleAddress), 2) + enq + "00000008" + LRC + Chr$(13) + Chr$(10)
    Text5.Text = cmdstring
    
    Timer1.Enabled = True
    
End Sub

Private Sub Form_Load()
    Dim i As Integer
    
    ModuleAddress = 67
    Timer1.Interval = 2000
    Timer1.Enabled = False
    Comm1.CommPort = 1
    Comm1.Settings = "9600,N,8,1"
    Comm2.CommPort = 2
    Comm2.Settings = "9600,N,8,1"
    Text1.Text = ModuleAddress
    Text2.Text = ""
    Text4.Text = ""
    Text5.Text = ""
    Text6.Text = ""
    For i = 0 To 7
        Text3(i).Text = ""
    Next i
     If Comm1.PortOpen = False Then
        Comm1.PortOpen = True
    End If
    Comm1.Output = cmdstring
    Comm1.InBufferCount = 0
   ' Comm1.RThreshold = 43
   ' Comm2.OutBufferCount = 0
                
    If Comm2.PortOpen = False Then
       Comm2.PortOpen = True
End If
    
    Comm2.InBufferCount = 0
  ' Comm2.RThreshold = 43
        
End Sub


Private Sub Timer1_Timer()
    Static gettimes As Long
        
    Comm1.OutBufferCount = 0
                
   ' If Comm1.PortOpen = False Then
      '  Comm1.PortOpen = True
   'End If
    Comm1.Output = cmdstring
   Comm1.InBufferCount = 0
   ' Comm1.RThreshold = 43
   ' Comm2.OutBufferCount = 0
                
   ' If Comm2.PortOpen = False Then
      '  Comm2.PortOpen = True
    'End If
    
  '  Comm2.InBufferCount = 0
   ' Comm2.RThreshold = 43
    gettimes = gettimes + 1
    Text4.Text = Str(gettimes)
    
End Sub

Private Sub Timer2_Timer()
  Comm2.OutBufferCount = 0
                
   ' If Comm1.PortOpen = False Then
      '  Comm1.PortOpen = True
   'End If
    Comm2.Output = cmdstring2
   Comm2.InBufferCount = 0
End Sub

⌨️ 快捷键说明

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