c++clinuxadapterparallel-port

C,C++ write on parallel port via USB adapter (LINUX)


as I said in the title I'm having some trouble using the parallel port on Lubuntu.. (I'm using a USB to PARALLEL adapter) I wrote some code that works fine on my other linux PC (which has the parport):

#include <stdio.h>
#include <unistd.h> //sleep()
#include <sys/io.h> //outb() ioperm()

#define LPT1 0x0378
#define HIGH 255
#define LOW 0

int main() 
{
    if (ioperm(LPT1,1,1) == -1) //set LPT permissions
    {
        printf("PORTE CHIUSE, ESCO!\n");
        return -1;
    }
    printf("PORTE APERTE SU %d\n", LPT1);
    while (1)
    {
        outb(HIGH, LPT1); //LED blinking on D0-D7
        sleep(5);
        outb(LOW, LPT1);
        sleep(5);
    }
    return 0;
}

Unfortunately this code doesn't work on the PC with the adapter.. I think that it is due to the different addresses of the virtual parport vs the physical one, but anyway I don't know how to address the virtual port.. So, what I should change in the code to make it work with the adapter? What address (if there is one) should I put into the costant "LPT1"?

Thanks in advance to everyone! ;) Good evening, Matteo.


Solution

  • Since you don't have an actual parallel port on your computer there isn't anything at the I/O address 0x0378. Since you're using the a USB to parallel adapter, the parallel port is the adapter, not your PC. To the Linux kernel your USB adapter looks like a standard USB printer device. To access you'll need to go through kernel's USB printer device driver. Unfortunately I don't know if it provides the low level access you're looking for. You can use it to print things by sending it a stream of data, but I don't think you can manipulate the state of individual pins.

    After looking at the USB Printer Class Specification it looks like it doesn't provide any way to manipulate the data pins the way you want.