VERSION 5.00 Begin VB.Form MainForm Caption = "Form1" ClientHeight = 3495 ClientLeft = 60 ClientTop = 345 ClientWidth = 9015 LinkTopic = "Form1" ScaleHeight = 233 ScaleMode = 3 'Pixel ScaleWidth = 601 StartUpPosition = 2 'CenterScreen Begin VB.ListBox VoltList Columns = 4 Height = 3180 Left = 1920 TabIndex = 6 Top = 120 Width = 6975 End Begin VB.ComboBox CalEdit Height = 315 ItemData = "MainForm.frx":0000 Left = 120 List = "MainForm.frx":000A TabIndex = 5 Text = ":AUTO:" Top = 360 Width = 1695 End Begin VB.CheckBox DiffCheck Caption = "Differential" Height = 255 Left = 120 TabIndex = 3 Top = 1320 Width = 1695 End Begin VB.Timer ADPollTime Enabled = 0 'False Interval = 1 Left = 120 Top = 2160 End Begin VB.CommandButton GoButton Caption = "Go" Height = 375 Left = 120 TabIndex = 4 Top = 1680 Width = 1695 End Begin VB.ComboBox RangeCombo Height = 315 ItemData = "MainForm.frx":001E Left = 120 List = "MainForm.frx":003A Style = 2 'Dropdown List TabIndex = 2 Top = 960 Width = 1695 End Begin VB.Label Label2 Alignment = 2 'Center Caption = "Analog Range" Height = 255 Left = 120 TabIndex = 1 Top = 720 Width = 1695 End Begin VB.Label CalLabel Alignment = 2 'Center Caption = "Calib. File" Height = 255 Left = 120 TabIndex = 0 Top = 120 Width = 1695 End End Attribute VB_Name = "MainForm" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private Declare Sub Sleep Lib "Kernel32" (ByVal MinDurMS As Long) 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 ADData(0 To (128 * 4 * 1024& - 1)) As Integer '4K scans of 128 channels. Dim bGoing As Boolean Dim KnownBytesLeft As Long Dim NextSample As Long, NextChannel As Long Dim Channels As Long Private Sub ADPollTime_Timer() Dim BytesLeft As Long Dim Volts As Double Dim RangeCode As Byte Dim Hz As Double Dim Counts As Long Dim Status As Long Status = ADC_BulkPoll(DeviceIndex, BytesLeft) If Status <> 0 Then Beep Hz = 0 CTR_StartOutputFreq DeviceIndex, 0, Hz ADPollTime.Enabled = False GoButton.Enabled = True RangeCombo.Enabled = True CalEdit.Enabled = True MsgBox "Error " & Status & " from ADC_BulkPoll.", vbExclamation, "ADC_BulkPoll Error" Exit Sub End If If BytesLeft >= KnownBytesLeft Then Exit Sub 'If we get here, some data has been taken. If BytesLeft = 0 Then 'Stop the counter. Hz = 0 CTR_StartOutputFreq DeviceIndex, 0, Hz ADPollTime.Enabled = False GoButton.Enabled = True RangeCombo.Enabled = True CalEdit.Enabled = True End If 'We're going to use the range code to convert to volts. RangeCode = RangeCombo.ListIndex Do Counts = ADData(NextSample) And &HFFFF& Volts = Counts / &HFFFF& '"Volts" now holds a value from 0 to 1. If (RangeCode And &H1) <> 0 Then 'Bit 0(mask 01 hex) indicates bipolar. Volts = Volts * 2 - 1 '"Volts" now holds a value from -1 to +1. End If If (RangeCode And &H2) = 0 Then 'Bit 1(mask 02 hex) indicates x2 gain. Volts = Volts * 2 End If If (RangeCode And &H4) = 0 Then 'Bit 2(mask 04 hex) indicates x5 gain. Volts = Volts * 5 End If '"Volts" now holds volts. VoltList.List(NextChannel) = "Ch " & NextChannel & ": " & CLng(Volts * 1000) / 1000 & " V" NextChannel = (NextChannel + 1) Mod Channels NextSample = NextSample + 1 KnownBytesLeft = KnownBytesLeft - 2 Loop Until KnownBytesLeft = BytesLeft 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 = LenB(Config) ADC_SetConfig DeviceIndex, Config, ConfigBufSize NextChannel = 0 End Sub Private Sub GoButton_Click() Dim Hz As Double Dim Status As Long Dim ConfigBufSize As Long Dim StartChannel As Byte, EndChannel As Byte 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) Status = ADC_SetConfig(DeviceIndex, Config, ConfigBufSize) NextChannel = 0 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 DoEvents bGoing = True KnownBytesLeft = (UBound(ADData) + 1) * 2 ADC_BulkAcquire DeviceIndex, KnownBytesLeft, ADData(0) NextSample = 0 'Give the worker thread time to get started on slower CPUs. Sleep 1 'Start the counter. Hz = 3000 CTR_StartOutputFreq DeviceIndex, 0, Hz ADPollTime.Enabled = True End Sub Private Sub RangeCombo_Click() Dim I As Long Dim RangeCode As Byte Dim bNewVisible As Boolean 'The ranges in the combo box are listed in order, so that the index is equal 'to the range code. RangeCode = RangeCombo.ListIndex For I = &H0 To &HF Config.ChannelRange(I) = RangeCode Next End Sub