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?

What kind of stuff are you working on? I've been trying to think up a good 
project since I moved last month and tore down my internet-controllable 
webcam. I was thinking maybe an automatic loading toaster, but haven't really 
made any moves. I just acquired a Xilinx-based board I want to mess with too, 
but as far as I can tell it's only programmable via windows ):  It's nice for 
little robots and things that need to be mobile. Otherwise an old desktop is 
great. Even this ancient Pentium laptop with 16 megs of Ram that barely had 
room on the hard drive for a minimal linux install was more than sufficient 
for the robotics I was messing around with.

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?
        
________________
James Nickerson


____________________
BYU Unix Users Group 
http://uug.byu.edu/ 
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to