VERSION 5.00 Begin VB.Form Sample1 Caption = "II8IDO4A Sample" ClientHeight = 3855 ClientLeft = 4485 ClientTop = 4815 ClientWidth = 4095 LinkTopic = "Form1" ScaleHeight = 3855 ScaleWidth = 4095 Begin VB.Timer PollTime Enabled = 0 'False Interval = 100 Left = 840 Top = 1920 End Begin VB.TextBox TextA Height = 285 Left = 3000 TabIndex = 16 Text = "00" Top = 1800 Width = 855 End Begin VB.CommandButton WriteAbtn Caption = "Write" Height = 255 Left = 3000 TabIndex = 3 Top = 2160 Width = 855 End Begin VB.Frame Frame1 Caption = "Key" Height = 1095 Left = 120 TabIndex = 0 Top = 120 Width = 3855 Begin VB.Label Label4 Alignment = 1 'Right Justify Caption = "Relay is Energized/Input is low: " Height = 255 Left = 120 TabIndex = 18 Top = 720 Width = 3255 End Begin VB.Label Label3 Alignment = 1 'Right Justify Caption = "Relay is De-Energized/Input is high:" Height = 255 Left = 120 TabIndex = 17 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 Label7 Caption = "Output" Height = 255 Left = 3000 TabIndex = 21 Top = 1320 Width = 855 End Begin VB.Label Label5 Caption = "Input Port A" Height = 255 Left = 360 TabIndex = 20 Top = 1320 Width = 1575 End Begin VB.Label Instructions Caption = "Instructions" Height = 1215 Left = 120 TabIndex = 19 Top = 2520 Width = 3855 End Begin VB.Label OutPortPnlA BackColor = &H000000FF& Height = 135 Index = 3 Left = 3000 MouseIcon = "Form1.frx":0000 MousePointer = 10 'Up Arrow TabIndex = 15 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlA BackColor = &H000000FF& Height = 135 Index = 2 Left = 3240 MouseIcon = "Form1.frx":0152 MousePointer = 10 'Up Arrow TabIndex = 14 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlA BackColor = &H000000FF& Height = 135 Index = 1 Left = 3480 MouseIcon = "Form1.frx":02A4 MousePointer = 10 'Up Arrow TabIndex = 13 Top = 1560 Width = 135 End Begin VB.Label OutPortPnlA BackColor = &H000000FF& Height = 135 Index = 0 Left = 3720 MouseIcon = "Form1.frx":03F6 MousePointer = 10 'Up Arrow TabIndex = 12 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 7 Left = 240 TabIndex = 11 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 6 Left = 480 TabIndex = 10 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 5 Left = 720 TabIndex = 9 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 4 Left = 960 TabIndex = 8 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 3 Left = 1200 TabIndex = 7 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 2 Left = 1440 TabIndex = 6 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 1 Left = 1680 TabIndex = 5 Top = 1560 Width = 135 End Begin VB.Label InPortAPnl BackColor = &H000000FF& Height = 135 Index = 0 Left = 1920 TabIndex = 4 Top = 1560 Width = 135 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 a device. Otherwise make the user choose dlg.Show vbModal DeviceIndex = dlg.DeviceIndex If DeviceIndex = -1 Then Unload Me Exit Sub End If End If OutData = 0 DIO_WriteAll DeviceIndex, OutData PollTime.Enabled = True 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 PollTime_Timer() Dim inMask As Byte Dim I As Integer DIO_Read8 DeviceIndex, 1, inMask For I = 0 To 7 If (ShiftRight(inMask, I) And &H1) Then InPortAPnl(I).BackColor = vbGreen Else InPortAPnl(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 3 If (ShiftRight(OutMask, I) And &H1) Then OutPortPnlA(I).BackColor = vbGreen Else OutPortPnlA(I).BackColor = vbRed End If Next I End Sub