added files
git-svn-id: svn://anubis/misc/parport-write@230 bd8a9e45-a331-0410-811e-c64571078777
This commit is contained in:
parent
2addf4e52a
commit
7f04cbfac6
7
Makefile
Normal file
7
Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
TARGET := parport-write
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(TARGET).c
|
||||
gcc -o $@ $<
|
78
parport-write.c
Normal file
78
parport-write.c
Normal file
@ -0,0 +1,78 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/parport.h>
|
||||
#include <linux/ppdev.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char getVal(int argc, char * argv[])
|
||||
{
|
||||
int val = 0xFF;
|
||||
if (argc >= 2)
|
||||
{
|
||||
if (strlen(argv[1]) >= 2 && strncmp(argv[1], "0x", 2) == 0)
|
||||
{
|
||||
sscanf(argv[1] + 2, "%x", &val);
|
||||
}
|
||||
else
|
||||
{
|
||||
sscanf(argv[1], "%d", &val);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Value not specified, using 0x%x\n", val);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
int fd;
|
||||
int result;
|
||||
char val = getVal(argc, argv);
|
||||
|
||||
fd = open("/dev/parport0", O_RDWR);
|
||||
|
||||
if (fd == -1)
|
||||
{
|
||||
perror("Could not open parallel port");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Claiming parallel port\n");
|
||||
if (ioctl(fd, PPCLAIM, NULL))
|
||||
{
|
||||
perror("Could not claim the parallel port!");
|
||||
close(fd);
|
||||
return 2;
|
||||
}
|
||||
|
||||
int mode = IEEE1284_MODE_BYTE;
|
||||
if (ioctl(fd, PPSETMODE, &mode))
|
||||
{
|
||||
perror("Could not set mode");
|
||||
ioctl(fd, PPRELEASE);
|
||||
close(fd);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int dir = 0x00;
|
||||
if (ioctl(fd, PPDATADIR, &dir))
|
||||
{
|
||||
perror("Could not set parallel port direction");
|
||||
ioctl(fd, PPRELEASE);
|
||||
close(fd);
|
||||
return 4;
|
||||
}
|
||||
|
||||
ioctl(fd, PPWDATA, &val);
|
||||
|
||||
printf("Releasing parallel port\n");
|
||||
ioctl(fd, PPRELEASE);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user