VERSION 5.00 Begin VB.Form Form1 BorderStyle = 3 'Fixed Dialog Caption = "Windows 8255 Sample" ClientHeight = 4524 ClientLeft = 48 ClientTop = 336 ClientWidth = 6144 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 4524 ScaleWidth = 6144 ShowInTaskbar = 0 'False StartUpPosition = 2 'CenterScreen Begin VB.Timer Timer1 Enabled = 0 'False Interval = 1000 Left = 2640 Top = 4080 End Begin VB.Frame Frame1 Caption = "Status" Height = 1695 Left = 120 TabIndex = 12 Top = 2280 Width = 5895 Begin VB.TextBox Memo1 Height = 1335 Left = 120 Locked = -1 'True MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 13 Top = 240 Width = 5655 End End Begin VB.CommandButton ExitButton Caption = "E&xit" Height = 375 Left = 4320 TabIndex = 11 Top = 4080 Width = 1575 End Begin VB.CommandButton PerformButton Caption = "Perform I/O" Height = 375 Left = 240 TabIndex = 4 Top = 4080 Width = 1455 End Begin VB.ComboBox AddressList Height = 315 ItemData = "Form1.frx":0000 Left = 1800 List = "Form1.frx":0002 Style = 2 'Dropdown List TabIndex = 3 Top = 840 Width = 3375 End Begin VB.Label PortBIn Alignment = 2 'Center BorderStyle = 1 'Fixed Single Caption = "00000000" Height = 255 Left = 3960 TabIndex = 10 Top = 1920 Width = 1215 End Begin VB.Label PortAIn Alignment = 2 'Center BorderStyle = 1 'Fixed Single Caption = "00000000" Height = 255 Left = 2400 TabIndex = 9 Top = 1920 Width = 1215 End Begin VB.Label PortAOut Alignment = 2 'Center BorderStyle = 1 'Fixed Single Caption = "00000000" Height = 255 Left = 840 TabIndex = 8 Top = 1920 Width = 1215 End Begin VB.Label Label5 AutoSize = -1 'True Caption = "Port B Input" Height = 195 Left = 4080 TabIndex = 7 Top = 1680 Width = 840 End Begin VB.Label Label4 AutoSize = -1 'True Caption = "Port A Input" Height = 195 Left = 2520 TabIndex = 6 Top = 1680 Width = 840 End Begin VB.Label Label3 AutoSize = -1 'True Caption = "Port A Output" Height = 195 Left = 960 TabIndex = 5 Top = 1680 Width = 960 End Begin VB.Label Label2 AutoSize = -1 'True Caption = "Select a port to use:" Height = 195 Left = 240 TabIndex = 2 Top = 960 Width = 1425 End Begin VB.Label CardName AutoSize = -1 'True Caption = "Card Name" BeginProperty Font Name = "MS Sans Serif" Size = 10.8 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 300 Left = 120 TabIndex = 1 Top = 480 Width = 1200 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "Windows 8255 Sample" BeginProperty Font Name = "MS Sans Serif" Size = 13.2 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 360 Left = 1440 TabIndex = 0 Top = 120 Width = 3180 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Rem This sample now uses the AIOWDM.bas VB module included in this project Rem Calls to OutPortB() InPortB() have been changed to RelOutPortB() RelInPortB() Rem They now use CardNum = 0, and address "Offset" instead of just "Address" Rem This app will write output to A and also read its value as input, It also reads Input on B Rem It only supports a single card installed in the system Public Status As Integer Public NumCards As Long Public Cardnum As Integer Dim Ports(5) As Long Public RunFlag As Boolean Public Offset As Long Public MyIndex As Integer Dim MyValues(2) As Integer Public Msg As String Private Sub AddressList_Click() Dim NewAddress As Long NewAddress = Ports(AddressList.ListIndex) If NewAddress <> Offset Then Offset = NewAddress: Memo1.Text = Memo1.Text + "New Port Selected: " + AddressList.Text + Chr(13) + Chr(10): Memo1.SelStart = 32768: End If End Sub Private Sub ExitButton_Click() End End Sub Private Sub Form_Load() Memo1.Text = "This sample outputs a walking bit on Port A of the selected group. It then reads back the value from Port A. This should be identical to the output value due to on-chip readback. It also displays the Input from Port B. If a wrap plug is installed, Port B should read the same value. Otherwise, ground individual bits on Port B to see them show zeroes on the display." + Chr(13) + Chr(10) Memo1.SelStart = 32768 Dim found As Boolean Dim DeviceID As Long Dim Base As Long Dim NameSize As Long Dim Name As String Dim i As Integer NumCards = 0 Cardnum = 0 DeviceID = 0 NameSize = 256 found = False RunFlag = True 'This is still an absolute port address value writen to the driver to test for card and error return 0xAA55 If (InPortB(&H61) = &HAA55) Then Call MsgBox("AIOWDM.SYS not detected. Please copy AIOWDM.SYS into C:\WINDOWS\system32\drivers directory or for Win7 C:\Windows\SysWOW64\drivers and re-run this sample.", 0, "Warning") End If 'Make sure theres at least one card in the system NumCards = GetNumCards() If (NumCards = 0) Then GoTo NoCards 'Samples are for only one card get the device ID Status = QueryCardInfo(i, DeviceID, Base, NameSize, Name) 'Validate then save the card name and address offsets here: Select Case DeviceID Case &HECA9& CardName.Caption = "PCI-A12-16 Analog I/O Card with Digital" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = &H10 ' These boards have an 0x10 offset to the DIO chip found = True Case &HECAA& CardName.Caption = "PCI-A12-16 Analog I/O Card with Digital" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = &H10 ' These boards have an 0x10 offset to the DIO chip found = True Case &H2C58& CardName.Caption = "PCI-DIO-96C3 Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") AddressList.AddItem ("Group 1 Base Offset 4") AddressList.AddItem ("Group 2 Base Offset 8") AddressList.AddItem ("Group 3 Base Offset 12") Ports(0) = 0 Ports(1) = 4 Ports(2) = 8 Ports(3) = 12 found = True Case &H2C50& CardName.Caption = "PCI-DIO-96CT Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") AddressList.AddItem ("Group 1 Base Offset 4") AddressList.AddItem ("Group 2 Base Offset 8") AddressList.AddItem ("Group 3 Base Offset 12") Ports(0) = 0 Ports(1) = 4 Ports(2) = 8 Ports(3) = 12 found = True Case &H2C70& CardName.Caption = "PCI-DIO-96CT Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") AddressList.AddItem ("Group 1 Base Offset 4") AddressList.AddItem ("Group 2 Base Offset 8") AddressList.AddItem ("Group 3 Base Offset 12") Ports(0) = 0 Ports(1) = 4 Ports(2) = 8 Ports(3) = 12 found = True Case &HC50& CardName.Caption = "PCI-DIO-24H Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = 0 found = True Case &HC51& CardName.Caption = "PCI-DIO-24D Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = 0 found = True Case &HE51& CardName.Caption = "PCI-DIO-24H(C) Parallel Digital I/O Card w/Counter" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = 0 found = True Case &HE52& CardName.Caption = "PCI-DIO-24D(C) Parallel Digital I/O Card w/Counter" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = 0 found = True Case &HE50& CardName.Caption = "PCI-DIO-24S Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = 0 found = True Case &HC60& CardName.Caption = "PCI-DIO-48 Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") AddressList.AddItem ("Group 1 Base Offset 4") Ports(0) = 0 Ports(1) = 4 found = True Case &HE60& CardName.Caption = "PCI-DIO-48S Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") AddressList.AddItem ("Group 1 Base Offset 4") Ports(0) = 0 Ports(1) = 4 found = True Case &HC52& CardName.Caption = "PCIe-DIO-24 Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = 0 found = True Case &HE53& CardName.Caption = "PCIe-DIO-24S Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = 0 found = True Case &HC53& CardName.Caption = "PCIe-DIO-24D Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = 0 found = True Case &HE55& CardName.Caption = "PCIe-DIO-24DC Parallel Digital I/O Card w/Counter" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = 0 found = True Case &HE54& CardName.Caption = "PCIe-DIO-24DS Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = 0 found = True Case &HE56& CardName.Caption = "PCIe-DIO-24DCS Parallel Digital I/O Card w/Counter" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = 0 found = True Case &HC61& CardName.Caption = "PCIe-DIO-48 Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") AddressList.AddItem ("Group 1 Base Offset 4") Ports(0) = 0 Ports(1) = 4 found = True Case &HE61& CardName.Caption = "PCIe-DIO-48S Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") AddressList.AddItem ("Group 1 Base Offset 4") Ports(0) = 0 Ports(1) = 4 found = True Case &HC68& CardName.Caption = "PCI-DIO-72 Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") AddressList.AddItem ("Group 1 Base Offset 4") AddressList.AddItem ("Group 2 Base Offset 8") Ports(0) = 0 Ports(1) = 4 Ports(2) = 8 found = True Case &HC70& CardName.Caption = "PCI-DIO-96 Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") AddressList.AddItem ("Group 1 Base Offset 4") AddressList.AddItem ("Group 2 Base Offset 8") AddressList.AddItem ("Group 3 Base Offset 12") Ports(0) = 0 Ports(1) = 4 Ports(2) = 8 Ports(3) = 12 found = True Case &HC69& CardName.Caption = "P104-DIO-96 Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") AddressList.AddItem ("Group 1 Base Offset 4") AddressList.AddItem ("Group 2 Base Offset 8") AddressList.AddItem ("Group 3 Base Offset 12") Ports(0) = 0 Ports(1) = 4 Ports(2) = 8 Ports(3) = 12 found = True Case &HC78& CardName.Caption = "PCI-DIO-120 Parallel Digital I/O Card" AddressList.AddItem ("Group 0 Base Offset 0") AddressList.AddItem ("Group 1 Base Offset 4") AddressList.AddItem ("Group 2 Base Offset 8") AddressList.AddItem ("Group 3 Base Offset 12") AddressList.AddItem ("Group 4 Base Offset 16") Ports(0) = 0 Ports(1) = 4 Ports(2) = 8 Ports(3) = 12 Ports(4) = 16 found = True Case &H2EE0& CardName.Caption = "PCIe-DIO24S-CTR12 Digital/Counter Card" AddressList.AddItem ("Group 0 Base Offset 0") Ports(0) = 0 found = True End Select NoCards: If Not found Then CardName.Caption = "No Card Found": Memo1.Text = "No Card Found!" + Chr(13) + Chr(10) + "This may mean that the card is not installed, or the card is not 8255 equipped" + Chr(13) + Chr(10) Memo1.SelStart = 32768: AddressList.Enabled = False RunFlag = False End If If RunFlag Then AddressList.ListIndex = 0 Offset = Ports(AddressList.ListIndex) ' use indexed value to set offset End If End Sub Private Sub PerformButton_Click() If Timer1.Enabled Then Timer1.Enabled = False: PerformButton.Caption = "Perform I/O" Else Timer1.Enabled = True: RelOutPortB Cardnum, Offset + 3, &H82 ' write control register, 100000010, set B Input, A Output and mode etc PerformButton.Caption = "Stop I/O" End If End Sub Private Sub Timer1_Timer() Dim i, j As Integer MyValues(0) = 2 ^ MyIndex RelOutPortB Cardnum, Offset + 0, MyValues(0) 'relative offset ' Changed to use relative functions RelInPortB(Cardnum, Port) ' using local Offset parameter which is now set to the appropriate offset from Base address ie 0 for Group 0 or 4 for Group 1 etc ' adding offset in this case using 0 for Group 0 port A and 1 for Group 0 port B: ' so this will read A and B inputs values even though A is set for output we can read/veify its value MyValues(1) = RelInPortB(Cardnum, Offset + 0) MyValues(2) = RelInPortB(Cardnum, Offset + 1) MyIndex = MyIndex + 1 MyIndex = MyIndex Mod 8 Msg = "" For j = 7 To 0 Step -1 If (MyValues(0) And (2 ^ j)) > 0 Then Msg = Msg & "1" Else Msg = Msg & "0" End If Next PortAOut.Caption = Msg Msg = "" For j = 7 To 0 Step -1 If (MyValues(1) And (2 ^ j)) > 0 Then Msg = Msg & "1" Else Msg = Msg & "0" End If Next PortAIn.Caption = Msg Msg = "" For j = 7 To 0 Step -1 If (MyValues(2) And (2 ^ j)) > 0 Then Msg = Msg & "1" Else Msg = Msg & "0" End If Next PortBIn.Caption = Msg End Sub