Maker Pro
Maker Pro

Parallel port and Visual Basic?

Z

Zucker

I am in the process of building a circuit that will monitor the start and
finish times for pine box derby cars. I would like to be able to catch these
events by feeding signals, through the parallel port, to a Visual Basic
program. I was thinking of using the eight data pins from the parallel port
to monitor eight lanes.

The electronics are good to go. My problem is with Visual Basic.

Does anyone know how to access and capture bit patterns from the parallel
port using Visual Basic?

Steve

PS...I have asked this same question in several programming newsgroups, but
I have not recieved any responses.
 
S

Si Ballenger

I am in the process of building a circuit that will monitor the start and
finish times for pine box derby cars. I would like to be able to catch these
events by feeding signals, through the parallel port, to a Visual Basic
program. I was thinking of using the eight data pins from the parallel port
to monitor eight lanes.

The electronics are good to go. My problem is with Visual Basic.

Does anyone know how to access and capture bit patterns from the parallel
port using Visual Basic?

Steve

PS...I have asked this same question in several programming newsgroups, but
I have not recieved any responses.

You may want to get the lpt-vb.zip file from the below site. It
has some vb source code for the parallel port. If you are using
NT/2K/XP, you may also need an application called userport
(google for userport.zip) to get direct hardware access to the
parallel port.

http://neil.fraser.name/software/lpt/
 
M

mike

Zucker said:
I am in the process of building a circuit that will monitor the start and
finish times for pine box derby cars. I would like to be able to catch these
events by feeding signals, through the parallel port, to a Visual Basic
program. I was thinking of using the eight data pins from the parallel port
to monitor eight lanes.

The electronics are good to go. My problem is with Visual Basic.

Does anyone know how to access and capture bit patterns from the parallel
port using Visual Basic?

Steve

PS...I have asked this same question in several programming newsgroups, but
I have not recieved any responses.

You have several problems.
The operating system may prohibit you from accessing the parallel port.
You may need a driver to enable this.
Visual Basic prohibits you access to the parallel port.
You may need a dll/driver/ocx etc to gain access.
You need some way to time the event.

Variable program latencies.

All these layers of software mean that you can't get an accurate or even
repeatable time measurement. The newer the OS, the greater the uncertainty.

Suggestion 1:
Do the sense/calculate in a microcontroller and send the answer to VB
via RS232 port.

Suggestion 2:
Ditch VB. Run pure DOS. Use the hardware timer in the 8253
emulation...it's the timer that normally runs the beeper.
Program it in something compiled and determinate like assembler or C.
This should give you guraranteed sub-second repeatability.

mike

--
Return address is VALID but some sites block emails
with links. Delete this sig when replying.
..
Wanted, PCMCIA SCSI Card for HP m820 CDRW.
FS 500MHz Tek DSOscilloscope TDS540 Make Offer
Wanted, 12.1" LCD for Gateway Solo 5300. Samsung LT121SU-121
Wanted 12" LCD for Compaq Armada 7770MT.
Bunch of stuff For Sale and Wanted at the link below.
MAKE THE OBVIOUS CHANGES TO THE LINK
ht<removethis>tp://www.geocities.com/SiliconValley/Monitor/4710/
 
J

John Larkin

I am in the process of building a circuit that will monitor the start and
finish times for pine box derby cars. I would like to be able to catch these
events by feeding signals, through the parallel port, to a Visual Basic
program. I was thinking of using the eight data pins from the parallel port
to monitor eight lanes.

The electronics are good to go. My problem is with Visual Basic.

Does anyone know how to access and capture bit patterns from the parallel
port using Visual Basic?

Steve

PS...I have asked this same question in several programming newsgroups, but
I have not recieved any responses.

Run PowerBasic under DOS. No problems!

John
 
C

Chris

John said:
Run PowerBasic under DOS. No problems!

John

I agree with Mr. Larkin. As a WAG, assume the Pinewood Derby cars are
going at least 10 mph at the end of the track. That means about 15
feet per second, which means 20 car lengths per second (8" car length).
Winning by 1/10th of a car length (you can easily see that yourself)
would mean you need much better than 5ms. latency. I would think
0.5ms. latency would be barely adequate for this job. Sorry, but that
isn't going to happen with VB. No way.

Power BASIC is ideal for this job.

If the OP wants to hijack the PC system timer for greater accuracy
instead of relying on a calibrated timing loop, here's a C program
listing that could easily be ported to Power BASIC:

http://www.edn.com/index.asp?layout=articlePrint&articleID=CA231577

For newbies or hobbyists using the parallel port for real-world I/O,
the ideal source is Jan Axelson's "Parallel Port Complete", which is
available from many sources, including the Lakeview Research website:

http://www.lvr.com/parport.htm

The links on this webpage alone should be enough for the OP to figure
out how to do parallel port hardware in Power BASIC, QB, C, or any DOS
language he knows already. But the book and CD are a great investment,
and will allow the OP to learn more and get up to speed quickly.

The book also has the drivers he would need to do this in VB, as well
as lots of sample code. However, it probably won't work well, because
no VB program will be able to devote exclusive attention to the port.
Windows just has so many other fascinating things to do that are _so_
important ;-) He'll probably only get ballpark 10 ms. or 20ms. latency
at best with VB, which isn't good enough.

