Author Topic: Why does Nobody Know Nothing About PC PCI Parallel Cards???  (Read 15641 times)

0 Members and 1 Guest are viewing this topic.

Online oPossum

  • Super Contributor
  • ***
  • Posts: 1417
  • Country: us
  • Very dangerous - may attack at any time
Re: Why does Nobody Know Nothing About PC PCI Parallel Cards???
« Reply #50 on: May 02, 2015, 05:20:31 pm »
Updated code with run time DLL load & link
Now checks for error return from WinIo driver
Builds as 32 or 64 bit (either will run on 64 bit)
Visual Studio 2013 Community Edition

Code: [Select]
Imports System.Runtime.InteropServices
Imports System.Threading

Module Module1

    <DllImport("kernel32.dll")> Public Function LoadLibrary(ByVal name As String) As IntPtr
    End Function

    <DllImport("kernel32.dll")> Public Function FreeLibrary(ByVal handle As IntPtr) As Boolean
    End Function

    <DllImport("kernel32.dll")> Public Function GetProcAddress(ByVal handle As IntPtr, ByVal name As String) As IntPtr
    End Function

    <UnmanagedFunctionPointer(CallingConvention.StdCall)>
    Delegate Function InitializeWinIoType() As Boolean

    <UnmanagedFunctionPointer(CallingConvention.StdCall)>
    Delegate Sub ShutdownWinIoType()

    <UnmanagedFunctionPointer(CallingConvention.StdCall)>
    Delegate Function GetPortValType(ByVal PortAddr As UInt16, ByRef pPortVal As UInt32, ByVal Size As Byte) As Boolean

    <UnmanagedFunctionPointer(CallingConvention.StdCall)>
    Delegate Function SetPortValType(ByVal PortAddr As UInt16, ByVal pPortVal As UInt32, ByVal Size As Byte) As Boolean

    Sub Main()

        Console.WriteLine("{0} bit", IntPtr.Size * 8)
        Dim winio As IntPtr
        If IntPtr.Size = 4 Then
            winio = LoadLibrary("WinIo32.dll")
        ElseIf IntPtr.Size = 8 Then
            winio = LoadLibrary("WinIo64.dll")
        Else
            Console.WriteLine("Unsupported system")
            Exit Sub
        End If

        Console.WriteLine("WinIo DLL Module Handle: {0:X}", winio)
        If winio = IntPtr.Zero Then
            Console.WriteLine("WinIo library could not be loaded")
            Exit Sub
        End If

        Dim fp As IntPtr
        fp = GetProcAddress(winio, "InitializeWinIo")
        If fp = IntPtr.Zero Then
            Console.WriteLine("Could not get address of InitializeWinIo")
            FreeLibrary(winio)
            Exit Sub
        End If
        Dim InitializeWinIo As InitializeWinIoType = DirectCast(Marshal.GetDelegateForFunctionPointer(fp, GetType(InitializeWinIoType)), InitializeWinIoType)

        fp = GetProcAddress(winio, "ShutdownWinIo")
        If fp = IntPtr.Zero Then
            Console.WriteLine("Could not get address of ShutdownWinIo")
            FreeLibrary(winio)
            Exit Sub
        End If
        Dim ShutdownWinIo As ShutdownWinIoType = DirectCast(Marshal.GetDelegateForFunctionPointer(fp, GetType(ShutdownWinIoType)), ShutdownWinIoType)

        fp = GetProcAddress(winio, "GetPortVal")
        If fp = IntPtr.Zero Then
            Console.WriteLine("Could not get address of GetPortVal")
            FreeLibrary(winio)
            Exit Sub
        End If
        Dim GetPortVal As GetPortValType = DirectCast(Marshal.GetDelegateForFunctionPointer(fp, GetType(GetPortValType)), GetPortValType)

        fp = GetProcAddress(winio, "SetPortVal")
        If fp = IntPtr.Zero Then
            Console.WriteLine("Could not get address of SetPortVal")
            FreeLibrary(winio)
            Exit Sub
        End If
        Dim SetPortVal As SetPortValType = DirectCast(Marshal.GetDelegateForFunctionPointer(fp, GetType(SetPortValType)), SetPortValType)

        If Not InitializeWinIo() Then
            Console.WriteLine("Error initializing WinIo driver")
            FreeLibrary(winio)
            Exit Sub
        End If

        Const port As UInt32 = &HD880

        Dim leds As Byte() = {&H1, &H2, &H4, &H8, &H10, &H20, &H40, &H80, &H40, &H20, &H10, &H8, &H4, &H2}

        Do

            For Each x In leds

                Console.WriteLine("{0:X4} = {1:X2}", port, x)

                If Not SetPortVal(port, x, 1) Then
                    Console.WriteLine("Error setting port value")
                    Exit Do
                End If

                Thread.Sleep(100)

            Next

        Loop While Not Console.KeyAvailable

        Console.ReadKey()

        ShutdownWinIo()

        FreeLibrary(winio)

    End Sub

