VERSION 5.00 Begin VB.Form Form1 BorderStyle = 3 'Fixed Dialog Caption = "PCI-AI12-16 Sample" ClientHeight = 5340 ClientLeft = 45 ClientTop = 330 ClientWidth = 6330 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 5340 ScaleWidth = 6330 StartUpPosition = 2 'CenterScreen Begin VB.OptionButton AIMCheck Caption = "Acquire AIM-16 Channels" Height = 255 Index = 1 Left = 3840 TabIndex = 64 ToolTipText = "Acquire AIM-16 channels 0-15 on PCIAI12-16(A) channel 0" Top = 960 Width = 2415 End Begin VB.OptionButton AIMCheck Caption = "Acquire Card Channels" Height = 255 Index = 0 Left = 3840 TabIndex = 63 ToolTipText = "Acquire PCIAI12-16(A) channels 0-15 (no AIM-16)" Top = 720 Value = -1 'True Width = 2415 End Begin VB.Timer Timer1 Enabled = 0 'False Interval = 250 Left = 3480 Top = 960 End Begin VB.TextBox CountsDisplay Height = 330 Index = 0 Left = 480 Locked = -1 'True TabIndex = 54 TabStop = 0 'False Top = 1710 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 1 Left = 480 Locked = -1 'True TabIndex = 53 TabStop = 0 'False Top = 2085 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 2 Left = 480 Locked = -1 'True TabIndex = 52 TabStop = 0 'False Top = 2460 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 3 Left = 480 Locked = -1 'True TabIndex = 51 TabStop = 0 'False Top = 2835 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 4 Left = 2040 Locked = -1 'True TabIndex = 50 TabStop = 0 'False Top = 1710 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 5 Left = 2040 Locked = -1 'True TabIndex = 49 TabStop = 0 'False Top = 2085 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 6 Left = 2040 Locked = -1 'True TabIndex = 48 TabStop = 0 'False Top = 2460 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 7 Left = 2040 Locked = -1 'True TabIndex = 47 TabStop = 0 'False Top = 2835 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 8 Left = 3555 Locked = -1 'True TabIndex = 46 TabStop = 0 'False Top = 1710 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 9 Left = 3555 Locked = -1 'True TabIndex = 45 TabStop = 0 'False Top = 2085 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 10 Left = 3555 Locked = -1 'True TabIndex = 44 TabStop = 0 'False Top = 2460 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 11 Left = 3555 Locked = -1 'True TabIndex = 43 TabStop = 0 'False Top = 2835 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 12 Left = 5130 Locked = -1 'True TabIndex = 42 TabStop = 0 'False Top = 1710 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 13 Left = 5130 Locked = -1 'True TabIndex = 41 TabStop = 0 'False Top = 2100 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 14 Left = 5130 Locked = -1 'True TabIndex = 40 TabStop = 0 'False Top = 2460 Width = 525 End Begin VB.TextBox CountsDisplay Height = 330 Index = 15 Left = 5130 Locked = -1 'True TabIndex = 39 TabStop = 0 'False Top = 2835 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 15 Left = 5670 Locked = -1 'True TabIndex = 38 TabStop = 0 'False Top = 2835 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 14 Left = 5670 Locked = -1 'True TabIndex = 36 TabStop = 0 'False Top = 2460 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 13 Left = 5670 Locked = -1 'True TabIndex = 34 TabStop = 0 'False Top = 2085 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 12 Left = 5670 Locked = -1 'True TabIndex = 32 TabStop = 0 'False Top = 1710 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 11 Left = 4095 Locked = -1 'True TabIndex = 30 TabStop = 0 'False Top = 2835 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 10 Left = 4095 Locked = -1 'True TabIndex = 28 TabStop = 0 'False Top = 2460 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 9 Left = 4095 Locked = -1 'True TabIndex = 26 TabStop = 0 'False Top = 2085 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 8 Left = 4095 Locked = -1 'True TabIndex = 24 TabStop = 0 'False Top = 1710 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 7 Left = 2580 Locked = -1 'True TabIndex = 22 TabStop = 0 'False Top = 2835 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 6 Left = 2580 Locked = -1 'True TabIndex = 20 TabStop = 0 'False Top = 2460 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 5 Left = 2580 Locked = -1 'True TabIndex = 18 TabStop = 0 'False Top = 2085 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 4 Left = 2580 Locked = -1 'True TabIndex = 16 TabStop = 0 'False Top = 1710 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 3 Left = 1020 Locked = -1 'True TabIndex = 14 TabStop = 0 'False Top = 2835 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 2 Left = 1020 Locked = -1 'True TabIndex = 12 TabStop = 0 'False Top = 2460 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 1 Left = 1020 Locked = -1 'True TabIndex = 10 TabStop = 0 'False Top = 2085 Width = 525 End Begin VB.TextBox VoltsDisplay Height = 330 Index = 0 Left = 1020 Locked = -1 'True TabIndex = 8 TabStop = 0 'False Top = 1710 Width = 525 End Begin VB.Frame Frame1 Caption = "Status" Height = 1320 Left = 120 TabIndex = 5 Top = 3315 Width = 6105 Begin VB.TextBox Status Height = 1020 Left = 120 Locked = -1 'True MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 6 TabStop = 0 'False Top = 240 Width = 5895 End End Begin VB.CommandButton ExitButton Caption = "E&xit" Height = 375 Left = 4800 TabIndex = 4 Top = 4800 Width = 1155 End Begin VB.CommandButton GetDataButton Caption = "Get &Data" Height = 375 Left = 315 TabIndex = 3 Top = 4800 Width = 1155 End Begin VB.ComboBox CardCombo Height = 315 ItemData = "Form1.frx":0000 Left = 120 List = "Form1.frx":0002 Style = 2 'Dropdown List TabIndex = 2 Top = 840 Width = 3375 End Begin VB.Label Label27 AutoSize = -1 'True Caption = "Volts" Height = 195 Left = 5775 TabIndex = 62 Top = 1500 Width = 345 End Begin VB.Label Label26 AutoSize = -1 'True Caption = "Counts" Height = 195 Left = 5145 TabIndex = 61 Top = 1500 Width = 495 End Begin VB.Label Label25 AutoSize = -1 'True Caption = "Volts" Height = 195 Left = 4200 TabIndex = 60 Top = 1500 Width = 345 End Begin VB.Label Label24 AutoSize = -1 'True Caption = "Counts" Height = 195 Left = 3570 TabIndex = 59 Top = 1500 Width = 495 End Begin VB.Label Label23 AutoSize = -1 'True Caption = "Volts" Height = 195 Left = 2685 TabIndex = 58 Top = 1500 Width = 345 End Begin VB.Label Label22 AutoSize = -1 'True Caption = "Counts" Height = 195 Left = 2055 TabIndex = 57 Top = 1500 Width = 495 End Begin VB.Label Label5 AutoSize = -1 'True Caption = "Volts" Height = 195 Left = 1125 TabIndex = 56 Top = 1500 Width = 345 End Begin VB.Label Label2 AutoSize = -1 'True Caption = "Counts" Height = 195 Left = 495 TabIndex = 55 Top = 1500 Width = 495 End Begin VB.Label Label21 AutoSize = -1 'True Caption = "15:" Height = 195 Left = 4770 TabIndex = 37 Top = 2910 Width = 225 End Begin VB.Label Label20 AutoSize = -1 'True Caption = "14:" Height = 195 Left = 4770 TabIndex = 35 Top = 2535 Width = 225 End Begin VB.Label Label19 AutoSize = -1 'True Caption = "13:" Height = 195 Left = 4770 TabIndex = 33 Top = 2160 Width = 225 End Begin VB.Label Label18 AutoSize = -1 'True Caption = "12:" Height = 195 Left = 4770 TabIndex = 31 Top = 1785 Width = 225 End Begin VB.Label Label17 AutoSize = -1 'True Caption = "11:" Height = 195 Left = 3195 TabIndex = 29 Top = 2910 Width = 225 End Begin VB.Label Label16 AutoSize = -1 'True Caption = "10:" Height = 195 Left = 3195 TabIndex = 27 Top = 2535 Width = 225 End Begin VB.Label Label15 AutoSize = -1 'True Caption = "9:" Height = 195 Left = 3195 TabIndex = 25 Top = 2160 Width = 135 End Begin VB.Label Label14 AutoSize = -1 'True Caption = "8:" Height = 195 Left = 3195 TabIndex = 23 Top = 1785 Width = 135 End Begin VB.Label Label13 AutoSize = -1 'True Caption = "7:" Height = 195 Left = 1680 TabIndex = 21 Top = 2910 Width = 135 End Begin VB.Label Label12 AutoSize = -1 'True Caption = "6:" Height = 195 Left = 1680 TabIndex = 19 Top = 2535 Width = 135 End Begin VB.Label Label11 AutoSize = -1 'True Caption = "5:" Height = 195 Left = 1680 TabIndex = 17 Top = 2160 Width = 135 End Begin VB.Label Label10 AutoSize = -1 'True Caption = "4:" Height = 195 Left = 1680 TabIndex = 15 Top = 1770 Width = 135 End Begin VB.Label Label9 AutoSize = -1 'True Caption = "3:" Height = 195 Left = 120 TabIndex = 13 Top = 2910 Width = 135 End Begin VB.Label Label8 AutoSize = -1 'True Caption = "2:" Height = 195 Left = 120 TabIndex = 11 Top = 2535 Width = 135 End Begin VB.Label Label7 AutoSize = -1 'True Caption = "1:" Height = 195 Left = 120 TabIndex = 9 Top = 2160 Width = 135 End Begin VB.Label Label6 AutoSize = -1 'True Caption = "0:" Height = 195 Left = 120 TabIndex = 7 Top = 1785 Width = 135 End Begin VB.Label Label3 AutoSize = -1 'True Caption = "Select a card to use:" Height = 195 Left = 240 TabIndex = 1 Top = 645 Width = 1470 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "Windows 95/NT PCI-AI12-16 Sample Program" BeginProperty Font Name = "MS Sans Serif" Size = 13.5 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 360 Left = 255 TabIndex = 0 Top = 105 Width = 5745 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 InPort Lib "ACCES32.dll" Alias "VBInPort" (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 OutPort Lib "ACCES32.dll" Alias "VBOutPort" (ByVal Port As Long, ByVal Value As Integer) As Integer 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 Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Private Declare Function GetTickCount Lib "kernel32" () As Long 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 BaseAddresses(5) As Long Reserved1(1) As Long RomBaseAddress 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 Dim WhichCard(63) As Boolean Dim WhichAddress(63) As Long Public RunFlag, Testing As Boolean Dim UsingAIM As Boolean Dim Chan As Byte Private Sub AIMCheck_Click(Index As Integer) UsingAIM = Index <> 0 If WhichCard(CardCombo.ListIndex) Then SetFifoChannels WhichAddress(CardCombo.ListIndex) End Sub Private Sub CardCombo_Change() If WhichCard(CardCombo.ListIndex) Then SetFifoChannels WhichAddress(CardCombo.ListIndex) End Sub Private Sub ExitButton_Click() End End Sub Private Sub Form_Load() Dim hKey As Long, DataSize As Long, DataType As Long, n As Long, I As Long, Num& 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 Call RegOpenKeyEx(HKEY_LOCAL_MACHINE, "System\CurrentControlSet\Services\NTioPCI\Parameters", 0, KEY_QUERY_VALUE, hKey) RunFlag = True DataSize = 4 Num& = 0 Call RegQueryValueEx(hKey, "NumDevices", 0, DataType, Num, DataSize) If (Num = 0) Then GoTo NoCards n = 0 DataSize = 64 * 64 Call RegQueryValueEx(hKey, "PCICommonConfig", 0, DataType, Buf(0), DataSize) For I = 0 To Num - 1 Select Case Buf(I).DeviceID Case &HACA8 CardCombo.AddItem ("Card " + Hex(n + 1) + " PCI-AI12-16 BaseAddress: " + Hex(Buf(I).BaseAddresses(2) And &HFFF8)) WhichCard(n) = False WhichAddress(n) = Buf(I).BaseAddresses(2) And &HFFFE n = n + 1 Case &HACA9 CardCombo.AddItem ("Card " + Hex(n + 1) + " PCI-AI12-16A BaseAddress: " + Hex(Buf(I).BaseAddresses(2) And &HFFF8)) WhichCard(n) = True WhichAddress(n) = Buf(I).BaseAddresses(2) And &HFFFE Call SetFifoChannels(WhichAddress(n)) n = n + 1 End Select Next NoCards: If n = 0 Then Status.Text = "No Card Found In Registry!" + Chr(13) + Chr(10) + "This may mean that the card is not installed. Make sure you have run PCIFind.exe." + Chr(13) + Chr(10): Status.SelStart = 32768 RunFlag = False End If If RunFlag Then CardCombo.ListIndex = 0 End If RegCloseKey (hKey) End Sub Private Sub GetDataButton_Click() If Not RunFlag Then Status.Text = Status.Text + "Cannot run without card!" + Chr(13) + Chr(10) Status.SelStart = 32768 ElseIf Testing Then Timer1.Enabled = False Testing = False GetDataButton.Caption = "Get &Data" Else Timer1.Enabled = True Testing = True GetDataButton.Caption = "Stop &Data" End If End Sub Private Sub SetChannel(Base As Long, Channel As Byte) Dim Data As Byte Data = Channel * &H10 Call OutPortB(Base + 2, Data) ' channel selected in upper nibble at base+2 End Sub Private Sub SetFifoChannels(Base As Long) Dim I As Byte Dim Ticks As Long ResetFifos Base If UsingAIM Then Call OutPort(Base + 2, &H0) Call OutPort(Base + 2, &H1000) Call OutPort(Base + 2, &H2000) Call OutPort(Base + 2, &H3000) Call OutPort(Base + 2, &H4000) Call OutPort(Base + 2, &H5000) Call OutPort(Base + 2, &H6000) Call OutPort(Base + 2, &H7000) Call OutPort(Base + 2, &H8000) Call OutPort(Base + 2, &H9000) Call OutPort(Base + 2, &HA000) Call OutPort(Base + 2, &HB000) Call OutPort(Base + 2, &HC000) Call OutPort(Base + 2, &HD000) Call OutPort(Base + 2, &HE000) Call OutPort(Base + 2, &HF000) Else Call OutPort(Base + 2, &H0) Call OutPort(Base + 2, &H10) Call OutPort(Base + 2, &H20) Call OutPort(Base + 2, &H30) Call OutPort(Base + 2, &H40) Call OutPort(Base + 2, &H50) Call OutPort(Base + 2, &H60) Call OutPort(Base + 2, &H70) Call OutPort(Base + 2, &H80) Call OutPort(Base + 2, &H90) Call OutPort(Base + 2, &HA0) Call OutPort(Base + 2, &HB0) Call OutPort(Base + 2, &HC0) Call OutPort(Base + 2, &HD0) Call OutPort(Base + 2, &HE0) Call OutPort(Base + 2, &HF0) End If Call InPort(Base + 2) 'read first FIFO to load aim+mux channel for first AD End Sub Private Sub ResetFifos(Base As Long) Dim I As Long Call OutPortB(Base + 4, &H48) '0x40 resets channel fifo, 0x08 resets data fifo For I = 0 To 2048 Call InPort(Base) 'read out all data from FIFO to clear it - should be redundant Next I If Not UsingAIM Then Chan = 15 End Sub Private Sub CheckFifo(Base As Long) While ((InPortB(Base + 4) And &H4) <> 0) Wend 'bit goes low when fifo half full End Sub Private Function WaitForEOC(Base As Long) As Integer Dim Timeout As Long Timeout = &H7FFF While ((InPortB(Base + 4) And &H80) = 0) And (Timeout <> 0) Timeout = Timeout - 1 Wend WaitForEOC = Timeout ' 0 = error End Function Private Sub CtrMode(Base As Long, Cntr As Byte, Mode As Byte) Call OutPortB(Base + 3, (Cntr * 2 ^ 6) Or &H30 Or (Mode * 2 ^ 1)) End Sub Private Sub CtrLoad(Base As Long, C As Integer, Val As Long) Call OutPortB(Base + C, Val And &HFF) Call OutPortB(Base + C, (Val \ 2 ^ 8) And &HFF) End Sub Private Sub Timer1_Timer() If WhichCard(CardCombo.ListIndex) Then Fifo (WhichAddress(CardCombo.ListIndex)) Else NoFifo (WhichAddress(CardCombo.ListIndex)) End If End Sub Private Sub Fifo(Base As Long) Dim Volts As Double Dim Counts As Integer Dim Value As Long Call CtrMode(Base + 8, 1, 2) 'ctr 1 mode 2 Call CtrMode(Base + 8, 2, 2) 'ctr 2 mode 2 Call CtrLoad(Base + 8, 1, &H2) Call CtrLoad(Base + 8, 2, &HFF) Call OutPortB(Base + 4, 1) ' set counter enable bit, starts conversions Call CheckFifo(Base) ' WAITS until FIFO half-full bit is set Call OutPortB(Base + 4, 0) ' clear counter enable bit, stops conversions While ((InPortB(Base + 4) And &H2) <> 0) 'bit goes low when fifo is empty Value = InPort(Base) Counts = Value And &HFFF If (Counts > &H7FF) Then 'sign-extend Counts = Counts Or &HF000 End If Volts = 20# * (Counts / 4095#) 'convert to volts: counts*max volt span/max counts If UsingAIM Then Chan = (Value And &HF000&) \ &H1000 'Read the actual channel Else Chan = (Chan + 1) Mod 16 'Go to the next channel End If VoltsDisplay(Chan).Text = Format(Volts, "#0.0##") CountsDisplay(Chan).Text = Counts Wend End Sub Private Sub NoFifo(Base As Long) Dim Volts As Double Dim Counts As Integer Dim Ticks As Long Call OutPortB(Base + 4, 0) ' clear counter enable bit, stops conversions For Chan = 0 To 15 Call SetChannel(Base, Chan) ' write channel, range, SE or diff Ticks = GetTickCount + 2 While Ticks > GetTickCount 'Allow for settle time (with change) Wend Call OutPortB(Base, 0) ' start conversion If (WaitForEOC(Base) = 0) Then ' WaitForEOC returns zero if it times out Status.Text = Status.Text + "A/D Timed Out" + Chr(13) + Chr(10) Else Counts = InPort(Base) And &HFFF ' get data If (Counts And &H800) Then Counts = Counts Or &HF000 ' sign-extend End If Volts = 20# * (Counts / 4095#) ' convert to volts: counts*max volt span/max counts VoltsDisplay(Chan).Text = Format(Volts, "#0.0##") CountsDisplay(Chan).Text = Counts End If Next Chan End Sub