VERSION 5.00 Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "comctl32.ocx" Begin VB.Form mainform Caption = "dac sample" ClientHeight = 4815 ClientLeft = 60 ClientTop = 345 ClientWidth = 8385 LinkTopic = "Form1" ScaleHeight = 4815 ScaleWidth = 8385 StartUpPosition = 2 'CenterScreen Begin VB.TextBox ConfigText Height = 1455 Left = 120 MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 40 TabStop = 0 'False Text = "main.frx":0000 Top = 1680 Width = 4575 End Begin VB.ComboBox AddressList Height = 315 Left = 120 TabIndex = 39 Text = "Address List" Top = 960 Width = 2415 End Begin VB.Frame DACFrame Caption = "DAC Resolution" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 735 Left = 4800 TabIndex = 34 Top = 1560 Width = 1695 Begin VB.OptionButton DACButton Caption = "16-Bit" Height = 195 Index = 1 Left = 120 TabIndex = 36 Top = 440 Width = 1215 End Begin VB.OptionButton DACButton Caption = "12-Bit" Height = 195 Index = 0 Left = 120 TabIndex = 35 Top = 240 Width = 1455 End End Begin VB.Frame outframe Caption = "Output Value" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 1335 Left = 120 TabIndex = 15 Top = 3360 Width = 4575 Begin ComctlLib.Slider value Height = 375 Left = 120 TabIndex = 17 Top = 240 Visible = 0 'False Width = 4215 _ExtentX = 7435 _ExtentY = 661 _Version = 327682 LargeChange = 16 Max = 65520 TickFrequency = 4096 End Begin VB.Label LOutput Height = 300 Left = 120 TabIndex = 16 Top = 840 Visible = 0 'False Width = 4335 End End Begin VB.CommandButton ExitButton Caption = "Exit Program" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 6600 TabIndex = 14 Top = 4320 Width = 1695 End Begin VB.CommandButton InitButton Caption = "Initialize" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 4800 TabIndex = 13 Top = 4320 Width = 1695 End Begin VB.Frame ChannelFrame Caption = "Output Channel" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 3855 Left = 6600 TabIndex = 9 Top = 360 Width = 1695 Begin VB.OptionButton chbutton Caption = "All Channels" Height = 195 Index = 16 Left = 120 TabIndex = 33 Top = 3435 Width = 1455 End Begin VB.OptionButton chbutton Caption = "Channel 15" Height = 195 Index = 15 Left = 120 TabIndex = 32 Top = 3240 Width = 1455 End Begin VB.OptionButton chbutton Caption = "Channel 14" Height = 195 Index = 14 Left = 120 TabIndex = 31 Top = 3030 Width = 1455 End Begin VB.OptionButton chbutton Caption = "Channel 13" Height = 195 Index = 13 Left = 120 TabIndex = 30 Top = 2835 Width = 1455 End Begin VB.OptionButton chbutton Caption = "Channel 12" Height = 195 Index = 12 Left = 120 TabIndex = 29 Top = 2625 Width = 1455 End Begin VB.OptionButton chbutton Caption = "Channel 11" Height = 195 Index = 11 Left = 120 TabIndex = 28 Top = 2445 Width = 1455 End Begin VB.OptionButton chbutton Caption = "Channel 10" Height = 195 Index = 10 Left = 120 TabIndex = 27 Top = 2235 Width = 1455 End Begin VB.OptionButton chbutton Caption = "Channel 9" Height = 195 Index = 9 Left = 120 TabIndex = 26 Top = 2040 Width = 1095 End Begin VB.OptionButton chbutton Caption = "Channel 8" Height = 195 Index = 8 Left = 120 TabIndex = 25 Top = 1830 Width = 1095 End Begin VB.OptionButton chbutton Caption = "Channel 7" Height = 195 Index = 7 Left = 120 TabIndex = 24 Top = 1635 Width = 1095 End Begin VB.OptionButton chbutton Caption = "Channel 6" Height = 195 Index = 6 Left = 120 TabIndex = 21 Top = 1440 Width = 1455 End Begin VB.OptionButton chbutton Caption = "Channel 5" Height = 195 Index = 5 Left = 120 TabIndex = 20 Top = 1230 Width = 1335 End Begin VB.OptionButton chbutton Caption = "Channel 4" Height = 195 Index = 4 Left = 120 TabIndex = 19 Top = 1035 Width = 1215 End Begin VB.OptionButton chbutton Caption = "Channel 3" Height = 195 Index = 3 Left = 120 TabIndex = 18 Top = 840 Width = 1335 End Begin VB.OptionButton chbutton Caption = "Channel 2" Height = 195 Index = 2 Left = 120 TabIndex = 12 Top = 645 Width = 1335 End Begin VB.OptionButton chbutton Caption = "Channel 1" Height = 195 Index = 1 Left = 120 TabIndex = 11 Top = 420 Width = 1095 End Begin VB.OptionButton chbutton Caption = "Channel 0" Height = 195 Index = 0 Left = 120 TabIndex = 10 Top = 240 Width = 1215 End End Begin VB.Frame OutputFrame Caption = "Output Range" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 1815 Left = 4800 TabIndex = 3 Top = 2400 Width = 1695 Begin VB.OptionButton rangebutton Caption = "4-20 mA" Height = 195 Index = 6 Left = 120 TabIndex = 23 Top = 1440 Width = 1215 End Begin VB.OptionButton rangebutton Caption = "0-10 VDC" Height = 195 Index = 5 Left = 120 TabIndex = 22 Top = 1240 Width = 1095 End Begin VB.OptionButton rangebutton Caption = "0-5 VDC" Height = 195 Index = 4 Left = 120 TabIndex = 8 Top = 1040 Width = 1455 End Begin VB.OptionButton rangebutton Caption = "0-2.5 VDC" Height = 195 Index = 3 Left = 120 TabIndex = 7 Top = 840 Width = 1095 End Begin VB.OptionButton rangebutton Caption = "+/-10 VDC" Height = 195 Index = 2 Left = 120 TabIndex = 6 Top = 640 Width = 1215 End Begin VB.OptionButton rangebutton Caption = "+/-5 VDC" Height = 195 Index = 1 Left = 120 TabIndex = 5 Top = 440 Width = 1215 End Begin VB.OptionButton rangebutton Caption = "+/-2.5 VDC" Height = 195 Index = 0 Left = 120 TabIndex = 4 Top = 240 Width = 1335 End End Begin VB.Frame ISAFrame Caption = "Base Address" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 650 Left = 4800 TabIndex = 0 Top = 840 Width = 1695 Begin VB.TextBox ISAEdit Height = 285 Left = 720 TabIndex = 1 Text = "300" Top = 220 Width = 855 End Begin VB.Label Label1 Caption = "hex" Height = 255 Left = 240 TabIndex = 2 Top = 250 Width = 495 End End Begin VB.Label PCILabel2 Caption = $"main.frx":0152 Height = 735 Left = 120 TabIndex = 41 Top = 720 Width = 4575 End Begin VB.Label PCIAddrLabel Caption = "PCI DAC Card Addresses" Height = 195 Left = 120 TabIndex = 38 Top = 720 Width = 2055 End Begin VB.Label PCILabel BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 240 TabIndex = 37 Top = 120 Width = 4335 End End Attribute VB_Name = "mainform" 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 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 Long) 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.dll" () As Long Private Const HKEY_LOCAL_MACHINE = &H80000002 Private Const MyKey = "Software\PCIFIND\NTioPCI\Parameters" 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 Ports(4) As Long Public RunFlag As Boolean Public Address As Long Public MyIndex As Integer Dim MyValues(2) As Integer Public Msg As String Dim base As Long Dim span As Double Dim offset As Double Dim maxch As Integer Dim channel As Long Dim CurVal As Long Dim bits As Integer Dim outval As Long Dim CalibMax As Integer, CalibMin As Integer Dim Range As Byte Private Sub AddressList_Click() base = "&H" + Mid(AddressList.Text, 14, 4) t = Mid(AddressList.Text, 10, 1) Select Case t Case 2 maxch = 2 PCILabel.Caption = "PCI-DA12-2 Digital-To-Analog Card" Case 4 maxch = 4 PCILabel.Caption = "PCI-DA12-4 Digital-To-Analog Card" Case 6 maxch = 6 PCILabel.Caption = "PCI-DA12-6 Digital-To-Analog Card" Case 8 maxch = 8 PCILabel.Caption = "PCI-DA12-8 Digital-To-Analog Card" Case Else maxch = 16 PCILabel.Caption = "PCI-DA12-16 Digital-To-Analog Card" End Select End Sub Private Sub ChButton_Click(Index As Integer) For i = 0 To 16 If chbutton(i).value = True Then maxch = i End If Next i End Sub Private Function ConvertForOutput(v As Long) As Long Dim i As Integer Dim CalV As Long, CalResult As Long ConvertForOutput = (v * outval / 65536) CalV = (((65536 - CalibMax - CalibMin) / 65536) * v + CalibMin) CalResult = (CalV * outval / 65536) 'Calibrated version thereof If maxch < 16 Then InPortB (base + 2) Call OutPort(base + (maxch * 2), CalResult) 'write to DAC InPortB (base + &HA) Else InPortB (base + 0) For i = 0 To maxch - 1 Call OutPort(base + (i * 2), CalResult) 'write to DAC Next i InPortB (base + 8) End If End Function Private Function IntToBin(n As Long) As String Dim temp As String Dim i As Integer Dim f As Double Dim out As Long If bits = 12 Then out = 2048 Else out = 32768 End If temp = "" 'print output onscreen as binary For i = 0 To bits - 1 If (n And (out)) = 0 Then temp = temp + "0" Else temp = temp + "1" End If out = out / 2 Next i If bits = 12 Then temp = temp + "xxxx" End If f = (((outval * 2) - 1) And n) * span / outval - offset 'convert to volts mystring = Str(f) mystring2 = Str(n) temp = temp + " hex " + Hex(mystring2) + " " + mystring 'print binary, hex, volts onscreen If rangebutton(5).value = True Or rangebutton(6).value = True Then IntToBin = temp + " mA" Else IntToBin = temp + " Volts" End If End Function Private Sub UpdateDAC() LOutput.Caption = IntToBin(ConvertForOutput(CurVal)) 'write output on screen End Sub Private Sub DACButton_Click(Index As Integer) If DACButton(0).value = True Then outval = 4096 bits = 12 value.LargeChange = 16 Else outval = 65536 bits = 16 value.LargeChange = 1 End If End Sub Private Sub ExitButton_Click() End End Sub Private Sub Form_Load() ISAFrame.Visible = False Call RegOpenKeyEx(HKEY_LOCAL_MACHINE, MyKey, 0, 1, hKey) DataSize = 4 Num = 0 n = 0 t = 0 Call RegQueryValueEx(hKey, "NumDevices", 0, DataType, Num, DataSize) If (Num = 0) Then GoTo NoCards PCILabel2.Visible = False DataSize = 64 * 64 Call RegQueryValueEx(hKey, "PCICommonConfig", 0, DataType, Buf(0), DataSize) For i = 0 To Num - 1 RunFlag = True Select Case Buf(i).DeviceID Case &H6CB0 PCILabel.Caption = "PCI-DA12-16 Digital-To-Analog Card" AddressList.AddItem ("PCI-DA12-16: " + Hex(Buf(i).BaseAddresses(2) And &HFFF8) + ":" + Hex(Buf(i).BaseAddresses(3) And &HFFF8)) n = n + 1 Case &H6CB1 PCILabel.Caption = "PCI-DA12-16V Digital-To-Analog Card" AddressList.AddItem ("PCI-DA12-16V:" + Hex(Buf(i).BaseAddresses(2) And &HFFF8) + ":" + Hex(Buf(i).BaseAddresses(3) And &HFFF8)) n = n + 1 Case &H6CA8 PCILabel.Caption = "PCI-DA12-8 Digital-To-Analog Card" AddressList.AddItem ("PCI-DA12-8: " + Hex(Buf(i).BaseAddresses(2) And &HFFF8) + ":" + Hex(Buf(i).BaseAddresses(3) And &HFFF8)) n = n + 1 Case &H6CA9 PCILabel.Caption = "PCI-DA12-8V Digital-To-Analog Card" AddressList.AddItem ("PCI-DA12-8V: " + Hex(Buf(i).BaseAddresses(2) And &HFFF8) + ":" + Hex(Buf(i).BaseAddresses(3) And &HFFF8)) n = n + 1 Case &H6CA0 PCILabel.Caption = "PCI-DA12-6 Digital-To-Analog Card" AddressList.AddItem ("PCI-DA12-6: " + Hex(Buf(i).BaseAddresses(2) And &HFFF8) + ":" + Hex(Buf(i).BaseAddresses(3) And &HFFF8)) n = n + 1 Case &H6C98 PCILabel.Caption = "PCI-DA12-4 Digital-To-Analog Card" AddressList.AddItem ("PCI-DA12-4: " + Hex(Buf(i).BaseAddresses(2) And &HFFF8) + ":" + Hex(Buf(i).BaseAddresses(3) And &HFFF8)) n = n + 1 Case &H6C90 PCILabel.Caption = "PCI-DA12-2 Digital-To-Analog Card" AddressList.AddItem ("PCI-DA12-2: " + Hex(Buf(i).BaseAddresses(2) And &HFFF8) + ":" + Hex(Buf(i).BaseAddresses(3) And &HFFF8)) n = n + 1 End Select Next i NoCards: If n = 0 Then PCILabel.Caption = "No PCI Card Found In Registry": ConfigText.SelStart = 32768: ISAFrame.Visible = True ISAEdit.Visible = True PCIAddrLabel.Visible = False AddressList.Visible = False RunFlag = False End If If RunFlag Then AddressList.ListIndex = 0 base = "&H" + Mid(AddressList.Text, 14, 4) t = Mid(AddressList.Text, 10, 1) Select Case t Case 2 maxch = 2 PCILabel.Caption = "PCI-DA12-2 Digital-To-Analog Card" Case 4 maxch = 4 PCILabel.Caption = "PCI-DA12-4 Digital-To-Analog Card" Case 6 maxch = 6 PCILabel.Caption = "PCI-DA12-6 Digital-To-Analog Card" Case 8 maxch = 8 PCILabel.Caption = "PCI-DA12-8 Digital-To-Analog Card" Case Else PCILabel.Caption = "PCI-DA12-16 Digital-To-Analog Card" maxch = 16 End Select End If RegCloseKey (hKey) DACButton(0).value = True rangebutton(0).value = True chbutton(0).value = True End Sub Private Sub InitButton_Click() value.Visible = True 'make slider bar visible LOutput.Visible = True If RunFlag Then Select Case True Case rangebutton(0).value: Range = 4 Case rangebutton(1).value: Range = 3 Case rangebutton(2).value: Range = 5 Case rangebutton(3).value: Range = 1 Case rangebutton(4).value: Range = 0 Case rangebutton(5).value: Range = 2 Case rangebutton(6).value: Range = 6 End Select Range = Range * 32 base2 = "&H" + Mid(AddressList.Text, 19, 4) CalibMin = InPortB((base2 + (maxch * 2) + Range)) NewTicks = GetTickCount + 10 Do: DoEvents: Loop While GetTickCount < NewTicks 'Pause for 10ms CalibMax = InPortB((base2 + (maxch * 2) + Range) + 1) If bits = 12 Then CalibMax = CalibMax * 16 CalibMin = CalibMin * 16 End If Else base = "&h" + ISAEdit.Text 'set base address If base <= &H100 Or base >= &H3FF Then 'check if base is okay Beep End If End If 'If RunFlag = True Then InPortB (base + 0) InPortB (base + 15) 'check base variable, what is assigned for PCI 'End If End Sub Private Sub RangeButton_Click(Index As Integer) If rangebutton(0).value = True Then 'set offset and span for output range span = 5 offset = 2.5 ElseIf rangebutton(1).value = True Then span = 10 offset = 5 ElseIf rangebutton(2).value = True Then span = 20 offset = 10 ElseIf rangebutton(3).value = True Then span = 2.5 offset = 0 ElseIf rangebutton(4).value = True Then span = 5 offset = 0 ElseIf rangebutton(5).value = True Then span = 10 offset = 0 ElseIf rangebutton(6).value = True Then span = 16 offset = -4 Else span = 5 offset = 2.5 End If UpdateDAC End Sub Private Sub Value_Scroll() CurVal = value.value UpdateDAC End Sub