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

📄 modetest.frm

📁 并口VBFastModeModeTest.vbp
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmModeTest 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Fast Mode Demo"
   ClientHeight    =   2484
   ClientLeft      =   48
   ClientTop       =   336
   ClientWidth     =   5292
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2484
   ScaleWidth      =   5292
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txtTimes 
      Height          =   285
      Left            =   3000
      TabIndex        =   7
      Text            =   "1000"
      Top             =   240
      Width           =   735
   End
   Begin VB.TextBox txtAddress 
      Height          =   285
      Left            =   1440
      TabIndex        =   5
      Text            =   "200"
      Top             =   240
      Width           =   735
   End
   Begin VB.CommandButton btnFastMode 
      Caption         =   "Fast Mode"
      Height          =   495
      Left            =   3600
      TabIndex        =   1
      Top             =   1440
      Width           =   1575
   End
   Begin VB.CommandButton btnNormal 
      Caption         =   "Normal Mode"
      Height          =   495
      Left            =   3600
      TabIndex        =   0
      Top             =   720
      Width           =   1575
   End
   Begin VB.Label Label5 
      Caption         =   "Times:"
      Height          =   375
      Left            =   2400
      TabIndex        =   8
      Top             =   240
      Width           =   1095
   End
   Begin VB.Label Label4 
      Caption         =   "I/O address:"
      Height          =   375
      Left            =   240
      TabIndex        =   6
      Top             =   240
      Width           =   1095
   End
   Begin VB.Label Label3 
      Caption         =   "Copyright (c)1997-2005 Hai Li, Zeal SoftStudio."
      Height          =   255
      Left            =   120
      TabIndex        =   4
      Top             =   2160
      Width           =   5175
   End
   Begin VB.Label Label2 
      Caption         =   "Click the ""Fast Mode"" button to test!"
      Height          =   375
      Left            =   240
      TabIndex        =   3
      Top             =   1560
      Width           =   3255
   End
   Begin VB.Label Label1 
      Caption         =   "Click the ""Normal Mode"" button to test!"
      Height          =   495
      Left            =   240
      TabIndex        =   2
      Top             =   840
      Width           =   3135
   End
End
Attribute VB_Name = "frmModeTest"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' FastMode sample
' Copyright (c) 1997-2005 Hai Li, Zeal SoftStudio.
' E-Mail: support@zealsoft.com
' Web: http://www.zealsoft.com
' This sample illustrates how to use the fast mode of
' NTPort Library to increase performance.

Option Explicit

Private Type LARGE_INTEGER
    lowpart As Long
    highpart As Long
End Type
Private Declare Function QueryPerformanceFrequency Lib "kernel32" _
              (lpFrequency As LARGE_INTEGER) As Long
Private Declare Function QueryPerformanceCounter Lib "kernel32" _
        (lpPerformanceCount As LARGE_INTEGER) As Long
Private Declare Function timeGetTime Lib "winmm.dll" () As Integer
Dim tTime As Double
Dim nPort As Integer
Dim nData As Integer
Dim i As Integer

Private Function ConvertLargeInt(li As LARGE_INTEGER) As Double
   Dim dbl As Double
   
   dbl = li.highpart * 2 ^ 32                 ' handle highpart
   dbl = dbl + (li.lowpart And &H7FFFFFFF)   ' handle all but sign bit of lowpart
   If li.lowpart And &H80000000 Then dbl = dbl + 2 ^ 31     ' handle sign bit

   ConvertLargeInt = dbl
End Function

' Get high resolution time
Function GetHiResTime() As Double
    Dim Cnt As LARGE_INTEGER, Freq As LARGE_INTEGER
    Dim dblCnt As Double, dblFreq As Double
    If QueryPerformanceFrequency(Freq) Then
        dblFreq = ConvertLargeInt(Freq)
        QueryPerformanceCounter Cnt
        dblCnt = ConvertLargeInt(Cnt)
        GetHiResTime = dblCnt / dblFreq * 1000
    Else
        GetHiResTime = timeGetTime()
    End If
End Function

Private Sub btnFastMode_Click()
    ' Check the OS
    If IsWinNT() = False Then
        MsgBox "Fast mode is designed for Windows NT/2000/XP/Server 2003 users, not Windows 95/98 users!"
        Exit Sub
    End If

    ' Using fast mode
    SetFastMode True
    
    ' Get the address of the port
    nPort = Val(txtAddress)
    
    ' To use the fast mode, you must call EnablePorts
    ' before you call the Inport, Outport, and other
    ' functions.
    EnablePorts nPort, nPort
    
    ' Test the result of EnablePorts
    Dim s As String
    s = Space(200)
    If GetLastState(s) <> ERROR_NONE Then
        MsgBox "Error:" + s, vbCritical
        Exit Sub
    End If
    
    ' If you are using Evaluation version, this
    ' statement will show the registration reminder
    ' dialog. If you are using the registered version,
    ' please call LicesnseInfo instead.
    nData = Inp(nPort)
    
    ' Start the time count
    tTime = GetHiResTime()
    
    ' Read the port in a loop
    For i = 1 To Val(txtTimes)
        nData = Inp(nPort)
    Next
    
    ' Stop the time count
    tTime = GetHiResTime() - tTime
    
    ' Free the resource
    DisablePorts nPort, nPort
    
    ' Show the result
    Label2 = "Fast mode time cost: " & Format(tTime, "#.##") & "ms"
End Sub

Private Sub btnNormal_Click()
    ' Using normal mode
    SetFastMode False
    
    ' Get the address of the port
    nPort = Val(txtAddress)
    
    ' If you are using Evalualtion version, this
    ' statement will show the registration reminder
    ' dialog. If you are using the registered version,
    ' please call LicesnseInfo instead.
    nData = Inp(nPort)
    
    ' Test the result of Inp
    Dim s As String
    s = Space(200)
    If GetLastState(s) <> ERROR_NONE Then
        MsgBox "Error:" + s, vbCritical
        Exit Sub
    End If
    
    ' Start the time count
    tTime = GetHiResTime()
    
    ' Read the port in a loop
    For i = 1 To Val(txtTimes)
        nData = Inp(nPort)
    Next
    
    ' Stop the time count
    tTime = GetHiResTime() - tTime
    
    ' Show the result
    Label1 = "Normal mode time cost: " & Format(tTime, "#.##") & "ms"
End Sub

⌨️ 快捷键说明

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