On Tue, 2004-06-01 at 00:08, James Nickerson wrote:
> On Sunday 16 May 2004 01:01 pm, Gabriel Gunderson wrote:
> > I'm picking-up on an old project that I wrote in C# under windows that
> > would read and set the pins on parallel ports. It used a .dll that
> > Linux. The deal is I would need to write or find a library in another
> > language to do the actual reading and writing and use the
> > System.Runtime.InteropServices to get at it.
>
> > What I'm wondering is....
> > Anyone know of how to do this in Linux?
>
> I know this is a late response, but if it still helps, here's the basic driver
> I wrote a while back in C to control a standard RC servo through the parallel
> port.
>
> /*
> servo.cpp
> sends timed pulse to pin(s) of parallel port to control RC servo
> author: James Nickerson
> */
>
>
> #include <iostream>
> #include <sys/io.h>
> #include <unistd.h>
> #include <time.h>
> #include <sched.h>
>
> using namespace std;
>
> #define PAR_PORT 0x378
> const int RC_VALLEY_TIME = 20000; //20k us = 20 ms
> const int SEEK_TIME = 25; //in loops
>
> int main (int argc,char **argv){
>
> pid_t thispid = getpid();
> struct sched_param *created_sp = new sched_param;
> created_sp->sched_priority=1;
> const struct sched_param *sp = created_sp;
>
> // Setup process to soft real time scheduling
> sched_setscheduler(thispid, SCHED_FIFO, sp);
>
> //Acquire port permission
> if(ioperm(PAR_PORT, 1, 1)) {
> cout << "FAILED TO ACQUIRE PORT PERMISSION!\n";
> exit(-1);
> } //if... else all good
>
> outb(0,PAR_PORT); //reset port
> int pulseLength; //in useconds
> int pins; //binary value(in dec), for our purpose up to 1111b (15d)
> sscanf(argv[1],"%d",&pins);
> sscanf(argv[2],"%d",&pulseLength);
>
> for (int t=0; t < SEEK_TIME; t++) { //to give it time to get there
> outb(pins, PAR_PORT);
> usleep(pulseLength);
> outb(0, PAR_PORT);
> usleep(RC_VALLEY_TIME);
> } //for t
>
> cout << "Transmission successful, Relinquishing port permission: ";
> if (!ioperm(PAR_PORT, 1, 0)) cout << "Success!\n"; else cout << "Fail.\n";
>
> return 0;
> }
>
> > P.S. Anyone into motion control or robotics on the list?
Cool, thanks.
> What kind of stuff are you working on?
All kinds of stuff. First I would like to get a basic XYZ table working
and mount a laser or cutting torch on it.
> I've been toying with the idea of trying to get a robotics group of some sort
> together, like I've noticed other places have. Y'all think there would be
> much interest?
Of course I would be game.
Gabe
____________________
BYU Unix Users Group
http://uug.byu.edu/
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list