Does anyone can help me how to interface Qt with parallel port? I'm developing a software that sends some commands to the parallel. Wich class may I use? Thanks
Does anyone can help me how to interface Qt with parallel port? I'm developing a software that sends some commands to the parallel. Wich class may I use? Thanks
i'm not sure but i think that qt cant help you with it, you must use standart api approachOriginally Posted by r00tz
![]()
a life without programming is like an empty bottle![]()
For which platform?
I implemented a basic Qt wrapped for parapin (the paraport driver for linux) if you want it I can post it.
I guess you should create a subclass of QIODevice and implement all the platform-specific issues by yourselfSomething like this:
A quote from TT's docs:Qt Code:
//ParalellPort.h #include <QIODevice> Q_OBJECT public: virtual ~ParalellPort(); virtual bool isSequential () const { return true; } virtual bool open(OpenMode); virtual void close (); //.. protected: virtual qint64 readData ( char * data, qint64 maxSize ); virtual qint64 writeData ( const char * data, qint64 maxSize ); private: #ifdef Q_OS_UNIX QFile deviceFile; #endif }; //ParalellPort.cpp #include "ParalellPort.cpp" #ifdef Q_OS_UNIX , deviceFile(port) #endif { } bool ParalellPort::open(OpenMode mode) { #ifdef Q_OS_UNIX return deviceFile.open(mode); #endif #ifdef Q_OS_MACX //... #endif #ifdef Q_OS_WIN32 //... #endif } //...To copy to clipboard, switch view to plain text mode
Subclasses of QIODevice are only required to implement the protected readData() and writeData() functions.
Well, yes and no.I guess you should create a subclass of QIODevice
The 'problem' with the parallel port is that you can (and usually want to) manipulate individual pins. not just (or nesseseraly) transmit data.
Originally Posted by high_flyer
Qt Code:
void ParalellPort::setPin(int pin, int value) { int oldValue = getChar(pin); if (value != 0) { putChar(oldValue | 1 << pin); } else { putChar(oldValue & (~ (1 << pin)) ); } } int ParalellPort::getPin(int pin) { return (getChar() & (1 << pin)) ? 1 ? 0; }To copy to clipboard, switch view to plain text mode
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.
wallyqt (13th November 2007)
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.
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
I am not sure you mean what your text says. i.e: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 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.
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
No, you want to use the user space moduleI want to use the kernel-driver of parapin which i load during boot.
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.
The *code* doesn't require root privileges.As far as i understand you code sample - it needs root privileges.
Under linux, you can set access privileges using the chmod command.
read the chmod command man pages for usage. (its simple)
QIOdevice could be good if you'd want to implement the driver your self.i think i should use Qiodevice.h and not mixing old and new stuff together,
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.
Bookmarks