VERSION 5.00 Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "comctl32.ocx" Begin VB.Form MainForm Caption = "USB-DIO-32 Sample" ClientHeight = 6435 ClientLeft = 3480 ClientTop = 4815 ClientWidth = 12135 LinkTopic = "Form1" ScaleHeight = 429 ScaleMode = 3 'Pixel ScaleWidth = 809 StartUpPosition = 2 'CenterScreen Begin VB.CheckBox FreqOutButton Caption = "Output 0.25Hz" Height = 375 Index = 2 Left = 10080 Style = 1 'Graphical TabIndex = 16 Top = 3720 Width = 1935 End Begin VB.CheckBox FreqOutButton Caption = "Output 0.25Hz" Height = 375 Index = 1 Left = 10080 Style = 1 'Graphical TabIndex = 15 Top = 3240 Width = 1935 End Begin VB.CheckBox FreqOutButton Caption = "Output 0.25Hz" Height = 375 Index = 0 Left = 10080 Style = 1 'Graphical TabIndex = 14 Top = 2760 Width = 1935 End Begin VB.CheckBox TristateButton Caption = "Tristate All" Height = 375 Left = 120 Style = 1 'Graphical TabIndex = 13 Top = 1920 Width = 11895 End Begin VB.CheckBox OutButton Caption = "Output" Height = 375 Index = 3 Left = 9120 Style = 1 'Graphical TabIndex = 12 Top = 1440 Width = 2895 End Begin VB.CheckBox OutButton Caption = "Output" Height = 375 Index = 2 Left = 6120 Style = 1 'Graphical TabIndex = 11 Top = 1440 Width = 2895 End Begin VB.CheckBox OutButton Caption = "Output" Height = 375 Index = 1 Left = 3120 Style = 1 'Graphical TabIndex = 10 Top = 1440 Width = 2895 End Begin VB.CheckBox OutButton Caption = "Output" Height = 375 Index = 0 Left = 120 Style = 1 'Graphical TabIndex = 9 Top = 1440 Width = 2895 End Begin ComctlLib.Slider FreqOutTrack Height = 375 Index = 0 Left = 120 TabIndex = 6 Top = 2760 Width = 9855 _ExtentX = 17383 _ExtentY = 661 _Version = 327682 LargeChange = 256 Min = 61440 Max = 65533 SelStart = 62071 TickFrequency = 256 Value = 62071 End Begin VB.Timer ReadTime Enabled = 0 'False Interval = 1 Left = 1800 Top = 0 End Begin ComctlLib.Slider FreqOutTrack Height = 375 Index = 1 Left = 120 TabIndex = 7 Top = 3240 Width = 9855 _ExtentX = 17383 _ExtentY = 661 _Version = 327682 LargeChange = 256 Min = 61440 Max = 65533 SelStart = 62071 TickFrequency = 256 Value = 62071 End Begin ComctlLib.Slider FreqOutTrack Height = 375 Index = 2 Left = 120 TabIndex = 8 Top = 3720 Width = 9855 _ExtentX = 17383 _ExtentY = 661 _Version = 327682 LargeChange = 256 Min = 61440 Max = 65533 SelStart = 62071 TickFrequency = 256 Value = 62071 End Begin VB.Label BitLabelD Alignment = 2 'Center Caption = "7" Height = 195 Index = 7 Left = 9120 TabIndex = 48 Top = 720 Width = 375 End Begin VB.Label BitLabelD Alignment = 2 'Center Caption = "6" Height = 195 Index = 6 Left = 9480 TabIndex = 47 Top = 720 Width = 375 End Begin VB.Label BitLabelD Alignment = 2 'Center Caption = "5" Height = 195 Index = 5 Left = 9840 TabIndex = 46 Top = 720 Width = 375 End Begin VB.Label BitLabelD Alignment = 2 'Center Caption = "4" Height = 195 Index = 4 Left = 10200 TabIndex = 45 Top = 720 Width = 375 End Begin VB.Label BitLabelD Alignment = 2 'Center Caption = "3" Height = 195 Index = 3 Left = 10560 TabIndex = 44 Top = 720 Width = 375 End Begin VB.Label BitLabelD Alignment = 2 'Center Caption = "2" Height = 195 Index = 2 Left = 10920 TabIndex = 43 Top = 720 Width = 375 End Begin VB.Label BitLabelD Alignment = 2 'Center Caption = "1" Height = 195 Index = 1 Left = 11280 TabIndex = 42 Top = 720 Width = 375 End Begin VB.Label BitLabelD Alignment = 2 'Center Caption = "0" Height = 195 Index = 0 Left = 11640 TabIndex = 41 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "7" Height = 195 Index = 7 Left = 6120 TabIndex = 40 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "6" Height = 195 Index = 6 Left = 6480 TabIndex = 39 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "5" Height = 195 Index = 5 Left = 6840 TabIndex = 38 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "4" Height = 195 Index = 4 Left = 7200 TabIndex = 37 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "3" Height = 195 Index = 3 Left = 7560 TabIndex = 36 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "2" Height = 195 Index = 2 Left = 7920 TabIndex = 35 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "1" Height = 195 Index = 1 Left = 8280 TabIndex = 34 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "0" Height = 195 Index = 0 Left = 8640 TabIndex = 33 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "7" Height = 195 Index = 7 Left = 3120 TabIndex = 32 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "6" Height = 195 Index = 6 Left = 3480 TabIndex = 31 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "5" Height = 195 Index = 5 Left = 3840 TabIndex = 30 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "4" Height = 195 Index = 4 Left = 4200 TabIndex = 29 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "3" Height = 195 Index = 3 Left = 4560 TabIndex = 28 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "2" Height = 195 Index = 2 Left = 4920 TabIndex = 27 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "1" Height = 195 Index = 1 Left = 5280 TabIndex = 26 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "0" Height = 195 Index = 0 Left = 5640 TabIndex = 25 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "7" Height = 195 Index = 7 Left = 120 TabIndex = 24 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "6" Height = 195 Index = 6 Left = 480 TabIndex = 23 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "5" Height = 195 Index = 5 Left = 840 TabIndex = 22 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "4" Height = 195 Index = 4 Left = 1200 TabIndex = 21 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "3" Height = 195 Index = 3 Left = 1560 TabIndex = 20 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "2" Height = 195 Index = 2 Left = 1920 TabIndex = 19 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "1" Height = 195 Index = 1 Left = 2280 TabIndex = 18 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "0" Height = 195 Index = 0 Left = 2640 TabIndex = 17 Top = 720 Width = 375 End Begin VB.Image LowLevel Enabled = 0 'False Height = 360 Left = 4200 Picture = "MainForm.frx":0000 Top = 0 Visible = 0 'False Width = 360 End Begin VB.Image HighLevel Enabled = 0 'False Height = 360 Left = 4680 Picture = "MainForm.frx":04CE Top = 0 Visible = 0 'False Width = 360 End Begin VB.Label CounterLabel Caption = "Counters" Height = 255 Left = 120 TabIndex = 5 Top = 2400 Width = 975 End Begin VB.Image LevelImage Height = 375 Index = 31 Left = 9120 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 30 Left = 9480 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 29 Left = 9840 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 28 Left = 10200 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 27 Left = 10560 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 26 Left = 10920 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 25 Left = 11280 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 24 Left = 11640 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 23 Left = 6120 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 22 Left = 6480 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 21 Left = 6840 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 20 Left = 7200 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 19 Left = 7560 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 18 Left = 7920 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 17 Left = 8280 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 16 Left = 8640 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 15 Left = 3120 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 14 Left = 3480 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 13 Left = 3840 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 12 Left = 4200 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 11 Left = 4560 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 10 Left = 4920 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 9 Left = 5280 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 8 Left = 5640 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 7 Left = 120 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 6 Left = 480 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 5 Left = 840 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 4 Left = 1200 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 3 Left = 1560 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 2 Left = 1920 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 1 Left = 2280 Top = 960 Width = 375 End Begin VB.Image LevelImage Height = 375 Index = 0 Left = 2640 Top = 960 Width = 375 End Begin VB.Label PortDLabel Caption = "Port D" Height = 255 Left = 9120 TabIndex = 4 Top = 480 Width = 975 End Begin VB.Label PortCLabel Caption = "Port C" Height = 255 Left = 6120 TabIndex = 3 Top = 480 Width = 975 End Begin VB.Label PortBLabel Caption = "Port B" Height = 255 Left = 3120 TabIndex = 2 Top = 480 Width = 975 End Begin VB.Label PortALbael Caption = "Port A" Height = 255 Left = 120 TabIndex = 1 Top = 480 Width = 975 End Begin VB.Label DigitalLabel Caption = "Digital I/O" Height = 255 Left = 120 TabIndex = 0 Top = 120 Width = 975 End End Attribute VB_Name = "MainForm" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Public DeviceIndex As Long Dim DIOData As Long Dim DoUpdate As Boolean Public DetectOK As Boolean Private Function FormatFreq(Freq As Double) As String If Freq >= 1000000 Then FormatFreq = Format$(Freq / 1000000, "0.0MHz") ElseIf Freq >= 10000 Then FormatFreq = Format$(Freq / 1000, "0.0KHz") ElseIf Freq >= 1000 Then FormatFreq = Format$(Freq / 1000, "0.0KHz") ElseIf Freq >= 10 Then FormatFreq = Format$(Freq, "0.00Hz") ElseIf Freq >= 1 Then FormatFreq = Format$(Freq, "0.00Hz") Else FormatFreq = Format$(Freq, "0.00Hz") End If End Function Private Sub Form_Load() Dim OutMask As Byte Dim I As Integer Dim Status As Long DeviceIndex = diOnly OutMask = &H0 DIOData = &HFFFFFFFF Status = DIO_Configure(ByVal DeviceIndex, False, OutMask, DIOData) If Status <> ERROR_SUCCESS Then Call DetectForm.Show(vbModal, Me) If DetectOK = False Then Unload Me Exit Sub End If End If For I = 0 To 2 Call CTR_8254Mode(DeviceIndex, I, 1, 2) Call CTR_8254Mode(DeviceIndex, I, 2, 3) Next I DoUpdate = True ReadTime.Enabled = True End Sub Private Sub Form_Unload(Cancel As Integer) ReadTime.Enabled = False End Sub Private Sub FreqOutButton_Click(Index As Integer) Dim CounterValue As Long If FreqOutButton(Index).Value = 1 Then CounterValue = 65535 - FreqOutTrack(Index).Value Call CTR_8254ModeLoad(DeviceIndex, Index, 1, 2, CounterValue) Call CTR_8254ModeLoad(DeviceIndex, Index, 2, 3, CounterValue) Else Call CTR_8254Mode(DeviceIndex, Index, 1, 2) Call CTR_8254Mode(DeviceIndex, Index, 2, 3) End If End Sub Private Sub FreqOutTrack_Change(Index As Integer) Dim CounterValue As Long CounterValue = 65535 - FreqOutTrack(Index).Value FreqOutButton(Index).Caption = "Output " + FormatFreq(3000000 / (CDbl(CounterValue) * CounterValue)) If FreqOutButton(Index).Value = 1 Then Call CTR_8254ModeLoad(DeviceIndex, Index, 1, 2, CounterValue) Call CTR_8254ModeLoad(DeviceIndex, Index, 2, 3, CounterValue) End If End Sub Private Sub LevelImage_Click(Index As Integer) Dim NewValue As Boolean If Index = 31 Then 'since there is no unsigned type in Visual Basic 6.0 'an index of 31 becomes a special case DIOData = DIOData Xor &H80000000 NewValue = (DIOData < 0) Else DIOData = DIOData Xor (2 ^ Index) 'Toggle bit NewValue = (DIOData And (2 ^ Index)) <> 0 'Get bit value End If Call DIO_Write1(DeviceIndex, Index, NewValue) DoUpdate = True End Sub Private Sub OutButton_Click(Index As Integer) Dim I As Integer Dim OutMask As Byte Dim TristateChecked As Boolean OutMask = &H0 For I = 0 To 3 If OutButton(I).Value = 1 Then OutMask = OutMask Or (2 ^ I) End If Next I TristateChecked = (TristateButton.Value = 1) Call DIO_Configure(DeviceIndex, TristateChecked, OutMask, DIOData) DoUpdate = True End Sub Private Sub ReadTime_Timer() Dim I As Integer Dim oDIOData As Long Dim Changes As Long oDIOData = DIOData Call DIO_ReadAll(DeviceIndex, DIOData) Changes = DIOData Xor oDIOData If DoUpdate Then Changes = &HFFFFFFFF DoUpdate = False End If For I = 0 To 30 If (Changes And (2 ^ I)) <> 0 Then If (DIOData And (2 ^ I)) <> 0 Then LevelImage(I).Picture = HighLevel.Picture Else LevelImage(I).Picture = LowLevel.Picture End If 'DIOData End If 'Changes Next I If DIOData < 0 Then LevelImage(31).Picture = HighLevel.Picture Else LevelImage(31).Picture = LowLevel.Picture End If End Sub Private Sub TristateButton_Click() Dim I As Integer Dim OutMask As Byte Dim TristateChecked As Boolean OutMask = &H0 For I = 0 To 3 If OutButton(I).Value = 1 Then OutMask = OutMask Or (2 ^ I) End If Next I TristateChecked = (TristateButton.Value = 1) Call DIO_Configure(DeviceIndex, TristateChecked, OutMask, DIOData) End Sub