how to access parall port in my module? - Hardware

This is a discussion on how to access parall port in my module? - Hardware ; Hi, all. My embedded board have paralled port with 25 pin. ( IO port 0x387, and SPP mode ) I'd like to access and use it from linux... I think I need linux parallel port device driver to access .... ...

+ Reply to Thread
Results 1 to 10 of 10

Thread: how to access parall port in my module?

  1. how to access parall port in my module?

    Hi, all.

    My embedded board have paralled port with 25 pin. ( IO port 0x387, and SPP
    mode )
    I'd like to access and use it from linux...

    I think I need linux parallel port device driver to access ....
    I'm new to parallel port .... so If I get some simple code about how to
    send a char or string...
    It will give great help to me....where can I see it to learn parallel port?


    (how parallel port initialize and send a char , and closing.... )


    Thanks.. have a nice day.



  2. Re: how to access parall port in my module?

    google-rambo88 staggered into the Black Sun and said:
    > My embedded board [has a] [parallel] port with 25 [pins]. ( IO port
    > 0x387, SPP mode.) I'd like to access and use it from linux. I think I
    > need [the] linux parallel port device driver to access [it]


    modprobe parport_pc (assuming this thing is an x86, if not, you
    should've said something)
    modprobe lp

    > I'm new to [using the] parallel port


    http://www.beyondlogic.org/spp/parallel.htm , OS-agnostic. Also
    http://freshmeat.net/projects/parapin/ , Linux-specific.

    > ... so If I get some simple code about how to send a char or
    > string... It will give great help to me....where can I see it to
    > learn parallel port? (how parallel port initialize and send a char ,
    > and closing.... )


    All whose base are belong to what?

    --
    ....In Hong Kong action movies, they don't have Hollywood Guns with
    infinite bullet supplies. Instead, they have Hong Kong Pants(tm) which
    hold an infinite supply of loaded pistols. --M. Sphar, the Monastery
    Matt G|There is no Darkness in Eternity/But only Light too dim for us to see

  3. Re: how to access parall port in my module?

    On Jul 17, 4:10 am, "google-rambo88" wrote:
    > Hi, all.

    [snip]
    > (how parallel port initialize and send a char , and closing.... )


    #include
    #include
    #include
    #include
    #include
    #include

    int main(void)
    {
    int ParallelPort;
    char buffer[1] = "A";

    if ((ParallelPort = open("/dev/lp0",O_RDONLY|O_DIRECT|O_SYNC)) >= 0)
    {
    int nbytes, total_written = 0;

    while (bytes_written < sizeof(buffer)
    {
    nbytes = write(ParallelPort, buffer + total_written,
    sizeof(buffer) - total_written);
    total_written += nbytes;
    }

    close(ParallelPort);
    }
    else return EXIT_ERROR;
    return EXIT_SUCCESS;
    }


  4. Re: how to access parall port in my module?

    Very strange... even though I include all header files... related open()
    function...
    ( #include ,#include ,#include )
    I met " `O_DIRECT' undeclared (first use in this function) "


    so I remove it for compiling.. And write() function returned ...
    ays -1

    when I run this short example, I can see following messages by runing
    "dmesg" command.

    parport0: PC-style at 0x378 [PCSPP,EPP]
    parport0: faking semi-colon
    parport0: Printer, Hewlett-Packard HP LaserJet 1100
    lp0: using parport0 (polling).
    lp0: console ready

    Why I can't write character to /dev/lp0?


    I 'd like to know How they are diffrect between /dev/lp0 and /dev.par0 and
    /dev/parport0 ?


    ================================================== ======
    #include
    #include
    #include
    #include
    #include
    #include

    int main(void)
    {
    int fd;
    int nbytes, total_written = 0;
    char buffer[3] = {0x65, 0x0D , 0x0a };

    fd = open("/dev/lp0",O_RDONLY| O_SYNC ) ;
    if ( fd > 0 )
    {

    nbytes = write(fd, buffer , 3 );
    printf ( "nbytes = ... %d\n", nbytes );
    }
    else

    close(fd);
    return 0;
    }



    Have a day....



    "Lew Pitcher" wrote in message
    news:1184677084.837472.127520@j4g2000prf.googlegro ups.com...
    > On Jul 17, 4:10 am, "google-rambo88" wrote:
    > > Hi, all.

    > [snip]
    > > (how parallel port initialize and send a char , and closing.... )

    >
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    >
    > int main(void)
    > {
    > int ParallelPort;
    > char buffer[1] = "A";
    >
    > if ((ParallelPort = open("/dev/lp0",O_RDONLY|O_DIRECT|O_SYNC)) >= 0)
    > {
    > int nbytes, total_written = 0;
    >
    > while (bytes_written < sizeof(buffer)
    > {
    > nbytes = write(ParallelPort, buffer + total_written,
    > sizeof(buffer) - total_written);
    > total_written += nbytes;
    > }
    >
    > close(ParallelPort);
    > }
    > else return EXIT_ERROR;
    > return EXIT_SUCCESS;
    > }
    >




  5. Re: how to access parall port in my module?

    google-rambo88 wrote:
    > Very strange... even though I include all header files... related open()
    > function...
    > ( #include ,#include ,#include )
    > I met " `O_DIRECT' undeclared (first use in this function) "

    [snip]
    >
    >


    Oops... I guess I should have compiled that once before posting. That's what I
    get for composing off the top of my head.

    Try this....

    #include
    #include
    #include
    #include
    #include
    #include

    int main(void)
    {
    int ParallelPort;
    char buffer[1] = "A";

    if ((ParallelPort = open("/dev/parport0",O_RDONLY|O_DIRECT|O_SYNC)) >= 0)
    {
    int nbytes, total_written = 0;

    while (total_written < sizeof(buffer))
    {
    nbytes = write(ParallelPort,
    buffer + total_written,
    sizeof(buffer) - total_written);
    total_written += nbytes;
    }

    close(ParallelPort);
    }
    else return EXIT_FAILURE;
    return EXIT_SUCCESS;
    }



    --
    Lew Pitcher

    Master Codewright & JOAT-in-training | Registered Linux User #112576
    http://pitcher.digitalfreehold.ca/ | GPG public key available by request
    ---------- Slackware - Because I know what I'm doing. ------


  6. Re: how to access parall port in my module?

    Lew Pitcher wrote:
    > google-rambo88 wrote:
    >> Very strange... even though I include all header files... related open()
    >> function...
    >> ( #include ,#include ,#include )
    >> I met " `O_DIRECT' undeclared (first use in this function) "

    > [snip]
    >>

    >
    > Oops... I guess I should have compiled that once before posting. That's what I
    > get for composing off the top of my head.
    >
    > Try this....
    >
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    >
    > int main(void)
    > {
    > int ParallelPort;
    > char buffer[1] = "A";
    >
    > if ((ParallelPort = open("/dev/parport0",O_RDONLY|O_DIRECT|O_SYNC)) >= 0)


    Gaak!! I thought I had corrected that error.... Change the above to
    if ((ParallelPort = open("/dev/parport0",O_RDONLY|O_SYNC)) >= 0)
    The open(2) manpage says that O_DIRECT exists, but the headers disagree :-S

    > {
    > int nbytes, total_written = 0;
    >
    > while (total_written < sizeof(buffer))
    > {
    > nbytes = write(ParallelPort,
    > buffer + total_written,
    > sizeof(buffer) - total_written);
    > total_written += nbytes;
    > }
    >
    > close(ParallelPort);
    > }
    > else return EXIT_FAILURE;
    > return EXIT_SUCCESS;
    > }
    >
    >
    >



    --
    Lew Pitcher

    Master Codewright & JOAT-in-training | Registered Linux User #112576
    http://pitcher.digitalfreehold.ca/ | GPG public key available by request
    ---------- Slackware - Because I know what I'm doing. ------


  7. Re: how to access parall port in my module?

    Lew Pitcher staggered into the Black Sun and said:
    > Lew Pitcher wrote:
    >>if ((ParallelPort = open("/dev/parport0",O_RDONLY|O_DIRECT|O_SYNC)) >= 0)

    [snip]
    >> nbytes = write(ParallelPort,
    >> buffer + total_written,
    >> sizeof(buffer) - total_written);

    > Gaak!! I thought I had corrected that error.... Change the above to
    > if ((ParallelPort = open("/dev/parport0",O_RDONLY|O_SYNC)) >= 0)


    write() to an fd that's been open()ed with O_RDONLY will return ...
    what, precisely? I'm guessing it'll be < 0, and errno would be EBADF.

    --
    Once I saw this wino who was eating grapes, and I said, "Dude, you
    have to wait." --Mitch Hedberg
    Matt G|There is no Darkness in Eternity/But only Light too dim for us to see

  8. Re: how to access parall port in my module?

    Dances With Crows wrote:
    > Lew Pitcher staggered into the Black Sun and said:
    >> Lew Pitcher wrote:
    >>> if ((ParallelPort = open("/dev/parport0",O_RDONLY|O_DIRECT|O_SYNC)) >= 0)

    > [snip]
    >>> nbytes = write(ParallelPort,
    >>> buffer + total_written,
    >>> sizeof(buffer) - total_written);

    >> Gaak!! I thought I had corrected that error.... Change the above to
    >> if ((ParallelPort = open("/dev/parport0",O_RDONLY|O_SYNC)) >= 0)

    >
    > write() to an fd that's been open()ed with O_RDONLY will return ...
    > what, precisely? I'm guessing it'll be < 0, and errno would be EBADF.
    >


    Gawd, I must have been asleep all day. Thanks, DWC for the catch on that.
    Blame it on first day back after a long, exciting vacation.


    --
    Lew Pitcher

    Master Codewright & JOAT-in-training | Registered Linux User #112576
    http://pitcher.digitalfreehold.ca/ | GPG public key available by request
    ---------- Slackware - Because I know what I'm doing. ------



  9. Re: how to access parall port in my module?

    Matt wrote:
    > google-rambo88 wrote:
    >
    >> It will give great help to me....where can I see it to learn parallel
    >> port?

    >
    > Some of these may be good:
    >
    >> http://parapin.sourceforge.net/doc/parapin.html
    >> http://www.lvr.com/parport.htm
    >> http://www.beyondlogic.org/spp/parallel.htm
    >> http://ee.cleversoul.com/parallel_port.html


+ Reply to Thread