VERSION 5.00 Begin VB.Form Form1 BorderStyle = 3 'Fixed Dialog Caption = "Sample 2" ClientHeight = 5445 ClientLeft = 1635 ClientTop = 1680 ClientWidth = 6405 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 5445 ScaleWidth = 6405 ShowInTaskbar = 0 'False StartUpPosition = 2 'CenterScreen Begin VB.Timer Timer1 Enabled = 0 'False Interval = 1 Left = 5280 Top = 480 End Begin VB.CommandButton ExitButton Caption = "E&xit" Height = 495 Left = 5040 TabIndex = 17 Top = 2520 Width = 1215 End Begin VB.CommandButton TestButton Caption = "&Test" Height = 495 Left = 5040 TabIndex = 16 Top = 1800 Width = 1215 End Begin VB.CheckBox Bit6 Caption = "When checked, voltage is too low (OPTION 1)" Height = 195 Left = 360 TabIndex = 12 Top = 4320 Width = 4335 End Begin VB.CheckBox Bit5 Caption = "When checked, voltage is too high (OPTION 1)" Height = 195 Left = 360 TabIndex = 11 Top = 4080 Width = 4335 End Begin VB.CheckBox Bit4 Caption = "When checked, fan speed is bad (OPTION 4)" Height = 195 Left = 360 TabIndex = 10 Top = 3840 Width = 4335 End Begin VB.CheckBox Bit3 Caption = "Isolated digital input #1 (OPTION 4)" Height = 195 Left = 360 TabIndex = 9 Top = 3600 Width = 4335 End Begin VB.CheckBox Bit2 Caption = "Isolated digital input #0 (OPTION 4)" Height = 195 Left = 360 TabIndex = 8 Top = 3360 Width = 4335 End Begin VB.CheckBox Bit1 Caption = "When checked, temperature is too high (OPTION 2)" Height = 195 Left = 360 TabIndex = 7 Top = 3120 Width = 4335 End Begin VB.CheckBox Bit0 Caption = "When checked, CTR1 has timed out" Height = 195 Left = 360 TabIndex = 6 Top = 2880 Width = 4335 End Begin VB.Label BaseLabel Alignment = 2 'Center Height = 375 Left = 0 TabIndex = 20 Top = 1080 Width = 6375 End Begin VB.Label Label12 Height = 255 Left = 4920 TabIndex = 19 Top = 4320 Width = 375 End Begin VB.Label Label11 Height = 255 Left = 4920 TabIndex = 18 Top = 4080 Width = 375 End Begin VB.Label Label10 Caption = "degrees Fahrenheit" Height = 255 Left = 2640 TabIndex = 15 Top = 4920 Width = 1455 End Begin VB.Label TemperatureLabel Caption = "000" Height = 255 Left = 1440 TabIndex = 14 Top = 4920 Width = 1095 End Begin VB.Label Label8 Caption = "Temperature:" Height = 255 Left = 360 TabIndex = 13 Top = 4920 Width = 975 End Begin VB.Label Label7 Caption = "Hit the test key to start and the Exit key to exit" Height = 270 Left = 360 TabIndex = 5 Top = 2475 Width = 3405 End Begin VB.Label Label6 Caption = "Note that some functions require options to be installed" Height = 240 Left = 360 TabIndex = 4 Top = 2160 Width = 4230 End Begin VB.Label Label5 Caption = "Temperature at BASE+4 and BASE+5, respectively" Height = 270 Left = 345 TabIndex = 3 Top = 1920 Width = 3690 End Begin VB.Label Label4 Caption = "This program demonstrates how to read the Control Register and" Height = 225 Left = 360 TabIndex = 2 Top = 1665 Width = 4725 End Begin VB.Label Label2 Caption = "Reading Control Register and Temperature" Height = 225 Left = 1680 TabIndex = 1 Top = 675 Width = 3285 End Begin VB.Label Label1 Caption = "Windows 95/NT PCI-WDG-CSM SAMPLE 2" BeginProperty Font Name = "MS Sans Serif" Size = 13.5 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 390 Left = 420 TabIndex = 0 Top = 135 Width = 5460 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit 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 Addressesses(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 Running As Boolean Public Found As Boolean Private Sub ExitButton_Click() Timer1.Enabled = False End End Sub Private Sub Form_Load() Dim hKey As Long, DataSize As Long, Num As Long, DataType As Long Dim I As Integer If (InPortB(&H61) = &HAA55) Then MsgBox "ACCESNT.SYS not detected. Please copy ACCESNT.SYS into [NT]/system32/drivers and re-run this sample.", 0, "Warning" End If Found = False RegOpenKeyEx HKEY_LOCAL_MACHINE, "Software\PCIFIND\NTioPCI\Parameters", 0, KEY_QUERY_VALUE, hKey DataSize = 4 Num = 0 RegQueryValueEx hKey, "NumDevices", 0, DataType, Num, DataSize If Num <> 0 Then DataSize = 64 * 64 RegQueryValueEx hKey, "PCICommonConfig", 0, DataType, Buf(0), DataSize RegCloseKey hKey For I = 0 To Num - 1 If Buf(I).VendorID = &H494F Then If (Buf(I).DeviceID = &H25C0) Or (Buf(I).DeviceID = &H2FC0) Or (Buf(I).DeviceID = &H2FC1) Then Address = Buf(I).Addressesses(2) And &HFFF8 BaseLabel.Caption = "Base Address: " + Hex$(Address) Found = True Exit For End If End If Next I End If If Not Found Then TestButton.Enabled = False BaseLabel.Caption = "No compatible watchdog board found." BaseLabel.FontSize = BaseLabel.FontSize * 2 BaseLabel.ForeColor = &HFFFFFF BaseLabel.BackColor = 0 End If End Sub Private Sub TestButton_Click() Timer1.Enabled = True End Sub Private Sub Timer1_Timer() Dim Readback As Byte Readback = InPortB(Address + 4) Label12.Caption = Hex(Readback) Bit0.Value = 0 Bit1.Value = 0 Bit2.Value = 0 Bit3.Value = 0 Bit4.Value = 0 Bit5.Value = 0 Bit6.Value = 0 If ((Readback And 1) = 1) Then Bit0.Value = 1 If ((Readback And 2) = 2) Then Bit1.Value = 1 If ((Readback And 4) = 4) Then Bit2.Value = 1 If ((Readback And 8) = 8) Then Bit3.Value = 1 If ((Readback And 16) = 16) Then Bit4.Value = 1 If ((Readback And 32) = 32) Then Bit5.Value = 1 If ((Readback And 64) = 64) Then Bit6.Value = 1 Readback = InPortB(Address + 5) Label11.Caption = Hex(Readback) TemperatureLabel.Caption = LTrim(Str(Readback * (11 / 15) + 7)) ' Temperature is simply ((BASE+5) * 11/15) + 7} End Sub