End Module
« Last Edit: May 03, 2015, 12:29:21 am by oPossum »
 

Offline janoc

  • Super Contributor
  • ***
  • Posts: 3785
  • Country: de
Re: Why does Nobody Know Notthing About PC PCI Parallel Cards???
« Reply #51 on: May 02, 2015, 08:58:06 pm »
Thanks Janoc.. but that is the whole point. it is my machine, I bought it, I own it, I am a programmer and electronics nerd, if I want to ace the kernel twiddling with ports, then my machine is my kernel to ace!

Um, well, certainly nobody is preventing you from doing so. However, you have to use the APIs that are provided by the OS of your choice for the purpose. That's all what I have to say to this.

 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Why does Nobody Know Notthing About PC PCI Parallel Cards???
« Reply #52 on: May 02, 2015, 09:11:33 pm »
Thanks Janoc.. but that is the whole point. it is my machine, I bought it, I own it, I am a programmer and electronics nerd, if I want to ace the kernel twiddling with ports, then my machine is my kernel to ace!

Um, well, certainly nobody is preventing you from doing so. However, you have to use the APIs that are provided by the OS of your choice for the purpose. That's all what I have to say to this.
Then please run bare-metal code on your machine. Adding an operating system to your machine requires you follow the design rules of the particular operating system.
In case of Windows 8+, it requires you to write a 64 bit WHQL signed driver to access IO in a non-standard way. The driver sdk is free iirc.
 

Offline free_electron

  • Super Contributor
  • ***
  • Posts: 8517
  • Country: us
    • SiliconValleyGarage
Re: Why does Nobody Know Notthing About PC PCI Parallel Cards???
« Reply #53 on: May 02, 2015, 09:16:10 pm »
Thanks Janoc.. but that is the whole point. it is my machine, I bought it, I own it, I am a programmer and electronics nerd, if I want to ace the kernel twiddling with ports, then my machine is my kernel to ace!

Um, well, certainly nobody is preventing you from doing so. However, you have to use the APIs that are provided by the OS of your choice for the purpose. That's all what I have to say to this.

nobody is preventing you form doing it. just tell the operating system what you want to do and what hardware you want to access, and it will let you, but you have to do it using the mechanisms designed for that purpose. in this case : write a kernel mode driver.
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Offline SuzyCTopic starter

  • Frequent Contributor
  • **
  • Posts: 792
Re: Why does Nobody Know Nothing About PC PCI Parallel Cards???
« Reply #54 on: May 02, 2015, 11:06:27 pm »
Dear Software Gurus,

Thanks oPossum, congratulations!

I have compiled with VS2010 in C# target X86 and ran the Winio.zip sample program called DumpPort on my target PC with my  2-port PCI Parallel Port card with no luck.

The Winio .dll and .sys file were put in the same folder as the .exe file on my desktop. I also put the Winio32.dll in the Windows\System32 folder. The XP Device Manager shows that the card is working normally and has added LPT2 and LPT3 to my XP X86 SP3 platform.

The program runs without any errors, but I what I see is no change looking at the Parallel Ports, namely base address of &HDFE0, &HDFE1 or &HDFE2 of the Parallel Port connector when the logic levels are manually changed with the help of shorting wires at the connector pins. These are the ports shown in the Device Manager for the PCI card installed on my X86 32-bit XP platform: 0xDFE0-DFE7 and DF98-DF9F (first PCI parallel port shown as LPT2)
(second parallel PCI port on this card shown as LPT3 has also two different port ranges: 0xDF90-DF97 and DF80-DF8F)

Why do PCI Parallel Port cards like mine have two sets of port ranges for each of the ports?
Perhaps, I am using DumpPort to examine the wrong port addresses?

Could it be that only some PCI Parallel Port cards will work?

Has anyone else had any luck with other chipsets used on other PCI Parallel Port cards?

