VERSION 5.00 Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "comctl32.ocx" Begin VB.Form MainForm Caption = "USB-CTR-15 Sample" ClientHeight = 7605 ClientLeft = 3480 ClientTop = 4815 ClientWidth = 12135 BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty LinkTopic = "Form1" ScaleHeight = 507 ScaleMode = 3 'Pixel ScaleWidth = 809 StartUpPosition = 2 'CenterScreen Begin VB.CommandButton Command1 BackColor = &H8000000D& Caption = "Click here to start sample." Height = 615 Left = 7560 Style = 1 'Graphical TabIndex = 30 Top = 1560 Width = 3015 End Begin VB.CheckBox FreqOutButton Caption = "Output 0.25Hz" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Index = 4 Left = 10080 Style = 1 'Graphical TabIndex = 8 Top = 5160 Width = 1935 End Begin VB.CheckBox FreqOutButton Caption = "Output 0.25Hz" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Index = 3 Left = 10080 Style = 1 'Graphical TabIndex = 6 Top = 4680 Width = 1935 End Begin VB.CheckBox FreqOutButton Caption = "Output 0.25Hz" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Index = 2 Left = 10080 Style = 1 'Graphical TabIndex = 5 Top = 4200 Width = 1935 End Begin VB.CheckBox FreqOutButton Caption = "Output 0.25Hz" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Index = 1 Left = 10080 Style = 1 'Graphical TabIndex = 4 Top = 3720 Width = 1935 End Begin VB.CheckBox FreqOutButton Caption = "Output 0.25Hz" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Index = 0 Left = 10080 Style = 1 'Graphical TabIndex = 3 Top = 3240 Width = 1935 End Begin ComctlLib.Slider FreqOutTrack Height = 375 Index = 0 Left = 120 TabIndex = 0 Top = 3240 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 = 100 Left = 11400 Top = 0 End Begin ComctlLib.Slider FreqOutTrack Height = 375 Index = 1 Left = 120 TabIndex = 1 Top = 3720 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 = 2 Top = 4200 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 = 3 Left = 120 TabIndex = 7 Top = 4680 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 = 4 Left = 120 TabIndex = 9 Top = 5160 Width = 9855 _ExtentX = 17383 _ExtentY = 661 _Version = 327682 LargeChange = 256 Min = 61440 Max = 65533 SelStart = 62071 TickFrequency = 256 Value = 62071 End Begin VB.Label Label6 Alignment = 2 'Center Caption = "WARNING: This will load all counters, and may cause outputs to change. Make sure you have nothing dangerous connected." Height = 975 Left = 7560 TabIndex = 31 Top = 2160 Width = 3015 WordWrap = -1 'True End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 14 Left = 3720 TabIndex = 29 Top = 2040 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 13 Left = 3120 TabIndex = 28 Top = 2040 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 12 Left = 2520 TabIndex = 27 Top = 2040 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 11 Left = 1440 TabIndex = 26 Top = 2040 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 10 Left = 840 TabIndex = 25 Top = 2040 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 9 Left = 240 TabIndex = 24 Top = 2040 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 8 Left = 6120 TabIndex = 23 Top = 840 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 7 Left = 5520 TabIndex = 22 Top = 840 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 6 Left = 4920 TabIndex = 21 Top = 840 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 5 Left = 3720 TabIndex = 20 Top = 840 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 4 Left = 3120 TabIndex = 19 Top = 840 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 3 Left = 2520 TabIndex = 18 Top = 840 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 2 Left = 1440 TabIndex = 17 Top = 840 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 1 Left = 840 TabIndex = 16 Top = 840 Width = 495 End Begin VB.Label ctrLbl BorderStyle = 1 'Fixed Single Caption = "0000" Height = 255 Index = 0 Left = 240 TabIndex = 15 Top = 840 Width = 495 End Begin VB.Label Label5 Caption = "BLOCK 4" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 2880 TabIndex = 14 Top = 1680 Width = 1095 End Begin VB.Label Label4 Caption = "BLOCK 3" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 600 TabIndex = 13 Top = 1680 Width = 1095 End Begin VB.Label Label3 Caption = "BLOCK 2" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 5160 TabIndex = 12 Top = 360 Width = 1095 End Begin VB.Label Label2 Caption = "BLOCK 1" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 2880 TabIndex = 11 Top = 360 Width = 1095 End Begin VB.Label Label1 Caption = "BLOCK 0" BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 600 TabIndex = 10 Top = 360 Width = 1095 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 Command1_Click() Dim I As Long For I = 0 To 4 CTR_8254ModeLoad DeviceIndex, I, 0, 2, 0 CTR_8254ModeLoad DeviceIndex, I, 1, 2, 0 CTR_8254ModeLoad DeviceIndex, I, 2, 3, 0 Next End Sub 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 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(10000000 / (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 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 3 If FreqOutButton(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 block As Long Dim count As Long Dim readings(14) As Integer CTR_8254ReadAll DeviceIndex, readings(0) For count = 0 To 14 ctrLbl(count).Caption = Hex(readings(count)) Next count 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 FreqOutButton(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