threadfunction.bas

来自「16 relay output channels and 16 isolated」· BAS 代码 · 共 82 行

BAS
82
字号
Attribute VB_Name = "ThreadFunction"
Option Explicit
Public DaqDevice As clsPCI1755
Public CheckEventThread As clsThreading

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
  
  gbStopThread = False
  
  'Cyclic check Fast DO events
  Do
     
    Select Case DaqDevice.EventCheck(500)   'Check Interrupt events, Time out = 0.5 second
    Case deNoEvent
      'Exit For

    Case deTcTimer                'Enable Timer interrupt event
      frmMain.txtCounterEvent.Text = frmMain.txtCounterEvent.Text + 1

    Case deDiPatternMatch         'Enable Pattern match event
      frmMain.txtPatternMatchEvent.Text = frmMain.txtPatternMatchEvent.Text + 1

    Case deDiStatusChange         'Enable Status change event
      frmMain.txtStatusChangeEvent.Text = frmMain.txtStatusChangeEvent.Text + 1

    Case deDiInterruptOfChannel0  'Enable DI 0 interrupt event
      frmMain.txtDiInterrupt(0).Text = frmMain.txtDiInterrupt(0).Text + 1

    Case deDiInterruptOfChannel1  'Enable DI 1 interrupt event
      frmMain.txtDiInterrupt(1).Text = frmMain.txtDiInterrupt(1).Text + 1

    Case deDiInterruptOfChannel2  'Enable DI 2 interrupt event
      frmMain.txtDiInterrupt(2).Text = frmMain.txtDiInterrupt(2).Text + 1

    Case deDiInterruptOfChannel3  'Enable DI 3 interrupt event
      frmMain.txtDiInterrupt(3).Text = frmMain.txtDiInterrupt(3).Text + 1

    Case deDiInterruptOfChannel4  'Enable DI 4 interrupt event
      frmMain.txtDiInterrupt(4).Text = frmMain.txtDiInterrupt(4).Text + 1

    Case deDiInterruptOfChannel5  'Enable DI 5 interrupt event
      frmMain.txtDiInterrupt(5).Text = frmMain.txtDiInterrupt(5).Text + 1

    Case deDiInterruptOfChannel6  'Enable DI 6 interrupt event
      frmMain.txtDiInterrupt(6).Text = frmMain.txtDiInterrupt(6).Text + 1

    Case deDiInterruptOfChannel7  'Enable DI 7 interrupt event
      frmMain.txtDiInterrupt(7).Text = frmMain.txtDiInterrupt(7).Text + 1
    End Select
    
    If gbStopThread = True Then
    
      'Enable controls setting
      frmMain.cmdStop.Enabled = False
      frmMain.cmdExit.Enabled = True
      frmMain.cmdStart.Enabled = True
      frmMain.cmdSelectDevice.Enabled = True
      
      'Terminate this thread
      ExitThread 0#
    End If
  Loop
  
End Function

⌨️ 快捷键说明

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