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

📄 cnt.frm

📁 控制卡高速计数模块程序。要是用VB做工控的可以参考。有接口程序
💻 FRM
字号:
VERSION 5.00
Begin VB.Form CNT 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "PCI8613_CNT"
   ClientHeight    =   2595
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   5895
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2595
   ScaleWidth      =   5895
   StartUpPosition =   3  '窗口缺省
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   1000
      Left            =   5040
      Top             =   1920
   End
   Begin VB.CommandButton Command1 
      Caption         =   "停止"
      Enabled         =   0   'False
      Height          =   375
      Left            =   3240
      TabIndex        =   3
      Top             =   1560
      Width           =   1335
   End
   Begin VB.CommandButton Command_GetVal 
      Caption         =   "开始"
      Height          =   375
      Left            =   1320
      TabIndex        =   2
      Top             =   1560
      Width           =   1335
   End
   Begin VB.TextBox TextCNTVal 
      Enabled         =   0   'False
      Height          =   270
      Left            =   2760
      TabIndex        =   1
      Top             =   840
      Width           =   855
   End
   Begin VB.Label Label1 
      Caption         =   "CNTVal  ="
      Height          =   255
      Left            =   1800
      TabIndex        =   0
      Top             =   840
      Width           =   855
   End
End
Attribute VB_Name = "CNT"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim hDevice As Long
Dim DeviceLgcID As Integer
Dim iCNTChannel As Integer
Dim CNTPara As PCI8613_PARA_CNT  ' 硬件参数

Private Sub Command_GetVal_Click()

    DeviceLgcID = 0
    hDevice = PCI8613_CreateDevice(DeviceLgcID) ' 创建设备对象
    
    If hDevice = INVALID_HANDLE_VALUE Then

        MsgBox "创建设备出错"
        Me.Command_GetVal.Enabled = False
        Exit Sub
    End If
    iCNTChannel = 0
    
    
    ' 预置硬件参数
    CNTPara.CNTVal = 100
    CNTPara.AddDecMode = 0
    CNTPara.ControlMode = 0
        
   If (PCI8613_SetDeviceCNT(hDevice, CNTPara, iCNTChannel) = False) Then '  初始化硬件
        MsgBox ("InitDeviceCNT error")
        Call Command1_Click
    End If
    
    Me.Command_GetVal.Enabled = False
    Me.Command1.Enabled = True
    Me.Timer1.Enabled = True

End Sub


Private Sub Command1_Click()

    If hDevice <> INVALID_HANDLE_VALUE Then

        If PCI8613_ReleaseDevice(hDevice) = False Then       ' 释放设备对象
            MsgBox "PCI8613_ReleaseDevice Error..."
        
        Else
            hDevice = INVALID_HANDLE_VALUE
        End If
        
        
        
    End If

    Me.Command_GetVal.Enabled = True
    Me.Command1.Enabled = False
    Me.Timer1.Enabled = False
End Sub


Private Sub Form_Load()
    hDevice = INVALID_HANDLE_VALUE
End Sub

Private Sub Form_Unload(Cancel As Integer)
    
    If hDevice <> INVALID_HANDLE_VALUE Then

        If PCI8613_ReleaseDevice(hDevice) = False Then       ' 释放设备对象
            MsgBox "PCI8613_ReleaseDevice Error..."
        End If
    End If


End Sub


Private Sub Timer1_Timer()

    If PCI8613_GetDeviceCNT(hDevice, CNTPara, iCNTChannel) = False Then
        MsgBox "GetDeviceCNT error="
        Call Command1_Click
    End If
    
    
    TextCNTVal.Text = CNTPara.CNTVal
    
End Sub

⌨️ 快捷键说明

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