Reading Inputs from PC Parallel Port in Visual Basic

D

Thread Starter

David

<p>Dear all,

<p>I have created an application using Microsoft Excel which will allow me to use my PC's parallel port.

<p>I have downloaded inpout32 and placed it in my windows/system folder. I have typed the following code into a separate module:
<pre>
Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" _
(ByVal PortAddress As Integer) _
As Integer

Public Declare Sub Out Lib "inpout32.dll" Alias "Out32" _
(ByVal PortAddress As Integer, _
ByVal Value As Integer)
</pre>
<p>using a simple command like "out 888, number" I am able to output any bit pattern I wish. However I am having problems reading the inputs.

<p>I understand the command is inp(888) and indeed if I was to output a bit pattern and then use the above command I am able to get a correct reading. The problem arises when I use external circuitry to supply the digital inputs to the port. Even something as simple as connecting a 5v powersupply to the port does not seem to work.

<p>Any help on this matter would be GREATLY appreciated.

<p>Many thanks.
 
I'm having that same problem. Writing up to the data port works. Since my port is a ECP Port, the data line is bi-direct. I tried reading however that didn't work. I also try using the status lines instead of data. That didn't work either, i did hook up a dmm to the status line and i kept getting a high. I also checked the control lines and got a high too, its negative logic, (however the control lines worked for writing data too, just like the data, i tested it out).

I don't know... I'll keep test.

regards
 
<p>Hi, this is a long tutorial. But at least it’s in depth. If the text looks funny due to the format of the website. I can email you the .doc file. [email protected]

<p>I was the same author as posted above. I've solved the riddle! Before I get ahead of myself, the parallel port I used is an ECP (Extended Capability Port). Find out if your port is the same as mine, yours could be an EPP or SPP.

<p>Go to “Control Panel / System / Hardware Tab / Device Manager / Ports (Com & LPT) / Printer Port (LPT1 or LPT2) /”

<p>It should indicate what type you have. You can also go to the ‘Resource’ Tab to indicate the range of your port: mine is I/O Range 0378 – 037F, ignore the other I/O range.

<p>For the ECP, there are some over headers if I was to use the data port as both input and output. Instead, I used the signal port for data processing.

<p>As mention before, I used a DMM to test out the ports (nothing connected to the ports yet) and I used the read function from the inpout32.dll, .ie In(Port Address), my particular port address was:

<p>Data Port: 0x378H or in VB Express &H378S
Status Port: 0x379H or in VB Express &H379S
Control Port: 0x37AH or in VB Express &H37AS
*note these port address are in HEX

<p>I used the messagebox.show and displayed the values. Here are my results again.
<pre>
Data Port: 0 <-- Correct!
Status Port: 120 Decimal; the following represents in binary form with the appropriate pins.
| S7 | S6 | S5 | S4 | S3 | S2 | S1 | S0 |
| 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
Control Port: 4 Decimal: the following represents in binary form with the appropriate pins.
| C7 | C6 | C5 | C4 | C3 | C2 | C1 | C0 |
| 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
</pre>
<p>Now, how does this help? It helps! Since I’m using the signal port to read data in (instead of the data port, for the reasons of overheads and extra work!). Look closely at the signal port and the pins. Refer to http://www.codeproject.com/csharp/csppleds.asp for pin locations. S6-S3 are all high! (actually S7 is high too, its just inverted). If I tie one of these pins, .ie pin 11, to a ground pin, .ie pin 25 and run my program. I’ll get a readout of 248 Decimal instead of 120 Decimal! Huh?

<pre>248 Decimal: the following represents in binary form with the appropriate pins.
| S7 | S6 | S5 | S4 | S3 | S2 | S1 | S0 |
| 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
</pre>
<p>Notice that the S7 (pin 11) changed from 0 to 1. It worked! Now, if I went through all the available signal pins S7-S3 one by one. These were my results.
<pre>
Nothing ground: 120D, 78H
| S7 | S6 | S5 | S4 | S3 | S2 | S1 | S0 |
| 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |

S7 ground: 248D, F8H
| S7 | S6 | S5 | S4 | S3 | S2 | S1 | S0 |
| 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |

