首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

数据采集仪和VB的有关问题

2012-02-27 
数据采集仪和VB的问题系统在1ms产生10个数据,软件从数据采集仪获得数据,但是VB定时器最小定时单位为1ms,不

数据采集仪和VB的问题
系统在1ms产生10个数据,软件从数据采集仪获得数据,但是VB定时器最小定时单位为1ms,不能设置0.1ms,那我该怎么获得数据呢?

[解决办法]
用QueryPerformanceFrequency QueryPerformanceCounter做关键字在搜索引擎上搜索
[解决办法]
VB定时器1毫秒都达不到。数据采集仪应该有FIFO采集功能,采集仪的速度可以达到200K甚至更高,这样1毫秒采集10个数据是很轻松的事。VB只不过是通过指令从采集仪中把数据取回而已。
[解决办法]
数据采集仪器为了配合外设一般都有缓存区间的,用VB2秒,或者更长时间去取数据,如果要求很及时处理的话,我就不知道了,
[解决办法]
如果真要及时处理,对VB单线程来说,只好用
DO WHILE 1


LOOP

中间取延时代码参照下面
Option Explicit

Declare Function QueryPerformanceCounter Lib "Kernel32 " _
(X As Currency) As Boolean
Declare Function QueryPerformanceFrequency Lib "Kernel32 " _
(X As Currency) As Boolean
Declare Function GetTickCount Lib "Kernel32 " () As Long
Declare Function timeGetTime Lib "winmm.dll " () As Long

Sub Test_Timers()
Dim Ctr1 As Currency, Ctr2 As Currency, Freq As Currency
Dim Count1 As Long, Count2 As Long, Loops As Long
'
' Time QueryPerformanceCounter
'
If QueryPerformanceCounter(Ctr1) Then
QueryPerformanceCounter Ctr2
Debug.Print "Start Value: "; Format$(Ctr1, "0.0000 ")
Debug.Print "End Value: "; Format$(Ctr2, "0.0000 ")
QueryPerformanceFrequency Freq
Debug.Print "QueryPerformanceCounter minimum resolution: 1/ " & _
Freq * 10000; " sec "
Debug.Print "API Overhead: "; (Ctr2 - Ctr1) / Freq; "seconds "
Else
Debug.Print "High-resolution counter not supported. "
End If
'
' Time GetTickCount
'
Debug.Print
Loops = 0
Count1 = GetTickCount()
Do
Count2 = GetTickCount()
Loops = Loops + 1
Loop Until Count1 <> Count2
Debug.Print "GetTickCount minimum resolution: "; _
(Count2 - Count1); "ms "
Debug.Print "Took "; Loops; "loops "
'
' Time timeGetTime
'
Debug.Print
Loops = 0
Count1 = timeGetTime()
Do
Count2 = timeGetTime()
Loops = Loops + 1
Loop Until Count1 <> Count2
Debug.Print "timeGetTime minimum resolution: "; _
(Count2 - Count1); "ms "
Debug.Print "Took "; Loops; "loops "
End Sub

[解决办法]
如果有缓存区的话就一次取10个出来然后自己处理

如果没有的话 就参照ZOU_SEAFARER(颓废程序员^_^) 说的 用while不停的取吧。。记得在循环体里面加上doevents,不然你就动不了了。

感觉用多线程做这个事情比较好。 可惜,尝试过用API做VB的多线程,结果惨不忍睹。。。

热点排行