Parallel Port Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fr33dan
    New Member
    • Oct 2008
    • 57

    #1

    Parallel Port Problem

    Hi everybody, long time no see. I'm writing a program to use the parallel port to write to an I2C chip using a custom fixture that utilizes pins 3 and 5.

    I've used inpout32.dll to access the port as described here but it doesn't seem to work properly.
    Code:
    Here is a table of what it does:
       D C
    0  1 0
    2  1 1
    8  0 0
    10 0 1
    
    This is what it should do:
       D C
    0  0 0
    2  0 1
    8  1 0
    10 1 1
    Here is the method that creates that table. The messagebox is just a debugging tool because my dev machine doesn't have a parallel port and my VS version doesn't support remote debugging.
    Code:
    private void update()
    {
        int writeVal = (dataVal ? this.DataOutputMask : 0);
        writeVal = writeVal | (clockVal ? this.ClockMask : 0);
        System.Windows.Forms.MessageBox.Show(writeVal + " being written to " + dataAddress);
        PortInterop.Output(dataAddress, writeVal);
    }
    I would imagine this has something to do with how C# interfaces with the DLL but I don't know anything about that so it's a wild guess because I'm out of ideas.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    It looks like you're writing 8-bits out... I don't know what the row labels on your output mean, but perhaps it's not coincidence that row 1 is swapped with row 3 and row 2 is swapped with row 4...?

    The code you pasted doesn't really help diagnose the problem. What controls the value of dataVal (is this a boolean?) and what is the value of DataOutputMask? Dito for ClockMask.

    I'd recommend stepping into this method and seeing what the values of each are, then tracing through with pen and paper to see what the bits are just before PortInterop.Out put(...).

    Comment

    • Fr33dan
      New Member
      • Oct 2008
      • 57

      #3
      This is why I come to these forums. No one else would have commented that. I look into it and as it turns out the fixture inverts the logic on the Data line and no one bothered to tell me. Just FYI the rows were the writeVal that was posted by the MessageBox before I took the readings. Infinite thanks.

      Comment

      • GaryTexmo
        Recognized Expert Top Contributor
        • Jul 2009
        • 1501

        #4
        Haha, glad you got it figured out :)

        Comment

        Working...