VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 4815 ClientLeft = 60 ClientTop = 345 ClientWidth = 10095 LinkTopic = "Form1" ScaleHeight = 321 ScaleMode = 3 'Pixel ScaleWidth = 673 StartUpPosition = 3 'Windows Default Begin VB.CommandButton StopButton Caption = "Stop" Height = 375 Left = 0 TabIndex = 6 Top = 2040 Width = 1695 End Begin VB.ListBox VoltList Columns = 4 Height = 4545 ItemData = "MainForm.frx":0000 Left = 1800 List = "MainForm.frx":0007 TabIndex = 7 Top = 120 Width = 8175 End Begin VB.ComboBox RangeCombo Height = 315 ItemData = "MainForm.frx":0015 Left = 0 List = "MainForm.frx":0031 Style = 2 'Dropdown List TabIndex = 3 Top = 840 Width = 1695 End Begin VB.CommandButton GoButton Caption = "Go" Height = 375 Left = 0 TabIndex = 5 Top = 1560 Width = 1695 End Begin VB.Timer ADPollTime Enabled = 0 'False Interval = 45 Left = 240 Top = 2640 End Begin VB.CheckBox DiffCheck Caption = "Differential" Height = 255 Left = 0 TabIndex = 4 Top = 1200 Width = 1695 End Begin VB.ComboBox CalEdit Height = 315 ItemData = "MainForm.frx":0096 Left = 0 List = "MainForm.frx":00A0 TabIndex = 1 Text = ":AUTO:" Top = 240 Width = 1695 End Begin VB.Label CalLabel Alignment = 2 'Center Caption = "Calib. File" Height = 255 Left = 0 TabIndex = 0 Top = 0 Width = 1695 End Begin VB.Label Label2 Alignment = 2 'Center Caption = "Analog Range" Height = 255 Left = 0 TabIndex = 2 Top = 600 Width = 1695 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 Type TUSBAI1664Config ChannelRange(0 To &HF) As Byte CalibMode As Byte TrigMode As Byte StartStopCh As Byte Oversample As Byte AIMUXChEx As Byte 'AIMUX start and end address bit extension register. D0 to D2=start pair, D4 to D6=end pair. End Type Dim DeviceIndex As Long Dim Config As TUSBAI1664Config Const Channels = 64 Private Sub ADPollTime_Timer() Dim Status As Long Dim Volts(0 To Channels - 1) As Double Dim Channel As Long, ChannelsUsed As Long Status = ADC_GetScanV(DeviceIndex, Volts(0)) If Status <> 0 Then StopButton.Value = True MsgBox "Error " & Status & " from ADC_GetScanV.", , "ADC_GetScanV Error" Exit Sub End If If DiffCheck.Value Then ChannelsUsed = Channels \ 2 Else ChannelsUsed = Channels End If For Channel = 0 To ChannelsUsed - 1 VoltList.List(Channel) = "Ch " & Channel & ": " & Volts(Channel) & " V" Next End Sub Private Sub DiffCheck_Click() RangeCombo_Click End Sub Private Sub Form_Load() Dim Dlg As DetectForm Dim Status As Long Dim Hz As Double Dim ConfigBufSize As Long 'dummy variables for function call since we can't do null in VBasic Dim PID As Long Dim NameSize As Long Dim Name As String Dim DIOBytes As Long Dim Counters As Long Dim outdata As Long CalEdit.ListIndex = 0 NameSize = 256 Name = String$(NameSize, " ") 'If you only have the one board, QueryDeviceInfo with diOnly will succeed 'with the right PID. If you have more than one board, or haven't plugged it 'in, it will fail, and this code will pop up the detector form so the user 'can pick a board or cancel. DeviceIndex = diOnly Status = QueryDeviceInfo(DeviceIndex, PID, NameSize, Name, DIOBytes, Counters) If (Status <> 0) Or Not (((PID >= &H8045&) And (PID <= &H8049&)) Or ((PID >= &H8145&) And (PID <= &H8149&))) Then Set Dlg = New DetectForm Dlg.Show vbModal DeviceIndex = Dlg.DeviceIndex Unload Dlg If DeviceIndex = -1 Then Unload Me Exit Sub End If End If If ADC_QueryCal(DeviceIndex) <> 0 Then 'this board doesn't have calibration CalLabel.Visible = False CalEdit.Visible = False End If 'Stop the counter, in case it was running. Hz = 0 CTR_StartOutputFreq DeviceIndex, 0, Hz 'Set the combo box to the first A/D range, then call RangeCombo_Click to 'set all the channels to that range. RangeCombo.ListIndex = 0 RangeCombo_Click Config.CalibMode = 0 'Take actual data, not internal calibration sources. Config.TrigMode = &H5 'Scan selected channels each counter rising edge. Config.StartStopCh = &HF0 'Select all 16 channels, from 0 to 15. 'If changing this, change NumChannels, up above. Config.Oversample = 0 'No oversample. ConfigBufSize = 20 'SizeOf(Config) ADC_SetConfig DeviceIndex, Config, ConfigBufSize End Sub Private Sub GoButton_Click() Dim Status As Long Dim StartChannel As Byte, EndChannel As Byte Dim ConfigBufSize As Long StartChannel = 0 If DiffCheck.Value Then EndChannel = (Channels \ 2) - 1 Else EndChannel = Channels - 1 End If Config.StartStopCh = ((EndChannel And &HF) * 16) Or (StartChannel And &HF) Config.AIMUXChEx = (EndChannel And &HF0) Or (StartChannel \ 16) ConfigBufSize = LenB(Config) ADC_SetConfig DeviceIndex, Config, ConfigBufSize If CalEdit.Visible Then Status = ADC_SetCal(DeviceIndex, CalEdit.Text) If Status <> 0 Then MsgBox "Calibration Error " & Status Exit Sub End If End If VoltList.Clear CalEdit.Enabled = False RangeCombo.Enabled = False GoButton.Enabled = False StopButton.Enabled = True DiffCheck.Enabled = False ADPollTime.Enabled = True End Sub Private Sub RangeCombo_Click() Dim I As Long Dim RangeCode As Byte Dim NewHeight As Long 'The ranges in the combo box are listed in order, so that the index is equal 'to the range code. RangeCode = RangeCombo.ListIndex If DiffCheck.Value Then RangeCode = RangeCode Or &H8 'Config.ChannelRange[0] controls channels $00, $10, $20, etc; 'Config.ChannelRange[1] controls channels $01, $11, $21, etc; etc. 'For simplicity, we set 'em all to the same range. For I = &H0 To &HF Config.ChannelRange(I) = RangeCode Next End Sub Private Sub StopButton_Click() ADPollTime.Enabled = False CalEdit.Enabled = True RangeCombo.Enabled = True GoButton.Enabled = True StopButton.Enabled = False DiffCheck.Enabled = True End Sub