📄 thread.bas
字号:
Attribute VB_Name = "ThreadFunction"
Option Explicit
Public Device As clsPCI1755
Public CheckEventThread As clsThreading
Const DataCount As Long = 1024# * 128
Public glDataBuf(DataCount) As Long 'Fast DO data out buffrer
Public Const glBufferSize As Long = DataCount * 4 'data buffer size in bytes
Public gbStopThread As Boolean
'Thread/process processing API
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public Declare Function GetCurrentProcess Lib "kernel32" () As Long
Public Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)
Public Function EventThread()
'NOTES:
'1. Do not try to set breakpoint in EvenThread(), this will crash the IDE.
'2. Use "Debug.Print" or something else to trace the thread
'3. Use Visual Bacsic 5.0 to compile this sample
'4. Because multi-thread programming was not be well-supported in Visual Basic,
' debug this sample may often crash the IDE. So you'd better compile this sample
' to a executable file and run it if you want to see the result.
Dim i As Integer
Dim usEvent As DeviceEvents
Dim dwStatus As Long, dwRetrieved As Long
gbStopThread = False
'Cyclic check Fast DO events
Do
'Check events
Select Case Device.EventCheck(1000) 'Check DO events, Time out = 1 second
Case deDoHighBufferTransferred
frmMain.txtBufferChange = "Higher half buffer"
Device.ClearFlag deDoUnderrun
If (frmMain.chkCyclic.value = 0) Then
'In non-cyclic mode, data transferring is completted, waiting FIFO empty.
frmMain.txtFdoAction.Text = "FIFO emptying"
End If
Case deDoLowBufferTransferred
frmMain.txtBufferChange = "Lower half buffer"
Device.ClearFlag deDoUnderrun
Case deDoTerminated
frmMain.txtFdoAction = "Terminated!"
gbStopThread = True
Case deDoUnderrun
frmMain.txtOverrunCount = Val(frmMain.txtOverrunCount.Text) + 1
Device.ClearFlag deDoUnderrun
Case deNoEvent
'Time out of check event
End Select
'Get conversion count
Device.FdoCheck dwStatus, dwRetrieved
frmMain.txtTransfered = dwRetrieved
If gbStopThread = True Then
'Disable all events
Device.EventEnable deDoHighBufferTransferred, False
Device.EventEnable deDoLowBufferTransferred, False
Device.EventEnable deDoUnderrun, False
Device.EventEnable deDoTerminated, False
'Enable controls setting
frmMain.cmdRun.Enabled = True
frmMain.cmdExit.Enabled = True
frmMain.cmdSelectDevice.Enabled = True
frmMain.cmdStop.Enabled = False
'Terminate this thread
ExitThread 0#
End If
Loop
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -