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

📄 main.frm

📁 这是vb用控件的写的串口程序
💻 FRM
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form main 
   BackColor       =   &H00C0C0C0&
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "七台河煤炭管理调试软件"
   ClientHeight    =   4305
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8775
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4305
   ScaleWidth      =   8775
   StartUpPosition =   2  '屏幕中心
   Begin MSDataGridLib.DataGrid DataGrid1 
      Bindings        =   "main.frx":0000
      Height          =   3615
      Left            =   0
      TabIndex        =   8
      Top             =   0
      Width           =   8775
      _ExtentX        =   15478
      _ExtentY        =   6376
      _Version        =   393216
      HeadLines       =   1
      RowHeight       =   15
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   2052
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   2052
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin VB.Timer Timer1 
      Interval        =   1000
      Left            =   1920
      Top             =   1800
   End
   Begin VB.CommandButton Command7 
      Caption         =   "串口设置"
      Height          =   375
      Left            =   6360
      TabIndex        =   7
      Top             =   3600
      Width           =   1215
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   3480
      Top             =   1920
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      CommPort        =   2
      DTREnable       =   -1  'True
      InputMode       =   1
   End
   Begin MSComctlLib.StatusBar StatusBar1 
      Align           =   2  'Align Bottom
      Height          =   345
      Left            =   0
      TabIndex        =   6
      Top             =   3960
      Width           =   8775
      _ExtentX        =   15478
      _ExtentY        =   609
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   4
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Style           =   6
            TextSave        =   "2005-12-5"
         EndProperty
         BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Style           =   5
            TextSave        =   "11:30"
            Object.ToolTipText     =   "个"
         EndProperty
         BeginProperty Panel4 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   2893
            MinWidth        =   2893
            Text            =   "欢迎使用本系统"
            TextSave        =   "欢迎使用本系统"
         EndProperty
      EndProperty
   End
   Begin VB.CommandButton Command6 
      Caption         =   "退  出"
      Height          =   375
      Left            =   7560
      TabIndex        =   5
      Top             =   3600
      Width           =   1215
   End
   Begin VB.CommandButton Command5 
      Caption         =   "切换到安装模式"
      Height          =   375
      Left            =   0
      TabIndex        =   4
      Top             =   3600
      Width           =   1575
   End
   Begin VB.CommandButton Command4 
      Caption         =   "清空显示"
      Height          =   375
      Left            =   5160
      TabIndex        =   3
      Top             =   3600
      Width           =   1215
   End
   Begin VB.CommandButton Command3 
      Caption         =   "连续查询"
      Height          =   375
      Left            =   3960
      TabIndex        =   2
      Top             =   3600
      Width           =   1215
   End
   Begin VB.CommandButton Command2 
      Caption         =   "单次查询"
      Height          =   375
      Left            =   2760
      TabIndex        =   1
      Top             =   3600
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "校准时钟"
      Height          =   375
      Left            =   1560
      TabIndex        =   0
      Top             =   3600
      Width           =   1215
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   615
      Left            =   4680
      Top             =   1920
      Visible         =   0   'False
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   1085
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\dat\dat.mdb;Persist Security Info=False"
      OLEDBString     =   "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\dat\dat.mdb;Persist Security Info=False"
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   "select time,red,tramroad,su1,su2 from lan"
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
End
Attribute VB_Name = "main"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim msreadbuff() As Byte
Dim sysren As Byte


Private Sub Command1_Click()
Dim mscombuff(13) As Byte
Dim yy As Integer
Dim x, i As Byte                     '设置时钟
mscombuff(0) = &H68
mscombuff(1) = &H33
mscombuff(2) = &H1
mscombuff(3) = &H8
yy = Year(Now)
x = yy / 100
mscombuff(4) = x
x = yy Mod 100
mscombuff(5) = x
x = Month(Now)
i = x / 16
i = i * 16
x = x Mod 10
i = i + x
mscombuff(6) = i
i = Day(Now)
i = x / 16
i = i * 16
x = x Mod 10
i = i + x
mscombuff(7) = i
mscombuff(8) = 0
i = Hour(Now)
i = x / 16
i = i * 16
x = x Mod 10
i = i + x
mscombuff(9) = i
i = Minute(Now)
i = x / 16
i = i * 16
x = x Mod 10
i = i + x
mscombuff(10) = i
i = Second(Now)
i = x / 16
i = i * 16
x = x Mod 10
i = i + x
mscombuff(11) = i
x = 0
For i = 3 To 11
    x = x + mscombuff(i)