Thanks,
Chris
 
B

Bob Masta

I am in the process of building a circuit that will monitor the start and
finish times for pine box derby cars. I would like to be able to catch these
events by feeding signals, through the parallel port, to a Visual Basic
program. I was thinking of using the eight data pins from the parallel port
to monitor eight lanes.

The electronics are good to go. My problem is with Visual Basic.

Does anyone know how to access and capture bit patterns from the parallel
port using Visual Basic?

Steve

PS...I have asked this same question in several programming newsgroups, but
I have not recieved any responses.
In addition to what others have said, note that the default port
configuration only has 5 input lines, one of which is inverted,
and they are on the Status port. If you want to read 8 inputs
at once on the Data port (which defaults to output-only), you'll need
to set a bidirectional mode. Alternatively, you could use 2 reads, of
the Status and Control ports, and get perhaps as many as 10 lines
with some bit-fiddling.

I agree that Windows is unlikely to work for this, unless you are
handy with Ring 0 driver development. I'd use real-mode DOS
(*not* a "DOS prompt" from Windows), which requires Win9x or
earlier. You will be able to get response times in the 10 microsecond
range. You will have to read the port(s) in a tight loop if you
want to get individual times, although if you just want to find the
winner you could OR all lines together to trigger an interrupt
(the printer interrupt, typically IRQ 7) when the first one crosses,
and then read the port to figure out which one it was.

You might be able to do this as a TSR, probably in assembly,
and have it post the results somewhere that your Basic code
could read it at its own pace. But you can't install TSRs under
Windows, so that leaves out Visual Basic. Sorry! Might
want to look into old QuickBasic for DOS.

Best regards,




Bob Masta
dqatechATdaqartaDOTcom

D A Q A R T A
Data AcQuisition And Real-Time Analysis
www.daqarta.com
 
B

Bob Masta

I am in the process of building a circuit that will monitor the start and
finish times for pine box derby cars. I would like to be able to catch these
events by feeding signals, through the parallel port, to a Visual Basic
program. I was thinking of using the eight data pins from the parallel port
to monitor eight lanes.

The electronics are good to go. My problem is with Visual Basic.

Does anyone know how to access and capture bit patterns from the parallel
port using Visual Basic?

Steve

PS...I have asked this same question in several programming newsgroups, but
I have not recieved any responses.

I just had a wild idea that should do the trick in any version of
Windows, using VB or almost any language: Use the sound card!
You can set the sample rate to 44100 or 48000 Hz to get better
than 23 usec resolution. There is good language and API
support for recording. All you need is a way to encode the
8 channels onto one (or 2) analog input. The solution is to
make a really simple D/A converter. I'd recommend an R-2R
ladder type, since they are less sensitive to resistor tolerance
than a weighted resistor scheme. Now each channel will
produce it's own unique level, and each observed level will
be due to one and only one unique combination of inputs.

The sound card is AC coupled, so this only works for a
situation like yours, where the cars pass a detector and
produce a pulse that lasts a short time. Sound cards typically
go down to at least 20 Hz, so the waveform should be
pretty flat on top for the short duration of a car's passage.

If you have only one car pass it's detector at a time for
a "clear winner" situation, then you just get a pulse whose
height encodes which track it is. The duration tells you the
speed. If you get more than one car at a time, you will
have to decode the amplitude waveform, but I think this
will be pretty straightforward. (Certainly compared to
writing ring 0 drivers to use the parallel port!) And note
that this is "real-time" performance under Windows, which
is nearly impossible to get any other way, since the sound
card is doing all the heavy lifting.

Note that you will need to take care that you set the
mixer controls to the same settings each time. Windows
doesn't make this easy; you either get uncalibrated
sliders in the standard mixer, or you have to confront
the Mixer API... the most abominable interface in the
whole Windows menagerie. So you might want to
come up with a simple calibration scheme, where
you just run one car down the MSB lane and normalize
to the recovered pulse height.

Best regards,




Bob Masta
dqatechATdaqartaDOTcom

D A Q A R T A
Data AcQuisition And Real-Time Analysis
www.daqarta.com
 
Top