VERSION 5.00 Begin VB.Form Form1 BorderStyle = 3 'Fixed Dialog Caption = "Sample 3" ClientHeight = 3630 ClientLeft = 45 ClientTop = 330 ClientWidth = 5760 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 3630 ScaleWidth = 5760 ShowInTaskbar = 0 'False StartUpPosition = 2 'CenterScreen Begin VB.CommandButton ExitButton Caption = "E&xit" Height = 375 Left = 4440 TabIndex = 10 Top = 3120 Width = 1215 End Begin VB.CommandButton TestButton Caption = "&Test" Height = 375 Left = 4440 TabIndex = 9 Top = 2640 Width = 1215 End Begin VB.Timer Timer1 Enabled = 0 'False Interval = 35 Left = 5040 Top = 600 End Begin VB.Label StatusLabel BorderStyle = 1 'Fixed Single Caption = "Watchdog Status" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 120 TabIndex = 8 Top = 3120 Width = 4215 End Begin VB.Label LoopLabel AutoSize = -1 'True Caption = "0" Height = 195 Left = 2760 TabIndex = 7 Top = 2640 Visible = 0 'False Width = 90 End Begin VB.Label LoopStatusLabel AutoSize = -1 'True Caption = "Updating counter 1 ... loop number:" Height = 195 Left = 120 TabIndex = 6 Top = 2640 Visible = 0 'False Width = 2505 End Begin VB.Label Label5 AutoSize = -1 'True Caption = "Hit the Test button to start and the Exit button to exit." Height = 195 Left = 120 TabIndex = 5 Top = 2160 Width = 3735 End Begin VB.Label Label4 Caption = $"Form1.frx":0000 Height = 435 Left = 120 TabIndex = 4 Top = 1560 Width = 5160 End Begin VB.Label BaseLabel AutoSize = -1 'True Caption = "0000" Height = 195 Left = 1200 TabIndex = 3 Top = 1080 Width = 360 End Begin VB.Label Label3 AutoSize = -1 'True Caption = "Base Address:" Height = 195 Left = 120 TabIndex = 2 Top = 1080 Width = 1020 End Begin VB.Label Label2 AutoSize = -1 'True Caption = "Use of Counter/Timer Chip with Watchdog Sample" Height = 195 Left = 960 TabIndex = 1 Top = 600 Width = 3585 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "Windows 95/NT PCI-WDG-CSM Sample 3" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 300 Left = 360 TabIndex = 0 Top = 120 Width = 4965 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Declare Function InPortB Lib "ACCES32.dll" Alias "VBInPortB" (ByVal Port As Long) As Integer Private Declare Function OutPortB Lib "ACCES32.dll" Alias "VBOutPortB" (ByVal Port As Long, ByVal Value As Byte) As Integer Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value. Private Const HKEY_LOCAL_MACHINE = &H80000002 Private Const KEY_QUERY_VALUE = &H1 Private Type TPCI_COMMON_CONFIG VendorID As Integer DeviceID As Integer Command As Integer Status As Integer RevisionID As Byte ProgIf As Byte SubClass As Byte BaseClass As Byte CacheLineSize As Byte LatencyTimer As Byte HeaderType As Byte BIST As Byte Addresses(5) As Long Reserved1(1) As Long RomAddressess As Long Reserved2(1) As Long InterruptLine As Byte InterruptPin As Byte MinimumGrant As Byte MaximumLatency As Byte End Type Dim Buf(63) As TPCI_COMMON_CONFIG Public Address As Long Public LoopCount As Integer Public State As Integer Private Sub ExitButton_Click() Form_Unload (0) End End Sub Private Sub Form_Load() If (InPortB(&H61) = &HAA55) Then Call MsgBox("ACCESNT.SYS not detected. Please copy ACCESNT.SYS into [NT]/system32/drivers and re-run this sample.", 0, "Warning") End If found = False Call RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\PCIFIND\NTioPCI\Parameters", 0, KEY_QUERY_VALUE, hKey) DataSize = 4 Num& = 0 Call RegQueryValueEx(hKey, "NumDevices", 0, DataType, Num, DataSize) If (Num = 0) Then GoTo NoCards DataSize = 64 * 64 Call RegQueryValueEx(hKey, "PCICommonConfig", 0, DataType, Buf(0), DataSize) For i = 0 To Num - 1 Step 1 If found Then Exit For temp = Hex(Buf(i).DeviceID) If (Buf(i).DeviceID = &H22C0) And (Buf(i).VendorID = &H494F) Then Address = Buf(i).Addresses(2) And &HFFF8 BaseLabel.Caption = Hex(Address) found = True End If Next i NoCards: If Not found Then StatusLabel.Caption = "PCI-WDG-CSM NOT FOUND!" BaseLabel.Caption = "NOT FOUND!" End If RegCloseKey (hKey) End Sub Private Sub Form_Unload(Cancel As Integer) InPortB (Address + 6) InPortB (Address + 7) End Sub Private Sub CtrMode(cntr As Byte, mode As Byte) ctrl = (cntr * (2 ^ 6)) Or &H30 Or (mode * (2 ^ 1)) Call OutPortB(Address + 3, ctrl) End Sub Private Sub LoadCtr(C As Long, Val As Long) Call OutPortB(Address + C, Val And &HFF) Call OutPortB(Address + C, ((Val And &HFF00) / 256) And &HFF) End Sub Private Sub SetCounter() InPortB (Address + 7) '{disable counter functions} Call CtrMode(2, 0) '{ set counter 2 to mode 0} Call OutPortB(Address + 7, 0) ' { enable counters} Call InPortB(Address + 7) '{disable counter functions} Call OutPortB(Address + 6, 0) '{enable buzzer} Call OutPortB(Address + &HC, 0) '{select low clock rate} Call InPortB(Address + &HD) '{disable opto reset} Call InPortB(Address + &HE) '{disable opto reset} Call InPortB(Address + &HF) '{disable program outputs} ' {program the counters for the REQUIRED modes} Call CtrMode(0, 3) '{set counter 0 to mode 3} Call LoadCtr(0, &HFFFF) '{full load value} Call CtrMode(1, 2) '{set counter 1 to mode 2} Call LoadCtr(1, &H10) '{load counter 1 with 10 hex} Call CtrMode(2, 1) '{set counter 2 to mode 1} 'Note:Not loading counter 2 creates an infinite reset duration 'Set the reset duration by loading a value in counter 2 'Change counter 2 to mode 2 to set duration End Sub Private Sub TestButton_Click() If (TestButton.Caption = "&Test") Then LoopStatusLabel.Visible = True LoopLabel.Visible = True TestButton.Caption = "&Abort" StatusLabel.Caption = "Watchdog Okay" SetCounter Timer1.Enabled = True State = 0 LoopCount = 0 Else InPortB (Address + 6) InPortB (Address + 7) Timer1.Enabled = False TestButton.Caption = "&Test" State = 0 LoopCount = 0 End If End Sub Private Sub Timer1_Timer() Select Case State Case 0 InPortB (Address + 4) ' clear any pending interrupts Call OutPortB(Address + 7, 0) ' start counters counting State = State + 1 Case 1 Call CtrMode(1, 2) Call LoadCtr(1, &H10) ' reload the counter LoopCount = LoopCount + 1 If (LoopCount = 100) Then State = State + 1 End If LoopLabel.Caption = LoopCount Case 2 readback = InPortB(Address + 4) If ((readback And 1) = 0) Then StatusLabel.Caption = "Watchdog Timed Out" TestButton.Caption = "&Test" State = State + 1 LoopCount = 0 Else StatusLabel.Caption = "Waiting for Timeout" End If Case 3 LoopCount = LoopCount + 1 If (LoopCount = 5) Then Call InPortB(Address + 6) Timer1.Enabled = False State = 0 LoopCount = 0 End If End Select End Sub