Next i
x = x Mod 256
mscombuff(12) = x
mscombuff(13) = &H10
Me.MSComm1.Output = mscombuff
Sleep (100)
msreadbuff = Me.MSComm1.Input
yy = UBound(msreadbuff)
If yy = 4 Then
    If msreadbuff(0) = &H68 And msreadbuff(1) = &H31 And msreadbuff(2) = &HE0 And msreadbuff(3) = &H79 And msreadbuff(4) = &H10 Then
        Me.StatusBar1.Panels(1) = "时钟传递成功"
    End If
Else
    Me.StatusBar1.Panels(1) = "时钟传递失败"
End If
End Sub

Private Sub Command2_Click()
Dim bl, i As Integer
Dim mscombuff(4) As Byte             '单次查询
Dim timess As String
mscombuff(0) = &H68
mscombuff(1) = &H31
mscombuff(2) = 2
mscombuff(3) = &H9B
mscombuff(4) = &H10
Me.MSComm1.Output = mscombuff
Sleep (80)
msreadbuff() = Me.MSComm1.Input
bl = UBound(msreadbuff) '返回数组的最大下标
If bl = 15 Then
    Me.Adodc1.Recordset.AddNew
    Me.Adodc1.Recordset.Fields("red") = msreadbuff(4)
    Me.Adodc1.Recordset.Fields("tramroad") = msreadbuff(5)
    Me.Adodc1.Recordset.Fields("su1") = msreadbuff(6)
    Me.Adodc1.Recordset.Fields("su2") = msreadbuff(7)
    timess = msreadbuff(8)
    For i = 9 To 13
        timess = timess + msreadbuff(i)
    Next i
    Me.Adodc1.Recordset.Fields("time") = timess
    Me.Adodc1.Recordset.Update
    Me.StatusBar1.Panels(1) = "操作成功"
Else
    Me.StatusBar1.Panels(1) = "操作失败"
End If
End Sub

Private Sub Command3_Click()
If Me.Timer1.Enabled Then
    Me.Timer1.Enabled = False         '连续查询
    Me.Command3.Caption = "连续读取"
    Me.Command2.Enabled = True
Else
    Me.Timer1.Enabled = True
    Me.Command3.Caption = "停止读取"
    Me.Command2.Enabled = False
End If
End Sub

Private Sub Command4_Click()
Dim i, l As Integer                       '清空显示
Me.Adodc1.Refresh
l = Me.Adodc1.Recordset.RecordCount
Me.Adodc1.Recordset.MoveFirst
For i = 1 To l
    Me.Adodc1.Recordset.Delete
    Me.Adodc1.Recordset.MoveNext
Next i
Me.Adodc1.Recordset.Update
End Sub

Private Sub Command5_Click()
Dim mscombuff(4) As Byte
Dim yy As Integer
If sysren = 0 Then
    sysren = 1
    Command5.Caption = "切换到正常模式"
    Me.Command2.Enabled = False
    Me.Command3.Enabled = False
    mscombuff(0) = &H68
    mscombuff(1) = &H31
    mscombuff(2) = 3
    mscombuff(3) = &H9C
    mscombuff(4) = &H10
Else
    sysren = 0
    Command5.Caption = "切换到安装模式"
    Me.Command2.Enabled = True
    Me.Command3.Enabled = True
    mscombuff(0) = &H68
    mscombuff(1) = &H31
    mscombuff(2) = 4
    mscombuff(3) = &H9D
    mscombuff(4) = &H10
End If
Me.MSComm1.Output = mscombuff
Sleep (40)
msreadbuff = Me.MSComm1.Input
yy = UBound(msreadbuff)
If yy = 4 Then
    If msreadbuff(0) = &H68 And msreadbuff(1) = &H31 And msreadbuff(2) = &HE0 And msreadbuff(3) = &H79 And msreadbuff(4) = &H10 Then
        Me.StatusBar1.Panels(1) = "转换成功"
    End If
Else
    Me.StatusBar1.Panels(1) = "转换失败"
End If
End Sub

Private Sub Command6_Click()
Unload Me
End Sub

Private Sub Command7_Click()
comset.Show
End Sub

Private Sub Form_Load()
Me.Timer1.Enabled = False
Me.StatusBar1.Panels(1) = "空闲状态"
sysren = 0
cldat = 0
Me.MSComm1.PortOpen = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
Unload comset
Me.MSComm1.PortOpen = False
End Sub

Private Sub Timer1_Timer()
Call Command2_Click
End Sub

⌨️ 快捷键说明

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