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

📄 frmmain.frm

📁 Visual Basic串口通信技术与典型实例
💻 FRM
📖 第 1 页 / 共 2 页
字号:
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"
Begin VB.Form frmbaojing 
   Caption         =   "自动报警系统"
   ClientHeight    =   4485
   ClientLeft      =   165
   ClientTop       =   855
   ClientWidth     =   5280
   BeginProperty Font 
      Name            =   "宋体"
      Size            =   8.25
      Charset         =   134
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   ScaleHeight     =   4485
   ScaleWidth      =   5280
   StartUpPosition =   3  'Windows Default
   Begin MSCommLib.MSComm MSComm2 
      Left            =   2520
      Top             =   3480
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   360
      Top             =   3120
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.Timer Timer1 
      Left            =   1680
      Top             =   3840
   End
   Begin MSComctlLib.ImageList ImageList1 
      Left            =   3840
      Top             =   2880
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   32
      ImageHeight     =   32
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   5
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMain.frx":0000
            Key             =   "start"
            Object.Tag             =   "启动"
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMain.frx":0452
            Key             =   "stop"
            Object.Tag             =   "暂停"
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMain.frx":08A4
            Key             =   "set"
            Object.Tag             =   "设置"
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMain.frx":0CF6
            Key             =   "exit"
            Object.Tag             =   "退出"
         EndProperty
         BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmMain.frx":1148
            Key             =   "log"
            Object.Tag             =   "管理日志"
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.ListView lvwLog 
      Height          =   1095
      Left            =   120
      TabIndex        =   0
      Top             =   1320
      Width           =   2655
      _ExtentX        =   4683
      _ExtentY        =   1931
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      NumItems        =   0
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "当日报警记录:"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   9
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   180
      Left            =   120
      TabIndex        =   1
      Top             =   720
      Width           =   1260
   End
   Begin VB.Menu mnuOperate 
      Caption         =   "操作"
      Begin VB.Menu mnuOperateAct 
         Caption         =   "启动"
         Checked         =   -1  'True
         Shortcut        =   ^A
      End
      Begin VB.Menu mnuOperateSetting 
         Caption         =   "参数设置..."
         Shortcut        =   ^B
      End
      Begin VB.Menu mnuOperateMaglog 
         Caption         =   "日志管理..."
         Shortcut        =   ^M
      End
   End
   Begin VB.Menu mnuExit 
      Caption         =   "退出"
   End
End
Attribute VB_Name = "frmbaojing"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private mDbalert As Database      ' 模块级数据库变量
Private rslog As ADODB.Recordset  ' 记录集变量,打开记录集
Private mLogItem As ListItem      ' 模块级列表项变量
Private sysdate As Date           ' 记录系统时间,和now时间比较,显示当天日志
Private cntLog As Integer         ' 日志表记录总数
Private comInbf As Boolean        ' 布防设置里面是否使用串口
Private lptInbf As Boolean        ' 布防设置里面是否使用并口

Private strcj(100) As String      ' 记录函数分析出的多个字符串
Private lptPort() As String       ' 记录布防设置里面的并口号

Private Sub Form_Load()
   Me.Left = GetSetting(App.Title, "Settings", "MainLeft", 1000)
   Me.Top = GetSetting(App.Title, "Settings", "MainTop", 1000)
   Me.Width = GetSetting(App.Title, "Settings", "MainWidth", 6500)
   Me.Height = GetSetting(App.Title, "Settings", "MainHeight", 6500)
   Me.WindowState = 2 '窗口最大化
    
   Call Init '系统初始化
End Sub

Private Sub Form_Resize()
   
   If Me.WindowState <> vbMinimized Then
       lvwLog.Width = Me.ScaleWidth * 0.98
       lvwLog.Height = Me.ScaleHeight - Label1.Top - Label1.Height * 2
       lvwLog.Left = (Me.Width - lvwLog.Width) \ 2.6
       lvwLog.Top = Label1.Top + Label1.Height * 1.5
       Label1.Left = lvwLog.Left
   End If
   
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Dim i As Integer
   'close all sub forms
    Unload frmbaojing
    Unload frmSetbf
    Unload frmSetcj
    Unload frmSetbj
    
    If Me.WindowState <> vbMinimized Then
        SaveSetting App.Title, "Settings", "MainLeft", Me.Left
        SaveSetting App.Title, "Settings", "MainTop", Me.Top
        SaveSetting App.Title, "Settings", "MainWidth", Me.Width
        SaveSetting App.Title, "Settings", "MainHeight", Me.Height
    End If
    
