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

📄 form1.frm

📁 工控硬件读写ISA多功能卡823的VB例子程序
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   BackColor       =   &H00808000&
   Caption         =   "Counter Demo"
   ClientHeight    =   2172
   ClientLeft      =   5004
   ClientTop       =   2556
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   2172
   ScaleWidth      =   4680
   Begin VB.Frame Frame1 
      BackColor       =   &H00FF8080&
      Caption         =   " Board Setting "
      Height          =   972
      Left            =   3000
      TabIndex        =   3
      Top             =   120
      Width           =   1452
      Begin VB.TextBox eSelect 
         Alignment       =   1  'Right Justify
         BackColor       =   &H0000FF00&
         Height          =   288
         Left            =   720
         TabIndex        =   5
         Text            =   "0"
         Top             =   600
         Width           =   612
      End
      Begin VB.TextBox eTotal 
         Alignment       =   1  'Right Justify
         BackColor       =   &H0000FFFF&
         Enabled         =   0   'False
         Height          =   288
         Left            =   720
         TabIndex        =   4
         Text            =   "0"
         Top             =   240
         Width           =   612
      End
      Begin VB.Label Label7 
         BackColor       =   &H00FF8080&
         Caption         =   "Active"
         ForeColor       =   &H00FFFFFF&
         Height          =   252
         Left            =   120
         TabIndex        =   7
         Top             =   600
         Width           =   492
      End
      Begin VB.Label Label4 
         BackColor       =   &H00FF8080&
         Caption         =   "Total"
         ForeColor       =   &H00FFFFFF&
         Height          =   252
         Left            =   120
         TabIndex        =   6
         Top             =   240
         Width           =   492
      End
   End
   Begin VB.ListBox List1 
      BackColor       =   &H0000FFFF&
      Height          =   1776
      Left            =   240
      TabIndex        =   2
      Top             =   120
      Width           =   2535
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Active"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.6
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   372
      Left            =   3000
      TabIndex        =   1
      Top             =   1200
      Width           =   1452
   End
   Begin VB.CommandButton Command1 
      Caption         =   "&Exit"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   10.8
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   372
      Left            =   3000
      TabIndex        =   0
      Top             =   1560
      Width           =   1452
   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 wBase As Integer, wCurrentBoard As Integer
Dim wTotalBoards As Integer, wRtn As Integer


Private Sub Command1_Click()
    A823_DriverClose
    End
End Sub

Private Sub Command2_Click()
    Dim i As Integer, dwCount As Long
        
    If A823_ActiveBoard(Val(eSelect.Text)) <> A823_NoError Then
        MsgBox "Can not Active the Board."
        Exit Sub
    End If

    wRtn = A823_GetConfigAddress(wBase, wCurrentBoard)
    If wRtn <> A823_NoError Then
        MsgBox "Get Configuration/Address information Error!!"
        Exit Sub
    End If

    List1.Clear
    A823_SetCounter0 wBase, 40000
    For i = 0 To 40
        dwCount = A823_ReadCounter0(wBase)
        List1.AddItem Str(dwCount)
    Next

End Sub

Private Sub Form_Load()
    Dim rtn
    Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
    
    '********************************************************************
    '* NOTICE: call A823_DriverInit() to initialize the driver.        *
    '* Initial the device driver, and return the board number in the PC *
    '********************************************************************
    Command2.Caption = "Active"
    Command2.Enabled = False
    
    wRtn = A823_DriverInit(wTotalBoards)
    If wRtn <> A823_NoError Then
        MsgBox "Driver Open Error !!!"
        Exit Sub
    End If
    
    If wTotalBoards < 1 Then
        MsgBox "Card Not Found!!"
        Exit Sub
    End If
    
    eTotal.Text = Str(wTotalBoards)
    
    Command2.Enabled = True
   
End Sub


'****************** Setting Counter 0 ***********/
'* wBase      : A823 Board Base-Address         */
'* wDownCount : Initialize Value for down-count */
'************************************************/
Private Sub A823_SetCounter0(ByVal wBase As Integer, ByVal wDownCount As Long)
    Dim hi, lo As Byte

    ' program the counter 0                       '      lo byte
    lo = (wDownCount And &HFF)                    '       then
    hi = (wDownCount / 256) And &HFF              '  Counter | hi byte | mode | binary
    A823_OutputByte (wBase + A823_TIMER_MODE), &H30    '   00     |   11    |  000 |  0
    A823_OutputByte (wBase + A823_TIMER0), lo
    A823_OutputByte (wBase + A823_TIMER0), hi
    'Sleep(1);  ' delay for the wDownCount write to 8253

End Sub


'****************** Reading Counter 0 ***********/
'* wBase      : A823 Board Base-Address         */
'* return     : Counter value                   */
'************************************************/
Private Function A823_ReadCounter0(wBase As Integer) As Long
    Dim hi, lo, count As Integer

    ' program the counter 0
                                                            '  Counter | latch | mode | binary */
    A823_OutputByte (wBase + A823_TIMER_MODE), 0                 '    00    |   00  |  000 |  0     */
    lo = A823_InputByte(wBase + A823_TIMER0)
    hi = A823_InputByte(wBase + A823_TIMER0)

    A823_ReadCounter0 = hi * 256 + lo
End Function

⌨️ 快捷键说明

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