![]() |
![]() Advanced DNS Management |
New ZoneEdit. New Managment. FREE DNS Is Back Sign Up Now |
![]() |
![]()
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"); } } |
|
|
![]() |
![]()
Post
#2
|
|
Its GNU/Linuxhelp.net ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Support Specialist Posts: 1,807 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? |
|
|
![]()
Post
#3
|
|
Whats this Lie-nix Thing? ![]() Group: Members Posts: 3 Joined: 11-October 08 Member No.: 13,708 ![]() |
|
|
|
![]() ![]() |
![]() |
Lo-Fi Version | Time is now: 24th April 2018 - 09:13 AM |