Results 1 to 20 of 32

Thread: Parallel Interface

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Cesar Guest

    Default Re: Parallel Interface

    Quote Originally Posted by high_flyer
    Well, yes and no.
    The 'problem' with the parallel port is that you can (and usually want to) manipulate individual pins. not just (or nesseseraly) transmit data.
    Qt Code:
    1. void ParalellPort::setPin(int pin, int value)
    2. {
    3. int oldValue = getChar(pin);
    4. if (value != 0) {
    5. putChar(oldValue | 1 << pin);
    6. } else {
    7. putChar(oldValue & (~ (1 << pin)) );
    8. }
    9. }
    10.  
    11. int ParalellPort::getPin(int pin)
    12. {
    13. return (getChar() & (1 << pin)) ? 1 ? 0;
    14. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Parallel Interface

    Ok, here is my implementation, at the moment the fact its Qt has no advantage.
    One could build in a polling mechanism that will send signals on pin state changes.
    This clas works, it is being used in a program that controlls harware through the paraport.
    You should install parapin and read the docs there.
    Attached Files Attached Files

  3. The following user says thank you to high_flyer for this useful post:

    wallyqt (13th November 2007)

  4. #3
    Join Date
    Feb 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Parallel Interface

    Well... I'd just like to thank both of you. This helped very very much, I got some tutorial about parallel port interfacing. With all code and tips you passed to me, I will implement it. Thanks a lot.

  5. #4
    Join Date
    Nov 2007
    Posts
    27
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Parallel Interface

    I tried the parapin drivers and it works good as root.
    When using the parapin-kernel-driver i can access the port from user-space.
    Do anybody know how to implement the kerneldriver with qt.
    I am looking for something very similar "QParaport.zip" from "high_flyer".

    I able to open the parapindriver with:
    (set pins is also possible:
    int kparappWidget::pushButtonOpen_clicked()
    {
    pardevice = open("/dev/ppdrv_device", 0);
    if (pardevice < 0) {
    fprintf(stderr, "pardevice open failed\n");
    exit(-1);
    }
    return 0;
    }

    but when i call the close function, all widgets on the application mainWin
    disappear and i only can close (kill) the app.

    int kparappWidget::pushButtonClose_clicked()
    {
    close(pardevice);
    return 0;
    }

    here is the code for setting pins:

    void kparappWidget::pushButtonSetPins_clicked()
    {
    ioctl(pardevice, PPDRV_IOC_PINMODE_OUT, LP_PIN02);

    ioctl(pardevice, PPDRV_IOC_PINSET, LP_PIN02 | LP_PIN03 | LP_PIN04 | LP_PIN05 | LP_PIN06 | LP_PIN07 | LP_PIN08 | LP_PIN09);
    }

    cheers wally
    Last edited by wallyqt; 13th November 2007 at 12:03. Reason: tried to removed disturbing smiles

  6. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Parallel Interface

    I tried the parapin drivers and it works good as root.
    When using the parapin-kernel-driver i can access the port from user-space.
    I am not sure you mean what your text says. i.e:
    Do you mean you want to use the kernel module from user space, or, do you want to use the user space module with a user that is not root?

    It could be that you have problem with read write right for non root users, you can fix that with chmod.

    You can't use the kernel module from user space (and you shouldn't)
    And if you don't need PIN10, (and from your code it seams that way) you don't need to - the user space module should be used - and you can the QParaport class for what you described here.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #6
    Join Date
    Nov 2007
    Posts
    27
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Parallel Interface

    high_flyer,

    you are right, its confusing because i didn't understand it myself not entirely.
    I want to use the kernel-driver of parapin which i load during boot.
    After the driver is once loaded i do not want to use root anymore.

    In command-line apps it works perfect, but i have problems to close the
    device properly in a kde-qt-app.

    i think i should use Qiodevice.h and not mixing old and new stuff together,
    but i am not a good programmer. So i ask in this forum.

    As far as i understand you code sample - it needs root previleges.
    But i want to use the parapin stuff also in a larger application which not should run as root.

    Maybe i do some fundamnetal error

    cheers wally

  8. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Parallel Interface

    I want to use the kernel-driver of parapin which i load during boot.
    No, you want to use the user space module
    Only the system is allowed to access the kernel space module.
    Read the parapin documentation.

    The problem with QParaport is that it is written for Qt3.
    And I haven't had a look at this code for a very long time, so I don't know how easy it should be to port it to Qt4. (I forgot about this during the last post)
    But I think it should be just a matter of changing the header deceleration.

    As far as i understand you code sample - it needs root privileges.
    The *code* doesn't require root privileges.
    Under linux, you can set access privileges using the chmod command.
    read the chmod command man pages for usage. (its simple)

    i think i should use Qiodevice.h and not mixing old and new stuff together,
    QIOdevice could be good if you'd want to implement the driver your self.
    But if you use the ready made parapin driver, all you can do is either wrap it (as I did with QParaport) or use it directly.
    It has nothing to do with mixing new and old.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #8
    Join Date
    Nov 2007
    Posts
    27
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Parallel Interface

    high_flyer

    Thanks for your patience and explanation.

    Any concrete idea what i could do to find the problem
    with close(device) function in the code above.

    Gnu debugger and system messages do not have
    any interesting outputs on this problem.

    cheers wally

  10. #9
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Parallel Interface

    yes - use the user space module.
    You should not access kernel space from user space.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  11. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Parallel Interface

    read the parapin user documentation in the link I posted before on this thread.
    Specifically look for the section:
    "Parapin Basics
    Userspace version and kernel version "
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  12. #11
    Join Date
    Nov 2007
    Posts
    27
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Parallel Interface

    high_flyer

    for me the parapin documentation sounds as follows:
    There is a C library version and a Kernel Module version with a device driver.

    Quotes from parapin documentation:

    C library version:
    Programs using Parapin must be running as root when they are initialized.

    Kernel-Module version:
    Before the parapindriver device interface may be used, an entry in /dev must be created that corresponds to the device driver module loaded in to the kernel

    Once parapindriver is successfully loaded, and a corresponding /dev entry is in place, initialization and shutdown of the parallel port are easy. To initialize the parapin system, just call open(2) on the /dev entry as you would any other device file:

    int device;
    device = open("/dev/<device-name>", 0);

    if (device < 0) {
    fprintf(stderr, "device open failed\n");
    exit(-1);
    }

    To shutdown the parapin system you simply have to call close(2):

    close(device);


    I want to use the last one and excepting the "close(device) everything is ok.


    cheers wally

  13. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Parallel Interface

    Ok, I see what you mean.
    It has been quite long since I used this, so I guess I need to read the docs again

    Did you do what is says in the docs about initializing the driver?
    int pin_init_kernel(int lpt, void (*irq_func)(int, void *, struct pt_regs *));
    AND :
    void pin_release();
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  14. #13
    Join Date
    Nov 2007
    Posts
    27
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Parallel Interface

    high_flyer

    No, because afaik this is the initialization for the C-library version.
    During boot my system do the following (of course as root) :


    DEVNAME="ppdrv_device"
    depmod
    modprobe kparapin
    modprobe parapindriver devname=${DEVNAME}
    mknod /dev/${DEVNAME} u `grep $DEVNAME /proc/devices | cut -d " " -f 1` 0
    # Change mode and ownership here if necessary
    chmod 777 /dev/${DEVNAME}
    chown root /dev/${DEVNAME}
    chgrp root /dev/${DEVNAME}

    After this is done i acces the parapellport (as user) by opening the device:

    pardevice = open("/dev/ppdrv_device", 0);
    if (pardevice < 0) {
    fprintf(stderr, "pardevice open failed\n");
    exit(-1);

    from this point on i can simply acces the parallelport with the ioctl command, e.g.:

    ioctl(pardevice, PPDRV_IOC_PINMODE_OUT, LP_PIN02);
    ioctl(pardevice, PPDRV_IOC_PINSET, LP_PIN02 | LP_PIN03)

    I preferred this because i added some parts to the KSIMUS Application.
    Its a Electronics simulator by Rasmus Diekenbrock.
    I want to avoid the need of root access during the simulator is accessing
    the parallelport. It works perfect in KSIMUS (also the close(device) command
    which is the reason i wrote here.

    In a simple new Kdevelop project, just for open the device,
    setting some pins and close the device, this mini application
    doesn't work as expected.

    When i call "close(device" all of the widgets ( 3 pushbuttons for open/set/close)
    disappear and thats it. I have to kill the process.

    I wrote here in QT-Centre because i think its not a problem of parapin.
    Parapin works perfect e.g. in the ksimus enveronment.

    I am sure i am making some coding or logical errors in my code.
    ( maybe the close(device) command from unistd.h is not welcome.

    Also some hint is desireable how to trace what is going on in the app
    after calling close(device) and the "crash"

    "gdb" and the system messages do not contain strange infos on this.

    cheers wally

  15. #14
    Join Date
    Nov 2007
    Posts
    27
    Thanks
    5
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Parallel Interface

    Quote Originally Posted by high_flyer View Post
    No, you want to use the user space module
    Only the system is allowed to access the kernel space module.
    .
    Quote Originally Posted by high_flyer View Post
    yes - use the user space module.
    .

    I think using the above code i do so hm ?
    (now i am completely confused)

    cheers wally

Similar Threads

  1. C++ Interface ..???
    By joseph in forum General Programming
    Replies: 3
    Last Post: 28th May 2008, 09:27
  2. Interface composition and QObject
    By brcain in forum Qt Programming
    Replies: 9
    Last Post: 20th November 2006, 17:56
  3. User Interface with QTableView
    By Brandybuck in forum Qt Programming
    Replies: 1
    Last Post: 22nd March 2006, 23:24
  4. Qt interface running extremely slowly...
    By jazztpt in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2006, 11:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.