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 (64 * 4 * 1024& - 1)) As Integer '4K scans of 64 channels, or 8K scans of 32 differential channels. Dim bGoing As Boolean Dim KnownBytesLeft As Long Dim NextSample As Long, NextChannel As Long Const Channels = 64 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 Dim ChannelsUsed 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 DiffCheck.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 If DiffCheck.Value Then ChannelsUsed = Channels \ 2 Else ChannelsUsed = Channels End If Do Counts = ADData(NextSample) And &HFFFF& 'We're going to use the range code to convert to volts. RangeCode = Config.ChannelRange(NextChannel \ 4) 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 ChannelsUsed NextSample = NextSample + 1 KnownBytesLeft = KnownBytesLeft - 2 Loop Until KnownBytesLeft = BytesLeft 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 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 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 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 = 1500 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 If DiffCheck.Value Then RangeCode = RangeCode Or &H8 'Config.ChannelRange[0] controls channels &H00 through &H03; 'Config.ChannelRange[1] controls channels &H04 through &H07; etc. For I = &H0 To &HF Config.ChannelRange(I) = RangeCode Next End Sub