Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
> ioperm segmentation error
linuxNoob17635
post Oct 11 2008, 05:58 AM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 3
Joined: 11-October 08
Member No.: 13,708



Hi guys, I'm having trouble with my program accessing the parallel port. I'm getting a segmentation error when I run it.

I'm quite sure that it has something to do with the way I'm using ioperm. Am I looking in the right direction?

Thanks in advance.

#include <stdio.h>
#include <stdlib.h>
#include <sys/io.h>
#include <time.h>
#include <unistd.h>

#define base 0x0378

void forward(int high, int low);
void reverse(int high, int low);

char dir;
int value, high, low;

int main(int argc, char *argv[])
{
dir = argv[1][0];
value = atoi(argv[2]);
high = ((100 - value) * 10);
low = (1000 - high);

if (argc!=3)
{
fprintf(stderr, "Error: Wrong number of arguments. Please enter direction (d or r) followed by speed (0 - 100).\n"), exit(1);
}

if ((value<0) || (value>100))
{
fprintf(stderr, "Error: motor speed must be between 0 and 100.\n"), exit(1);
}

if (dir == 'f')
{
forward(high,low);
}

if (dir == 'r')
{
reverse(high,low);
}

if (ioperm(base,1,1))
{
fprintf(stderr, "Couldn't get the port at %x\n", base), exit(1);
}
return 0;
}

void forward(int high, int low)
{
for(;;)
{
printf("Motor running forward.\n");
usleep(high);
outb(0x0F, base);
printf("high\n");
usleep(low);
outb(0x0, base);
printf("low\n");
}
}

void reverse(int high, int low)
{
for(;;)
{
printf("Motor running in reverse.\n");
usleep(high);
outb(0xF0, base);
printf("high\n");
usleep(low);
outb(0x0, base);
printf("low\n");
}
}
Go to the top of the page
 
+Quote Post
 
Start new topic
Replies
michaelk
post Oct 11 2008, 06:00 PM
Post #2


Its GNU/Linuxhelp.net
*******

Group: Support Specialist
Posts: 1,797
Joined: 23-January 03
Member No.: 360



Excellent and thanks for replying back that your program is working.
BTW what type of motor controller are you using?
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 20th October 2017 - 04:40 PM