LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   $./lptloop Couldn't get the port at 378 (https://www.linuxquestions.org/questions/linux-general-1/%24-lptloop-couldnt-get-the-port-at-378-a-642101/)

cwc 05-14-2008 06:34 AM

$./lptloop Couldn't get the port at 378
 
I am building a simple circuit I trying to control from the
parallel port using linux gcc.
I get the following error. I don't understand what I need to
do to get my code to work from a non root user.
Any hint would be appreciated.

./lptloop Couldn't get the port at 378


[code]
// lptloop
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
//#include </usr/include/sys/io.h>
#define base 0x378 /* printer port base address */
#define value 255 /* numeric value to send to printer port */
#define value0 0 /* numeric value to send to printer port */
#define value1 1 /* numeric value to send to printer port */
#define value2 2 /* numeric value to send to printer port */
#define value3 4 /* numeric value to send to printer port */
#define value4 8 /* numeric value to send to printer port */
#define value5 16 /* numeric value to send to printer port */
#define value6 32 /* numeric value to send to printer port */
#define value7 64 /* numeric value to send to printer port */
#define value8 128 /* numeric value to send to printer port */

main(int argc, char **argv)
{
int i,p;
if (ioperm(base,1,1))
fprintf(stderr, "Couldn't get the port at %x\n", base), exit(1);

outb(value0, base);//clear printer port
for (p = 0;p < 1000;p++){
outb(value0, base);
sleep(1);
outb(value1, base);
sleep(1);
outb(value2, base);
sleep(1);
outb(value3, base);
sleep(1);
outb(value4, base);
sleep(1);
outb(value5, base);
sleep(1);
outb(value6, base);
sleep(1);
outb(value7, base);
sleep(1);
outb(value8, base);
sleep(1);
}
//outb(value0, base);

}

theNbomr 05-16-2008 09:39 AM

You can't use the IO instructions without root permissions. To allows this would completely undermine all security on the system. That is why access to real hardware is done through kernel-mode device drivers. Your application looks as if it is only using the data signals of the parallel port; perhaps simply writing bytes to /dev/lp will suffice.
--- rod.

cwc 05-16-2008 06:07 PM

That's what I thought
 
Quote:

Originally Posted by theNbomr (Post 3155299)
You can't use the IO instructions without root permissions. To allows this would completely undermine all security on the system. That is why access to real hardware is done through kernel-mode device drivers. Your application looks as if it is only using the data signals of the parallel port; perhaps simply writing bytes to /dev/lp will suffice.
--- rod.

Thank you very much.

That's what I thought. It looks like I have some work to do :)
I've looked into a couple of device driver books.

michaelk 05-17-2008 04:39 PM

Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.


All times are GMT -5. The time now is 01:43 PM.