S6 ground: 56D, 38H
| S7 | S6 | S5 | S4 | S3 | S2 | S1 | S0 |
| 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |

S5 ground: 88D, 58H
| S7 | S6 | S5 | S4 | S3 | S2 | S1 | S0 |
| 0 | 1 | 0 | 1 | 1 | 0 | 0 | 0 |

S4 ground: 104D, 68H
| S7 | S6 | S5 | S4 | S3 | S2 | S1 | S0 |
| 0 | 1 | 1 | 0 | 1 | 0 | 0 | 0 |

S3 ground: 112D, 70H
| S7 | S6 | S5 | S4 | S3 | S2 | S1 | S0 |
| 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
</pre>
<p>I know this was very long. But I hoped it helps. If you need the code, I’ll be happy to share. It’s in VB Express although. Email me at [email protected]

<p>Regards
 
Thank you for your input, I will consider it. I too have made some progress though I would certainly not say I have solved the riddle. You see I would like to use the data ports as opposed to the status ports as the inputs.

I have discovered that if you write decimal 0 to the port (ie set every bit low) and then write 1 to bit 5, this seems to "activate a read mode." With bit 5 set to 1 you can then read the status of the other bits... at least you can when you
use only a 5v power supply with no external circuitry. I attempted to connect this to an A to D converter and at this point I am unable to read anything.
 
If you are using win 95/98/98se try a web search for WIN95IO.DLL. This DLL is very easy to interface VB with your Paralell Port. BUT, it only works with the older versions of windows.
 
P
Did you make sure ur ADC supports VB? I know when I tried looking for one, I needed to make sure it supported VB platform; until I used the signal port for data acquisition. Oh, did remember to tie your grounds; this will insure that your external circuit is at the same level as your parallel port ground. (i'll also try your suggestion for the data port)

Thanks & Regards
 
Does my ADC support VB? Goodness, I don't know. Why would it have to? Surely as long as it outputs something like 5V, the parallel port should detect it. Surely there is no communication between VB and the ADC itself? All communication would be done between VB and the Parallel port would it not?

I tried Win95io but it wouldn't work for me as I am using windows XP.
 
P
Oh sorry, I thought you were using an isolated ADC with it's own cable connection. I didn't know that you were still using the parallel port.

Try my tutorial on www.codeproject.com; I don't know if it'll help you but you might get something out of it.

http://codeproject.com/useritems/Photodiode_Amplifier.asp
This 1st article, I used a relay switch and amplifer to boost my signal.

http://codeproject.com/useritems/Inpout32_read.asp
This 2nd article has been updated about access to parallel port via VB Express.

Hopes it helps
Regards
phebejtsov
 
J

Jason Bartlett

Do you import the dlls in the same way in VB Express as you did in the Excell Macro. I am also curious on what you think on VB Express.

Thanks
Jason
 
hi, thank you. I am from Mongolia. I am student. my english is poor. I am learning Visual basic. I need about "how to use network protocol in the visual basic". I want to do chat program of local area network.
 
It is important to note that you write a 1 to bit 5 (where bit #s are 7 6 5 4 3 2 1 0) of the CONTROL REGISTER (37Ah / 890), and then you can read the DATA REGISTER (378h / 888). A 1 at bit 5 is the decimal value 32.

I.E. using inpout32 in VB for Excel:
Out 890, 32
test = Inp(888)
 
The input pins at the PC parallel port work exactly opposite as that of the output pins...

i.e. output pins give a "HIGH" signal when active,
but input pins take a "LOW" signal when active.

All you need to do is to modify the input interfacing circuit...

The circuit should be such that it gives a "LOW" or "Ground" when an input is triggered to the input pins.
 
If I understand your question correctly, this may help... If you are trying to read the 5 input (status) lines, your address should be 889 not 888. 888 is used to send data out to the parallel port and 889 address is used to read the 5 status (input) lines. If you use 888 as your port address, you will only be able to read the status of what was sent to the output data lines not the 5 status (input) lines.

Dave S, EE
 
I was thinking of taking inputs from parallel ports and configuring it on the visual basic but i didn't find the way...Any help?
 
Top