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 = 5 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 = 2 Top = 840 Width = 1695 End Begin VB.CommandButton GoButton Caption = "Go" Height = 375 Left = 0 TabIndex = 1 Top = 1560 Width = 1695 End Begin VB.Timer ADPollTime Enabled = 0 'False Interval = 45 Left = 240 Top = 2640 End Begin VB.ComboBox CalEdit Height = 315 ItemData = "MainForm.frx":0096 Left = 0 List = "MainForm.frx":00A0 TabIndex = 0 Text = ":AUTO:" Top = 240 Width = 1695 End Begin VB.Label CalLabel Alignment = 2 'Center Caption = "Calib. File" Height = 255 Left = 0 TabIndex = 4 Top = 0 Width = 1695 End Begin VB.Label Label2 Alignment = 2 'Center Caption = "Analog Range" Height = 255 Left = 0 TabIndex = 3 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 Dim Channels As Long Private Sub ADPollTime_Timer() Dim Status As Long Dim Volts() As Double Dim Channel As Long ReDim Volts(Channels - 1) 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 For Channel = 0 To Channels - 1 VoltList.List(Channel) = "Ch " & Channel & ": " & Volts(Channel) & " V" Next End Sub Private Sub Form_Load() Dim Dlg As DetectForm Dim Status As Long Dim Hz As Double Dim ConfigBufSize As Long Dim bRightType As Boolean Dim PID As Long 'dummy variables for function call since we can't do null in VBasic 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) bRightType = False If (PID >= &H804A&) And (PID <= &H805D&) Then bRightType = True 'USB-AI boards with AIMUX32. If (PID >= &H814A&) And (PID <= &H815D&) Then bRightType = True 'USB-AIO boards with AIMUX32. If (Status <> 0) Or Not bRightType Then Set Dlg = New DetectForm Dlg.Show vbModal DeviceIndex = Dlg.DeviceIndex Unload Dlg If DeviceIndex = -1 Then Unload Me Exit Sub End If QueryDeviceInfo DeviceIndex, PID, NameSize, Name, DIOBytes, Counters End If Select Case PID Case &H804A& To &H804E& Channels = 32 Case &H804F& To &H8053& Channels = 64 Case &H8054& To &H8058& Channels = 96 Case &H8059& To &H805D& Channels = 128 Case &H814A& To &H814E& Channels = 32 Case &H814F& To &H8153& Channels = 64 Case &H8154& To &H8158& Channels = 96 Case &H8159& To &H815D& Channels = 128 End Select 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 EndChannel = Channels - 1 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 CalEdit.Enabled = False RangeCombo.Enabled = False GoButton.Enabled = False StopButton.Enabled = True 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 'Config.ChannelRange[0] controls channels &H00 through &H07; 'Config.ChannelRange[1] controls channels &H08 through &H0F; 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 End Sub