And thanks free_electron and Jeroen3, but special thanks for the original Winio coder and oPossum for actually getting something to work!

..Still Portless in Seattle
« Last Edit: May 02, 2015, 11:47:14 pm by SuzyC »
 

Online oPossum

  • Super Contributor
  • ***
  • Posts: 1417
  • Country: us
  • Very dangerous - may attack at any time
Re: Why does Nobody Know Nothing About PC PCI Parallel Cards???
« Reply #55 on: May 03, 2015, 12:57:24 am »
Are you able to write to the port and see the data outputs change?

Here is a VB.NET program that will display the status, control, and data registers continuously. Be sure to edit it for the base address of your parallel card.
The status inputs have pullup resistors, so shorting one of them to ground should show a change.
Some ports will do the same with the control lines.
Note that some signals are inverted so they show 0 when pulled high, and will change to 1 when grounded.

Should look like the attached screen capture when idle.

Code: [Select]
Option Strict On
Imports System.Runtime.InteropServices
Imports System.Threading

Module Module1
    <DllImport("kernel32.dll")> Public Function LoadLibrary(ByVal name As String) As IntPtr
    End Function

    <DllImport("kernel32.dll")> Public Function FreeLibrary(ByVal handle As IntPtr) As Boolean
    End Function

    <DllImport("kernel32.dll")> Public Function GetProcAddress(ByVal handle As IntPtr, ByVal name As String) As IntPtr
    End Function

    <UnmanagedFunctionPointer(CallingConvention.StdCall)>
    Delegate Function InitializeWinIoType() As Boolean

    <UnmanagedFunctionPointer(CallingConvention.StdCall)>
    Delegate Sub ShutdownWinIoType()

    <UnmanagedFunctionPointer(CallingConvention.StdCall)>
    Delegate Function GetPortValType(ByVal PortAddr As UInt16, ByRef pPortVal As UInt32, ByVal Size As Byte) As Boolean

    <UnmanagedFunctionPointer(CallingConvention.StdCall)>
    Delegate Function SetPortValType(ByVal PortAddr As UInt16, ByVal pPortVal As UInt32, ByVal Size As Byte) As Boolean

    Sub Main()

        Console.WriteLine("{0} bit", IntPtr.Size * 8)
        Dim winio As IntPtr
        If IntPtr.Size = 4 Then
            winio = LoadLibrary("WinIo32.dll")
        ElseIf IntPtr.Size = 8 Then
            winio = LoadLibrary("WinIo64.dll")
        Else
            Console.WriteLine("Unsupported system")
            Exit Sub
        End If

        Console.WriteLine("WinIo DLL Module Handle: {0:X}", winio)
        If winio = IntPtr.Zero Then
            Console.WriteLine("WinIo library could not be loaded")
            Exit Sub
        End If

        Dim fp As IntPtr
        fp = GetProcAddress(winio, "InitializeWinIo")
        If fp = IntPtr.Zero Then
            Console.WriteLine("Could not get address of InitializeWinIo")
            FreeLibrary(winio)
            Exit Sub
        End If
        Dim InitializeWinIo As InitializeWinIoType = DirectCast(Marshal.GetDelegateForFunctionPointer(fp, GetType(InitializeWinIoType)), InitializeWinIoType)

        fp = GetProcAddress(winio, "ShutdownWinIo")
        If fp = IntPtr.Zero Then
            Console.WriteLine("Could not get address of ShutdownWinIo")
            FreeLibrary(winio)
            Exit Sub
        End If
        Dim ShutdownWinIo As ShutdownWinIoType = DirectCast(Marshal.GetDelegateForFunctionPointer(fp, GetType(ShutdownWinIoType)), ShutdownWinIoType)

        fp = GetProcAddress(winio, "GetPortVal")
        If fp = IntPtr.Zero Then
            Console.WriteLine("Could not get address of GetPortVal")
            FreeLibrary(winio)
            Exit Sub
        End If
        Dim GetPortVal As GetPortValType = DirectCast(Marshal.GetDelegateForFunctionPointer(fp, GetType(GetPortValType)), GetPortValType)

        fp = GetProcAddress(winio, "SetPortVal")
        If fp = IntPtr.Zero Then
            Console.WriteLine("Could not get address of SetPortVal")
            FreeLibrary(winio)
            Exit Sub
        End If
        Dim SetPortVal As SetPortValType = DirectCast(Marshal.GetDelegateForFunctionPointer(fp, GetType(SetPortValType)), SetPortValType)

        If Not InitializeWinIo() Then
            Console.WriteLine("Error initializing WinIo driver")
            FreeLibrary(winio)
            Exit Sub
        End If

        Const port_base As UInt32 = &HD880
        Const data_port As UInt32 = port_base + 0
        Const status_port As UInt32 = port_base + 1
        Const control_port As UInt32 = port_base + 2

        SetPortVal(control_port, &H4, 1)

        Console.Clear()
        Console.SetCursorPosition(0, 0)
        Console.WriteLine("S7 S6 S5 S4 S3  C3 C2 C1 C0  D7 D6 D5 D4 D3 D2 D1 D0   Register Bits")
        Console.WriteLine("11 10 12 13 15  17 16 14  1   9  8  7  6  5  4  3  2   DB25 Pins")

        Do

            Dim status As UInt32
            Dim control As UInt32
            Dim data As UInt32

            GetPortVal(status_port, status, 1)
            GetPortVal(control_port, control, 1)
            GetPortVal(data_port, data, 1)

            Console.SetCursorPosition(0, 2)

            Console.WriteLine(" {0}  {1}  {2}  {3}  {4}   {5}  {6}  {7}  {8}   {9}  {10}  {11}  {12}  {13}  {14}  {15}  {16}", _
                              (status >> 7) And 1, _
                              (status >> 6) And 1, _
                              (status >> 5) And 1, _
                              (status >> 4) And 1, _
                              (status >> 3) And 1, _
                              (control >> 3) And 1, _
                              (control >> 2) And 1, _
                              (control >> 1) And 1, _
                              control And 1, _
                              (data >> 7) And 1, _
                              (data >> 6) And 1, _
                              (data >> 5) And 1, _
                              (data >> 4) And 1, _
                              (data >> 3) And 1, _
                              (data >> 2) And 1, _
                              (data >> 1) And 1, _
                              data And 1)

            Thread.Sleep(20)

        Loop While Not Console.KeyAvailable

        Console.ReadKey()

        ShutdownWinIo()

        FreeLibrary(winio)

    End Sub

