direct parallel port access from Lisp (x86, Linux, CLISP or CMUCL)
From: Frank Sergeant (frank_at_pygmy.utoh.org)
Date: 06/30/04
- Next message: Erann Gat: "Re: I wish I'd never met Lisp"
- Previous message: RobertMaas_at_YahooGroups.Com: "Re: Is anything easier to do in java than in lisp?"
- Next in thread: Andreas Hinze: "Re: direct parallel port access from Lisp (x86, Linux, CLISP or CMUCL)"
- Reply: Andreas Hinze: "Re: direct parallel port access from Lisp (x86, Linux, CLISP or CMUCL)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Jun 2004 01:37:44 -0500
I am accessing a relay board attached to a Linux x86 box using CLISP.
The relay board has 8 relays. Each relay is controlled by one of the 8
data bits on the parallel port.
Lisp calls a small executable (named 'simpleparport', written in C).
For example, to turn 4 relays on and 4 off:
(shell (format nil "./simpleparport ~D ~D" #x378 #xA5))
To to turn on the bit0 relay and then off again:
(shell (format nil "./simpleparport ~D ~D" #x378 1))
(shell (format nil "./simpleparport ~D ~D" #x378 0))
I wonder if I am doing it the hard way. Is there an easier way to do it
directly from Lisp? (Especially CMUCL or CLISP)
Below is the C program (stripped of error handling) in case there isn't
an easier way, in case it's useful to anyone. The executable needs to
run as root in order to set io permissions. The Linux
IO-Port-Programming HOWTO provided the key information. Apparently, the
optimision level ('-O2') is important. The resulting executable can be
run directly from the command line, or called from CLISP with EXECUTE or
SHELL. The arguments must be in decimal for this simple version of the
program.
------- simpleparport.c -------
/* Compile with `gcc -O2 -o simpleparport simpleparport.c' */
#include <stdio.h>
#include <unistd.h>
#include <asm/io.h>
int main (int argc, char *argv[]) {
int ioaddress, value;
sscanf (argv[1], "%d", &ioaddress);
sscanf (argv[2], "%d", &value);
if (ioperm (ioaddress, 3, 1)) {
perror ("ioperm");
exit (1);
}
outb (value, ioaddress);
exit (0);
}
-- Frank
- Next message: Erann Gat: "Re: I wish I'd never met Lisp"
- Previous message: RobertMaas_at_YahooGroups.Com: "Re: Is anything easier to do in java than in lisp?"
- Next in thread: Andreas Hinze: "Re: direct parallel port access from Lisp (x86, Linux, CLISP or CMUCL)"
- Reply: Andreas Hinze: "Re: direct parallel port access from Lisp (x86, Linux, CLISP or CMUCL)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]