我要实现500BIT/S发送数据,现在是发送1BIT后调用DELAY延迟2MS,
请问在VB中如何使用QueryPerformanceFrequency和QueryPerformanceCounter 建立的一个SUB DELAY函数,能精确到2MS,以便于我发送1BIT后掉用该DELAY函数延迟2MS~
由于刚接手VB,不太会用API函数,急急急啊啊~希望各位大侠帮忙写个DELAY函数~万分感谢
请问在VB中如何使用QueryPerformanceFrequency和QueryPerformanceCounter 建立的一个SUB DELAY函数,能精确到2MS,以便于我发送1BIT后掉用该DELAY函数延迟2MS~
由于刚接手VB,不太会用API函数,急急急啊啊~希望各位大侠帮忙写个DELAY函数~万分感谢
''''
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
Public Declare Function timeGetTime Lib "winmm.dll" () As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'
' '延时函数
' 毫秒
Public Sub Delay(DelayNum As Long)
Dim Ctr1, Ctr2, Freq As Currency
Dim Start As Long ', Stime2 As Single
If QueryPerformanceFrequency(Freq) Then
QueryPerformanceCounter Ctr1
Do
Sleep 1
DoEvents
QueryPerformanceCounter Ctr2
Loop While (Ctr2 - Ctr1) / Freq * 1000 < DelayNum
Else
' MsgBox "不支持高精度计数器!"
'设定开始时间
Start = timeGetTime
Do While timeGetTime < Start + DelayNum
Sleep 1
DoEvents
Loop
End If
End Sub