VERSION 5.00 Begin VB.Form Sample1 Caption = "Form1" ClientHeight = 4785 ClientLeft = 4485 ClientTop = 4815 ClientWidth = 10035 LinkTopic = "Form1" ScaleHeight = 4785 ScaleWidth = 10035 Begin VB.Timer Timer1 Left = 5880 Top = 360 End Begin VB.TextBox TextB Height = 285 Left = 7800 TabIndex = 38 Text = "FF" Top = 1920 Width = 1095 End Begin VB.TextBox TextA Height = 285 Left = 5640 TabIndex = 37 Text = "FF" Top = 1920 Width = 1095 End Begin VB.CommandButton WriteBbtn Caption = "Write Port B" Height = 255 Left = 7680 TabIndex = 4 Top = 2400 Width = 1335 End Begin VB.CommandButton WriteAbtn Caption = "Write Port A" Height = 255 Left = 5520 TabIndex = 3 Top = 2400 Width = 1335 End Begin VB.Frame Frame1 Caption = "Key" Height = 1095 Left = 960 TabIndex = 0 Top = 120 Width = 4575 Begin VB.Label Label4 Alignment = 1 'Right Justify Caption = "Relay is De-Energized/Input is low: " Height = 255 Left = 120 TabIndex = 40 Top = 720 Width = 3255 End Begin VB.Label Label3 Alignment = 1 'Right Justify Caption = "Relay is Energized/Input is high:" Height = 255 Left = 120 TabIndex = 39 Top = 240 Width = 3255 End Begin VB.Label Label2 BackColor = &H0000FF00& Height = 255 Left = 3480 TabIndex = 2 Top = 240 Width = 255 End Begin VB.Label Label1 BackColor = &H000000FF& Height = 255 Left = 3480 TabIndex = 1 Top = 720 Width = 255 End End Begin VB.Label Instructions Caption = "Label5" Height = 1215 Left = 720 TabIndex = 41 Top = 2880 Width = 8415 End Begin VB.Label OutPortPnlB BackColor = &H0000FF00& Height = 135 Index = 7 Left = 7560 MousePointer = 10 'Up Arrow TabIndex = 36 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlB BackColor = &H0000FF00& Height = 135 Index = 6 Left = 7800 MousePointer = 10 'Up Arrow TabIndex = 35 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlB BackColor = &H0000FF00& Height = 135 Index = 5 Left = 8040 MousePointer = 10 'Up Arrow TabIndex = 34 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlB BackColor = &H0000FF00& Height = 135 Index = 4 Left = 8280 MousePointer = 10 'Up Arrow TabIndex = 33 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlB BackColor = &H0000FF00& Height = 135 Index = 3 Left = 8520 MousePointer = 10 'Up Arrow TabIndex = 32 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlB BackColor = &H0000FF00& Height = 135 Index = 2 Left = 8760 MousePointer = 10 'Up Arrow TabIndex = 31 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlB BackColor = &H0000FF00& Height = 135 Index = 1 Left = 9000 MousePointer = 10 'Up Arrow TabIndex = 30 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlB BackColor = &H0000FF00& Height = 135 Index = 0 Left = 9240 MousePointer = 10 'Up Arrow TabIndex = 29 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlA BackColor = &H0000FF00& Height = 135 Index = 7 Left = 5280 MouseIcon = "Form1.frx":0000 MousePointer = 10 'Up Arrow TabIndex = 28 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlA BackColor = &H0000FF00& Height = 135 Index = 6 Left = 5520 MouseIcon = "Form1.frx":0152 MousePointer = 10 'Up Arrow TabIndex = 27 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlA BackColor = &H0000FF00& Height = 135 Index = 5 Left = 5760 MouseIcon = "Form1.frx":02A4 MousePointer = 10 'Up Arrow TabIndex = 26 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlA BackColor = &H0000FF00& Height = 135 Index = 4 Left = 6000 MouseIcon = "Form1.frx":03F6 MousePointer = 10 'Up Arrow TabIndex = 25 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlA BackColor = &H0000FF00& Height = 135 Index = 3 Left = 6240 MouseIcon = "Form1.frx":0548 MousePointer = 10 'Up Arrow TabIndex = 24 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlA BackColor = &H0000FF00& Height = 135 Index = 2 Left = 6480 MouseIcon = "Form1.frx":069A MousePointer = 10 'Up Arrow TabIndex = 23 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlA BackColor = &H0000FF00& Height = 135 Index = 1 Left = 6720 MouseIcon = "Form1.frx":07EC MousePointer = 10 'Up Arrow TabIndex = 22 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlA BackColor = &H0000FF00& Height = 135 Index = 0 Left = 6960 MouseIcon = "Form1.frx":093E MousePointer = 10 'Up Arrow TabIndex = 21 Top = 1560 Width = 135 End Begin VB.Label InPortBPnl BackColor = &H000000FF& Height = 135 Index = 7 Left = 2520 TabIndex = 20 Top = 1560 Width = 135 End Begin VB.Label InPortBPnl BackColor = &H000000FF& Height = 135 Index = 6 Left = 2760 TabIndex = 19 Top = 1560 Width = 135 End Begin VB.Label InPortBPnl BackColor = &H000000FF& Height = 135 Index = 5 Left = 3000 TabIndex = 18 Top = 1560 Width = 135 End Begin VB.Label InPortBPnl BackColor = &H000000FF& Height = 135 Index = 4 Left = 3240 TabIndex = 17 Top = 1560 Width = 135 End Begin VB.Label InPortBPnl BackColor = &H000000FF& Height = 135 Index = 3 Left = 3480 TabIndex = 16 Top = 1560 Width = 135 End Begin VB.Label InPortBPnl BackColor = &H000000FF& Height = 135 Index = 2 Left = 3720 TabIndex = 15 Top = 1560 Width = 135 End Begin VB.Label InPortBPnl BackColor = &H000000FF& Height = 135 Index = 1 Left = 3960 TabIndex = 14 Top = 1560 Width = 135 End Begin VB.Label InPortBPnl BackColor = &H000000FF& Height = 135 Index = 0 Left = 4200 TabIndex = 13 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 7 Left = 360 TabIndex = 12 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 6 Left = 600 TabIndex = 11 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 5 Left = 840 TabIndex = 10 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 4 Left = 1080 TabIndex = 9 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 3 Left = 1320 TabIndex = 8 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 2 Left = 1560 TabIndex = 7 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 1 Left = 1800 TabIndex = 6 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 0 Left = 2040 TabIndex = 5 Top = 1560 Width = 135 End Begin VB.Label Label7 Caption = "Output Port A" Height = 255 Left = 5280 TabIndex = 44 Top = 1320 Width = 1575 End Begin VB.Label Label8 Caption = "Output Port B" Height = 255 Left = 7560 TabIndex = 45 Top = 1320 Width = 1695 End Begin VB.Label Label6 Caption = "Input Port B" Height = 255 Left = 2520 TabIndex = 43 Top = 1320 Width = 1695 End Begin VB.Label Label5 Caption = "Input Port A" Height = 255 Left = 480 TabIndex = 42 Top = 1320 Width = 1575 End End Attribute VB_Name = "Sample1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim DeviceIndex As Long Private Sub Form_Load() Dim dlg As New DetectForm Dim Status 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 Instructions.Caption = "Clicking on the ""Write Port A"" and ""Write Port B"" will write the values entered into the edit boxes to the relays." + vbCrLf Instructions.Caption = Instructions.Caption + "Clicking on the lights above the edit boxes will change the relays one at a time." + vbCrLf DeviceIndex = diOnly Status = QueryDeviceInfo(DeviceIndex, PID, NameSize, Name, DIOBytes, Counters) If Status <> 0 Then '0 Means it found an only device. Otherwise ask the user. dlg.Show vbModal DeviceIndex = dlg.DeviceIndex If DeviceIndex = -1 Then Unload Me Exit Sub End If End If OutData = &HFFFFFFFF DIO_WriteAll DeviceIndex, OutData Timer1.Interval = 100 End Sub Private Sub OutPortPnlA_Click(Index As Integer) If OutPortPnlA(Index).BackColor = vbGreen Then OutPortPnlA(Index).BackColor = vbRed DIO_Write1 DeviceIndex, Index, False Else OutPortPnlA(Index).BackColor = vbGreen DIO_Write1 DeviceIndex, Index, True End If End Sub Private Sub OutPortPnlB_Click(Index As Integer) If OutPortPnlB(Index).BackColor = vbGreen Then OutPortPnlB(Index).BackColor = vbRed DIO_Write1 DeviceIndex, Index + 8, False Else OutPortPnlB(Index).BackColor = vbGreen DIO_Write1 DeviceIndex, Index + 8, True End If End Sub Private Sub Timer1_Timer() Dim MasterInMask(0 To 3) As Byte Dim InMask As Byte Dim I As Integer DIO_ReadAll DeviceIndex, MasterInMask(0) InMask = MasterInMask(2) For I = 0 To 7 If InMask And 2 ^ I Then InPortAPnl(I).BackColor = vbGreen Else InPortAPnl(I).BackColor = vbRed End If Next I InMask = MasterInMask(3) For I = 0 To 7 If InMask And 2 ^ I Then InPortBPnl(I).BackColor = vbGreen Else InPortBPnl(I).BackColor = vbRed End If Next I End Sub Private Sub WriteAbtn_Click() Dim OutMask As Byte Dim I As Integer OutMask = "&H" + TextA.Text DIO_Write8 DeviceIndex, 0, OutMask For I = 0 To 7 If OutMask And 2 ^ I Then OutPortPnlA(I).BackColor = vbGreen Else OutPortPnlA(I).BackColor = vbRed End If Next I End Sub Private Sub WriteBbtn_Click() Dim OutMask As Byte Dim I As Integer OutMask = "&H" + TextB.Text DIO_Write8 DeviceIndex, 1, OutMask For I = 0 To 7 If OutMask And 2 ^ I Then OutPortPnlB(I).BackColor = vbGreen Else OutPortPnlB(I).BackColor = vbRed End If Next I End Sub