End Module
 

Offline SuzyCTopic starter

  • Frequent Contributor
  • **
  • Posts: 792
Re: Why does Nobody Know Nothing About PC PCI Parallel Cards???
« Reply #56 on: May 03, 2015, 01:53:07 am »
GigaThanx, oPossum, it works!

I discovered two problems with my PCI card:

Firstly, the old parallel cable had all the parallel pinout spec'd ground pins connected together at the Centronics connector end end, but they did not connect to a I/O ground point of the PCI card, only the shield wire of the DB25 wired cable was connected to ground. Connecting these two grounds together allowed me to view and change logic levels on the ports.

Secondly, I presumed that the PC's back panel DB25F of this 2-ported PCI Parallel Port Adapter was LPT2..it was in fact, LPT3 and when I changed logic levels at the connector and then input from the corrected ports, (base address 0xDF90)..everything works!
It turns out the interior bed-of-nails male connector located on the PCI PCB is used for LPT2.

Thirdly, using inpout32.dll, I attempted to debug the program and access port addresses that were used by the target PCI card which was not installed on the desktop with the VB6 or VS@010 compilers, and so I got a VB6 IDE crash, but the compiled .exe program worked fine on the target PC.

I also got my VB6 version of this access idea working using Inpout32.dll, X86 only and it also lacks the excellent error X86/X64 checking and .dll operation diagnostics and Win7 compatibility..oPossum, you did some excellent work!
« Last Edit: May 03, 2015, 02:49:20 am by SuzyC »
 

Offline SuzyCTopic starter

  • Frequent Contributor
  • **
  • Posts: 792
Re: Why does Nobody Know Nothing About PC PCI Parallel Cards???
« Reply #57 on: May 03, 2015, 02:36:18 am »
Thanks Mechatrommer, your explanation was most helpful to understand the importance of programs having a few manners when playing with Windows private ports.

Thanks again to all that posted, and to Suicidaleggroll and Jeroen3 and Janoc.

"Thanks free-electron..you say correctly, I assume, that, "SO : PCI is not mapped in Io space but in main memory space."

but WiNDOWS assigns the PCI Parallel Ports, so they seem to be ports, functionally identical to legacy ports, but these 0xDFxx ports do exist! (if only emulated?)
« Last Edit: May 03, 2015, 02:50:51 am by SuzyC »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf