Stop Microsoft

Miscellaneous => Programming & Networking => Topic started by: TheQuirk on 1 August 2002, 07:01

Title: dos.h
Post by: TheQuirk on 1 August 2002, 07:01
I need to find a unix equal of outp() (dos.h). I remember reading it in some source code that was designed for BSD, but I don't know what header it used. Until now I used dos.h, but it only works in DOS and windows 9x.
Title: dos.h
Post by: voidmain on 1 August 2002, 07:29
That appears to be an x86 specific instruction. What do you need the function for? Maybe I can help find a way to do what you need.

I see a few places in a couple of drivers in the Linux kernel where it is defined and used. Don't know if it performs the same thing as the DOS version.  For an example look at a couple of these kernel driver files which are a few places I spotted it:

/usr/src/linux/drivers/net/skfp/h/types.h
/usr/src/linux/drivers/net/skfp/h/skfbi.h

[ July 31, 2002: Message edited by: VoidMain ]

Title: dos.h
Post by: TheQuirk on 1 August 2002, 08:32
I need that function so I could control some electronics.

It's just for an after school experiment to see if  I could do something intresting with my computer and, well, home made elecronic devices  (http://smile.gif) .

Here's a fast example: (if you run it in dos and hook up an oscilloscope to the second hole in your parallel port, you'll see a pattern that looks like this: _-_-_-)

Code: [Select]
Title: dos.h
Post by: voidmain on 1 August 2002, 08:39
Take a look at this:

http://www.hut.fi/Misc/Electronics/circuits/parallel_output.html (http://www.hut.fi/Misc/Electronics/circuits/parallel_output.html)

There is a Linux example in it. ioperm() and outb() are your functions.

[ July 31, 2002: Message edited by: VoidMain ]

Title: dos.h
Post by: voidmain on 1 August 2002, 10:07
I just rewrote your code for x86 Linux:

Code: [Select]

I put the code in a file called "scope.c" and to compile it I use the command:

gcc -lm -O scope.c -o scope

Then you will either have to run it as "root" or set the owner of the program to "root" and set the SUID bit.

Also, in your calculation "u=255*(1+pow(-1,i))/2" you had an "l" (lower case "L") before the plus sign.  I assume that was a typo and should have been a "1" (one) so I changed it. I can think of much easier ways to alternate between 1 and 255 though, and it wouldn't require the math library.   (http://smile.gif)   Also, instead of the "delay(1000)" I used "sleep(1)".

I just tested it on my Linux laptop with a multimeter and it works just fine...

[ August 01, 2002: Message edited by: VoidMain ]

Title: dos.h
Post by: TheQuirk on 1 August 2002, 11:06
i used delay because it usually goes below one second.

and most importantly, thanks!  (http://smile.gif)

[ August 01, 2002: Message edited by: TheQuirk ]

Title: dos.h
Post by: voidmain on 1 August 2002, 11:27
If you need a function like delay() you might then check out the nanosleep() function.
Title: dos.h
Post by: TheQuirk on 1 August 2002, 11:42
thanks, again. I'm just so used to programming in dos/windows... =\
Title: dos.h
Post by: voidmain on 3 August 2002, 10:15
You sparked my interest with your parallel port interests.  I too have always wanted to get into building something that I could control from my computer but I have no electronics background. I decided to go pick up a breadboard, a handfull of LEDs, some wire and a DB25 connector.  I built a cable to plug into my parallel port and wire up all the data pins and a ground to the breadboard.  Stuck in 8 LEDs (Red, Green, and Yellow randomly).

Then I took the lptout.c example and an nsleep.c example (using usleep() to get the millisecond resolution) which gave the the necessary programs to include in a simple shell script to control the LEDs.  I made the shell script so you could input the LED sequences interactively or put all of your LED commands in a file and loop through them to make cool christmas light patterns.  My son made the light sequences.  Here's the three pieces of code:

lptout.c:
Code: [Select]

nsleep.c
Code: [Select]

lights:
Code: [Select]

Then:

# gcc -O -o lptout lptout.c
# chmod u+s lptout
$ gcc -o nsleep nsleep.c
$ chmod +x lights

Then to run the lights program interactively:
$ ./lights

If you want to have the script read the value/delay sequences from a file run it like:

$ ./lights lights.txt

Here is the "lights.txt" file my son came up with:

Code: [Select]

Makes a good Christmas light sequence.             (http://smile.gif)            

Thanks for sparking my interest.  Now it's on to more interesting things like building a battle bot and writing a program to control it.. I am into R/C airplanes as well so I am trying to think of a way to use radio and computer control together.. Any ideas?

[ August 06, 2002: Message edited by: VoidMain ]

Title: dos.h
Post by: TheQuirk on 3 August 2002, 11:42
great little program  (http://smile.gif)
how much weight can one of the airplanes carry? maybe you could fit a small enough single board computer to automate various tasks? it would be a rather costly project, though...

By the way, the battle bots website has a TON of information on how to build your own robot, program it, etc.
Title: dos.h
Post by: voidmain on 3 August 2002, 12:12
Well, I was more thinking about just using the transmitter, receiver, and servos to control things other than airplanes or cars. But if I were to use it for a plane I would keep the computer on the ground and program the transmitter or a second transmitter/receiver.  Or for a remote control truck or something (we have a nitro powered 4WD truck as well).  I do have a large airplane with an 80" wingspan and a 44cc gas engine on it (27% of the full size real plane (CAP 232)) but the last time I flew it nearly exploded in midair due to aileron flutter from overspeed at around 100mph+, have it apart repairing it now.

I'll have to check out the battle bot site, thanks for the tip!

P.S. I just added system bell sound to the LED program. It's changes frequency and duration corresponding to the light sequences. I know, I'm a geek...

[ August 03, 2002: Message edited by: VoidMain ]

Title: dos.h
Post by: Kintaro on 3 August 2002, 16:05
Interesting, Im new to programming in C++ and C but i did this once in powerbasic to make a program to copy files to another with an LPT port.
I have an electronic knoledge, im studying the workings of the MicroPorcessor and so on. And so far i know how a CPU works at the electronic level so what the hell.
Title: dos.h
Post by: TheQuirk on 3 August 2002, 21:20
You could  easily control the airplane then from your computer. But it's kind of dumb, because you'll just be replicating your remote control. You could always, like I said, automate different functions using your computer.
Title: dos.h
Post by: choasforages on 3 August 2002, 22:18
hmmmmm, howabout sticking a video camera on it. i have seen it done on techtv by some 14year useing visual basic. then agian, why doesn't somebody out do the little shit with a real langague like c, c++ or even java.
Title: dos.h
Post by: TheQuirk on 3 August 2002, 22:21
I was thinking about that, but I'm guessing the camera would probably be too heavy or mess something up? Maybe one of those small, cheap netcams will do the trick?
Title: dos.h
Post by: choasforages on 3 August 2002, 23:12
yeah, a usb netcam, i have hooked them up to my linux box before, so maybe an ipaq, of sharp zaruis is in order
Title: dos.h
Post by: TheQuirk on 4 August 2002, 00:01
i've seen devices that would transmit USB signals wirelessly, so I guess that's possible.
Title: dos.h
Post by: TheQuirk on 4 August 2002, 10:56
But I don't belive those devices have enough power to signal that far, though. As voidmain said, that airplane went at 100mph, and I don't even think those devices can hold a candle to even 50 feet.
Title: dos.h
Post by: voidmain on 4 August 2002, 11:07
Actually they do make cameras that you can put on R/C planes and transmit the signal back to the ground. You can even buy the entire plane kit with the camera.  They actually are very reasonable.  I have been thinking about doing that for some time now.  But I don't have to program anything for that.  Just plug in a VCR and record the show.  

And I can't think of any useful purpose for hooking my computer up to control something on a plane or car.  I mean I already have a computerized transmitter that cost me about $1200 that does everything but open my beer for me.

I am rather thinking of robotics type of controlling.  Seems like that should be a fun little project.
Title: dos.h
Post by: choasforages on 4 August 2002, 11:45
well, open beer, that would be a sweet robot,
danger danger voidmain, beer levels down
Title: dos.h
Post by: TheQuirk on 4 August 2002, 21:08
I saw a robot that opened beer!
Title: dos.h
Post by: Kintaro on 18 August 2002, 08:03
No dont use a webcam, you can get small CCD's for about $90 bucks, but you'd want a transmitter and stuff, then pick it up and use a TV card or something.
Title: dos.h
Post by: voidmain on 18 August 2002, 21:37
Yeah, I have seen a hundred ways for getting video from an R/C plane.  Here is one:

http://www.pcug.org.au/~mgriffin/aerocam.htm (http://www.pcug.org.au/~mgriffin/aerocam.htm)

I've definitely seen better implementations...
Title: dos.h
Post by: Kintaro on 18 August 2002, 21:42
My cousin had a rc-plane and rigged a very small CCD to it and had another small UHF transmitter. It worked okay but the engine was not good for the signal. Made cool videos, until it crashed.