End Sub

Private Sub mnuExit_Click()
   
   Unload frmSetbf
   Unload Me
   
End Sub

Private Sub mnuOperateMaglog_Click()
     frmrz.Show vbModal
End Sub

Private Sub mnuOperateAct_Click()
  
    mAction = Not mAction                 '切换操作状态
    mnuOperateAct.Checked = mAction       '使菜单上体现操作状态的转换
    
    If mAction Then
       Toolbar1.Buttons(1).Image = 1
       Toolbar1.Buttons(1).ToolTipText = "启动"
       Toolbar1.Buttons(1).Value = tbrPressed
    Else
       Toolbar1.Buttons(1).Image = 2
       Toolbar1.Buttons(1).ToolTipText = "暂停"
       Toolbar1.Buttons(1).Value = tbrUnpressed
    End If
End Sub

Private Sub mnuOperateSetting_Click()
     mAction = False
     mnuOperateAct.Checked = mAction       '使菜单上体现操作状态的转换
     frmSetbf.Show vbModal, Me
End Sub
'建表头
Private Sub makecolumns()
    lvwLog.View = lvwReport
    lvwLog.ColumnHeaders.Clear
    lvwLog.ColumnHeaders.Add , , "布控名称", lvwLog.Width / 5
    lvwLog.ColumnHeaders.Add , , "时间", lvwLog.Width / 5
    lvwLog.ColumnHeaders.Add , , "动作", lvwLog.Width * 2.9 / 5
End Sub
'系统初始化子程序:
'设置timer控件的interval属性
'设置系统状态
'初始化数据库
'初始化通信端口
Private Sub Init()
        Timer1.Interval = 5000      '1秒钟检查一次timer事件
        mAction = True              '启动系统
        sysdate = Date              '记录系统启动日期
   
        Call makecolumns              '添加日志表表头
       
       '从数据库里面添加日志表内容
       
    Set cn = New ADODB.Connection '打开和数据库alertinfo的连接
       With cn
                .ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & _
                 App.Path & "\db1.mdb;"
                .Open
        End With
    Set rslog = New ADODB.Recordset '打开alertinfo数据库里面的log表
        
        Dim str As String
        str = "select * from Log where date >= #" & sysdate & "#;"
        rslog.Open str, cn, adOpenStatic, adLockOptimistic

' 日志表记录总数,用它来进行和变化后的日志总数做比较,以此判断是否该对lvwlog进行更新。        cntLog = rslog.RecordCount   '纪录下初始化时候日志纪录的数目
       
        lvwLog.ListItems.Clear
        Call showLog(rslog)         '显示日志表中今日的记录
        
        rslog.Close
            
      '初始化端口
      Call initcpara
            
End Sub
'初始化端口
Private Sub initcpara()
    '初始化串口
   Call initcom
    
'    初始化并口
'
'    If InitializeWinIo = False Then
'                MsgBox "Whoops ! There is a problem with InitializeWinIo.", vbOKOnly + vbCritical, frmbaojing.Caption
'                mAction = False
'    End If
'
   Call getLpt   '从数据库中得到可以使用的并口编号,并赋予数组lptPort
End Sub
Private Sub getLpt()
Dim r As ADODB.Recordset
Dim s As String

Set r = New ADODB.Recordset
    
    s = "select distinct number from bufangset where porperty='并口' and promote=true"
    r.Open s, cn, adOpenStatic, adLockOptimistic
  '若在布防设置表中select出的并口项数量为零则判断系统不使用并口,反之使用。
    If r.RecordCount = 0 Then
                   lptInbf = False
    Else
                    lptInbf = True
    '若有并口则开一个并口端口数组
    '并给数组赋值
    ReDim lptPort(1 To r.RecordCount)
    

⌨️ 快捷键说明

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