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

📄 thread.bas

📁 16 relay output channels and 16 isolated digital input channels LED indicators to show activated
💻 BAS
字号:
Attribute VB_Name = "ThreadFunction"
Option Explicit
Public Device As clsPCI1755
Public CheckEventThread As clsThreading

Public glDataBuf(600000) As Long                  'Fast DI data out buffrer
Public Const glBufferSize As Long = 600000# * 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 DI events
  Do
    'Check events
    Select Case Device.EventCheck(1000)   'Check DI events, Time out = 1 second
    Case deDiHighBufferReady
      frmMain.txtBufferChange = "Higher half buffer"
      Device.ClearFlag deDiOverrun
    
    Case deDiLowBufferReady
      frmMain.txtBufferChange = "Lower half buffer"
      Device.ClearFlag deDiOverrun
    
    Case deDiTerminated
      frmMain.txtFdiAction = "Terminated!"
      gbStopThread = True
      
    Case deDiOverrun
      frmMain.txtOverrunCount = Val(frmMain.txtOverrunCount.Text) + 1
      Device.ClearFlag deDiOverrun
       
    Case deNoEvent
      'Time out of check event
      
    End Select
    
    'Get conversion count
    Device.FdiCheck dwStatus, dwRetrieved
    frmMain.txtTransfered = dwRetrieved
    
    If gbStopThread = True Then
      'Disable all events
      Device.EventEnable deDiHighBufferReady, False
      Device.EventEnable deDiLowBufferReady, False
      Device.EventEnable deDiOverrun, False
      Device.EventEnable deDiTerminated, 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 + -