作成者 |
メッセージ |
|
|
ありがとうございます。
とても参考になりました。
長時間動作させると、ハンドルリークが問題になりました。
メインタスクにてtimerIDを開放する必要が有りそうです。
難しいですねぇ・・・
ありがとうございます。
とても参考になりました。
長時間動作させると、ハンドルリークが問題になりました。 メインタスクにてtimerIDを開放する必要が有りそうです。
難しいですねぇ・・・
|
|
|
投稿記事 |
Posted: 2020年3月01日(日) 13:03 |
|
|
|
|
|
コード: #N88BASIC
Type TIMECAPS
wPeriodMin As Long
wPeriodMax As Long
End Type
Const TIME_PERIODIC = 1
Declare Function timeGetDevCaps Lib "winmm.dll" (lpTimeCaps As *TIMECAPS, uSize As Long) As Long
Declare Function timeSetEvent Lib "winmm" (uDelay As DWord, uResolution As DWord, lpFunction As DWord, dwUser As *DWord, uFlags As DWord) As DWord
Declare Function timeBeginPeriod Lib "winmm" (uPeriod As DWord) As DWord
Declare Function timeEndPeriod Lib "winmm" (uPeriod As DWord) As DWord
Declare Function timeKillEvent Lib "winmm" (uTimerID As DWord) As DWord
Dim tc As TIMECAPS
Dim timerID As DWord
Dim res As Long
Dim count As DWord
Dim s As String
count = 0
timeGetDevCaps(VarPtr(tc), SizeOf(TIMECAPS))
Print "タイマー分解能"
Print "最小値=";tc.wPeriodMin
Print "最大値=";tc.wPeriodMax
timeBeginPeriod(tc.wPeriodMin)
res = 300'タイマ間隔
timerID = timeSetEvent(res, res, AddressOf(TimerCallback), 0, TIME_PERIODIC)
Sub TimerCallback(id As DWORD, msg As DWORD, usr As DWORD, dw1 As DWORD, dw2 As DWORD)
count = count + 1
Print count ; "回タイマー呼ばれました"
If count = 10 Then
timeKillEvent(timerID)
timeEndPeriod(tc.wPeriodMin)
Print "タイマーおわり"
End If
End Sub
Sleep(res*11)
Print "なにかキーを押してください"
Input s
End
[code]#N88BASIC
Type TIMECAPS wPeriodMin As Long wPeriodMax As Long End Type Const TIME_PERIODIC = 1
Declare Function timeGetDevCaps Lib "winmm.dll" (lpTimeCaps As *TIMECAPS, uSize As Long) As Long Declare Function timeSetEvent Lib "winmm" (uDelay As DWord, uResolution As DWord, lpFunction As DWord, dwUser As *DWord, uFlags As DWord) As DWord Declare Function timeBeginPeriod Lib "winmm" (uPeriod As DWord) As DWord Declare Function timeEndPeriod Lib "winmm" (uPeriod As DWord) As DWord Declare Function timeKillEvent Lib "winmm" (uTimerID As DWord) As DWord
Dim tc As TIMECAPS Dim timerID As DWord Dim res As Long Dim count As DWord Dim s As String
count = 0
timeGetDevCaps(VarPtr(tc), SizeOf(TIMECAPS)) Print "タイマー分解能" Print "最小値=";tc.wPeriodMin Print "最大値=";tc.wPeriodMax
timeBeginPeriod(tc.wPeriodMin)
res = 300'タイマ間隔
timerID = timeSetEvent(res, res, AddressOf(TimerCallback), 0, TIME_PERIODIC)
Sub TimerCallback(id As DWORD, msg As DWORD, usr As DWORD, dw1 As DWORD, dw2 As DWORD)
count = count + 1 Print count ; "回タイマー呼ばれました" If count = 10 Then timeKillEvent(timerID) timeEndPeriod(tc.wPeriodMin) Print "タイマーおわり" End If End Sub
Sleep(res*11) Print "なにかキーを押してください" Input s End[/code]
|
|
|
投稿記事 |
Posted: 2020年2月22日(土) 20:21 |
|
|
|
|
|
SetTimer()を使用していましたが誤差が大きいので、高精度なタイマーの使い方(サンプル希望)を
教えていただけませんか。
timeSetEvent()またはCreateTimerQueue()を試そうと挑戦していますが、難しくて理解できません。
[ここをクリックすると内容が表示されます] [ここをクリックすると非表示にします]コード:
Declare Function timeSetEvent Lib "winmm" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As HANDLE
Declare Function timeBeginPeriod Lib "winmm" Alias "timeBeginPeriod" (ByVal uPeriod As Long) As HANDLE
Declare Function timeEndPeriod Lib "winmm" Alias "timeEndPeriod" (ByVal uPeriod As Long) As HANDLE
Declare Function CreateTimerQueue Lib "kernel32" Alias "CreateTimerQueue" () As HANDLE
Declare Function CreateTimerQueueTimer Lib "kernel32.dll" (ByRef phNewTimer As Long, ByVal TimerQueue As Long, ByVal Callback As Long, ByVal Parameter As Long, ByVal DueTime As Long, ByVal Period As Long, ByVal Flags As Long) As HANDLE
Declare Function DeleteTimerQueueTimer Lib "kernel32" Alias "DeleteTimerQueueTimer" (ByVal TimerQueue As Long, ByVal Timer As Long, ByVal CompletionEvent As Long) As HANDLE
Declare Function DeleteTimerQueueEx Lib "kernel32" Alias "DeleteTimerQueueEx" (ByVal TimerQueue As Long, ByVal CompletionEvent As Long) As HANDLE
SetTimer()を使用していましたが誤差が大きいので、高精度なタイマーの使い方(サンプル希望)を 教えていただけませんか。
timeSetEvent()またはCreateTimerQueue()を試そうと挑戦していますが、難しくて理解できません。
[hide][code] Declare Function timeSetEvent Lib "winmm" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As HANDLE Declare Function timeBeginPeriod Lib "winmm" Alias "timeBeginPeriod" (ByVal uPeriod As Long) As HANDLE Declare Function timeEndPeriod Lib "winmm" Alias "timeEndPeriod" (ByVal uPeriod As Long) As HANDLE
Declare Function CreateTimerQueue Lib "kernel32" Alias "CreateTimerQueue" () As HANDLE Declare Function CreateTimerQueueTimer Lib "kernel32.dll" (ByRef phNewTimer As Long, ByVal TimerQueue As Long, ByVal Callback As Long, ByVal Parameter As Long, ByVal DueTime As Long, ByVal Period As Long, ByVal Flags As Long) As HANDLE Declare Function DeleteTimerQueueTimer Lib "kernel32" Alias "DeleteTimerQueueTimer" (ByVal TimerQueue As Long, ByVal Timer As Long, ByVal CompletionEvent As Long) As HANDLE Declare Function DeleteTimerQueueEx Lib "kernel32" Alias "DeleteTimerQueueEx" (ByVal TimerQueue As Long, ByVal CompletionEvent As Long) As HANDLE [/code][/hide]
|
|
|
投稿記事 |
Posted: 2020年2月15日(土) 11:09 |
|
|
|
|