thread.bas
来自「16 relay output channels and 16 isolated」· BAS 代码 · 共 70 行
BAS
70 行
Attribute VB_Name = "Thread"
Option Explicit
' Windows (Constant, Data structure, API) declaration
Public Const CREATE_SUSPENDED = &H4
Public Const THREAD_PRIORITY_NORMAL = &H0
Public Const THREAD_PRIORITY_TIME_CRITICAL = &H15
Public Const STILL_ACTIVE = &H103
Global ThreadHandle As Long
Global ThreadID As Long
Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Boolean
End Type
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
Declare Function GetTickCount Lib "kernel32" () As Long
Declare Function ResumeThread Lib "kernel32" (ByVal hThread As Long) As Long
Declare Function SetThreadPriority Lib "kernel32" (ByVal hThread As Long, ByVal nPriority As Long) As Long
Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, lpExitCode As Long) As Long
Declare Function CreateThread Lib "kernel32" (ByVal lpThreadAttributes As Long, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As Long
Sub EventThread()
Dim dwStartTime As Long
Dim dwCurrentTime As Long
Dim dwTime As Long
Dim EventCount_DI0 As Long
Dim EventCount_DI16 As Long
' Dim szBuf_IDI(0 To 3) As String * 20
Dim usEventType As Long
ptCheckEvent.EventType = DRV_GetAddress(usEventType)
ptCheckEvent.Milliseconds = 1000
dwStartTime = GetTickCount()
While (gbEnableDI0 Or gbEnableDI16)
If (DRV_CheckEvent(DeviceHandle, ptCheckEvent) = SUCCESS) Then
If usEventType = ADS_EVT_INTERRUPT_DI0 Then
EventCount_DI0 = EventCount_DI0 + 1
ElseIf usEventType = ADS_EVT_INTERRUPT_DI16 Then
EventCount_DI16 = EventCount_DI16 + 1
End If
End If
dwCurrentTime = GetTickCount()
dwTime = dwCurrentTime - dwStartTime
If (dwTime >= 1000) Then
If (gbEnableDI0) Then
frmMain.ctlEvtFrqDI0 = CSng((CLng(EventCount_DI0) / CSng(dwTime) * 1000#))
End If
If (gbEnableDI16) Then
frmMain.ctlEvtFrqDI16 = CSng((CLng(EventCount_DI16) / CSng(dwTime) * 1000#))
End If
EventCount_DI0 = 0
EventCount_DI16 = 0
dwStartTime = GetTickCount()
End If
Wend
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?