VERSION 5.00 Begin VB.Form MainForm Caption = "USB-DIO-32 Sample" ClientHeight = 2415 ClientLeft = 3480 ClientTop = 4815 ClientWidth = 9135 LinkTopic = "Form1" ScaleHeight = 161 ScaleMode = 3 'Pixel ScaleWidth = 609 StartUpPosition = 2 'CenterScreen Begin VB.CheckBox TristateButton Caption = "Tristate All" Height = 375 Left = 120 Style = 1 'Graphical TabIndex = 6 Top = 1920 Width = 5895 End Begin VB.CheckBox OutButton Caption = "Output" Height = 375 Index = 1 Left = 3120 Style = 1 'Graphical TabIndex = 5 Top = 1440 Width = 2895 End Begin VB.CheckBox OutButton Caption = "Output" Height = 375 Index = 0 Left = 120 Style = 1 'Graphical TabIndex = 4 Top = 1440 Width = 2895 End Begin VB.Timer ReadTime Enabled = 0 'False Interval = 1 Left = 1800 Top = 0 End Begin VB.Label Label1 Caption = "Relays" Height = 255 Left = 6120 TabIndex = 31 Top = 120 Width = 975 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "7" Height = 195 Index = 7 Left = 6120 TabIndex = 30 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "6" Height = 195 Index = 6 Left = 6480 TabIndex = 29 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "5" Height = 195 Index = 5 Left = 6840 TabIndex = 28 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "4" Height = 195 Index = 4 Left = 7200 TabIndex = 27 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "3" Height = 195 Index = 3 Left = 7560 TabIndex = 26 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "2" Height = 195 Index = 2 Left = 7920 TabIndex = 25 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "1" Height = 195 Index = 1 Left = 8280 TabIndex = 24 Top = 720 Width = 375 End Begin VB.Label BitLabelC Alignment = 2 'Center Caption = "0" Height = 195 Index = 0 Left = 8640 TabIndex = 23 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "7" Height = 195 Index = 7 Left = 3120 TabIndex = 22 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "6" Height = 195 Index = 6 Left = 3480 TabIndex = 21 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "5" Height = 195 Index = 5 Left = 3840 TabIndex = 20 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "4" Height = 195 Index = 4 Left = 4200 TabIndex = 19 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "3" Height = 195 Index = 3 Left = 4560 TabIndex = 18 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "2" Height = 195 Index = 2 Left = 4920 TabIndex = 17 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "1" Height = 195 Index = 1 Left = 5280 TabIndex = 16 Top = 720 Width = 375 End Begin VB.Label BitLabelB Alignment = 2 'Center Caption = "0" Height = 195 Index = 0 Left = 5640 TabIndex = 15 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "7" Height = 195 Index = 7 Left = 120 TabIndex = 14 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "6" Height = 195 Index = 6 Left = 480 TabIndex = 13 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "5" Height = 195 Index = 5 Left = 840 TabIndex = 12 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "4" Height = 195 Index = 4 Left = 1200 TabIndex = 11 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "3" Height = 195 Index = 3 Left = 1560 TabIndex = 10 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "2" Height = 195 Index = 2 Left = 1920 TabIndex = 9 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "1" Height = 195 Index = 1 Left = 2280 TabIndex = 8 Top = 720 Width = 375 End Begin VB.Label BitLabelA Alignment = 2 'Center Caption = "0" Height = 195 Index = 0 Left = 2640 TabIndex = 7 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.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 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 Private Declare Function DIO_Configure Lib "AIOUSB" Alias "VBDIO_Configure" (ByVal DeviceIndex As Long, ByVal Tristate As Boolean, ByRef OutMask As Any, ByRef Data As Any) As Long Private Declare Function CTR_8254Mode Lib "AIOUSB" Alias "VBCTR_8254Mode" (ByVal DeviceIndex As Long, ByVal BlockIndex As Long, ByVal CounterIndex As Long, ByVal Mode As Long) As Long Private Declare Function CTR_8254ModeLoad Lib "AIOUSB" Alias "VBCTR_8254ModeLoad" (ByVal DeviceIndex As Long, ByVal BlockIndex As Long, ByVal CounterIndex As Long, ByVal Mode As Long, ByVal LoadValue As Integer) As Long Private Declare Function DIO_Write1 Lib "AIOUSB" Alias "VBDIO_Write1" (ByVal DeviceIndex As Long, ByVal BitIndex As Long, ByVal Data As Boolean) As Long Private Declare Function DIO_ReadAll Lib "AIOUSB" Alias "VBDIO_ReadAll" (ByVal DeviceIndex As Long, ByRef Data As Any) As Long 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) End Sub Private Sub FreqOutTrack_Change(Index As Integer) End Sub Private Sub LevelImage_Click(Index As Integer) Dim NewValue As Boolean DIOData = DIOData Xor (2 ^ Index) 'Toggle bit NewValue = (DIOData And (2 ^ Index)) <> 0 'Get bit value 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 1 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 23 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 End Sub Private Sub TristateButton_Click() Dim I As Integer Dim OutMask As Byte Dim TristateChecked As Boolean OutMask = &H0 For I = 0 To 1 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