Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Interfacing LPT1 with VB6

Status
Not open for further replies.

pablome

New Member
I found already 2 sites that explain some about Parralel Port interfacing using VB in windows and are yet to understand it all. These sites are:

**broken link removed** & http://www.geocities.com/adeebraza/new/art.html & http://electrosofts.com/parallel/parallelwin.html

I have hardware that will test a Logic Low to pin 10 of LPT1 and show that in a VB program which will than tell another VB program already developed to tell its code through serial port to stop the robot arm at that instant.

I was wondering if there is a program already made or how to I developed one in VB to read from PIN 10 of LPT1 and tell that to another already made VB program.
 
What version of windows are you using? If it is 98 and under, then you can just simply use "out" statements. On the otherhand if you are using an NT OS (NT, ME, 2K, XP, VISTA), then you must have a DLL called inpout32.dll. Just google for it.

Also, do you understand how binary works? If i remember correctly, pin 10 is an input on the status lines, so you would just use the following code (which is pseudocode, because i can't remember the VB6 input command...) "/*" denotes a comment. :)

Code:
dim val as integer
dim base as integer     /* This is the base address of the parallel port, normaly
                        /* &H278, &H378, or even &H3BC
dim stat as integer = base + 1 /*status registor (or your location for the pin) is base + 1

let x = inp(stat)         /* lets x = the value of the status port

Now, "X" must be decoded. Pin 10's status is the seventh bit, so you must convert "X" into binary, and then pull out the 7th bit, which will tell you if input 10 is high or low.




I would have gone more into depth, but my wireless keyboard is acting up... :confused:
Let me know if you need more help! ;)
 
Last edited:
Ok, then. That just adds a little bit of a curve ball then... :D

Since i use VB.NET, i am just guessing what VB6 code looks like (i have used VB6, but only for about a total of 2-3 hours)

Download the zip i have attached, and extract the inpout32.dll to your "C:\windows\system32\" directory.

Now, paste the following code right into your program (at the very top).

Code:
Declare Function Inp _
                Lib "inpout32.dll" _
                Alias "Inp32" _
                (ByVal PortAddress As Integer) As Integer

Declare Sub Out _
                Lib "inpout32.dll" _
                Alias "Out32" _
                (ByVal PortAddress As Integer, ByVal Value As Integer)


Now, like i said before, dim a variable for your base port, as well as for your status line. The following example assumes you have a textbox named textbox1 on the form.

Code:
public const base = &h278    'This is the base address of the parallel port, normaly &H278, &H378, or even &H3BC
public const status = base + 1 'status registor (or your location for the pin) is base + 1

textbox1.text = inp(status)


Now, i will leave the decimal to binary conversion to you. This function may help; https://www.devx.com/vb2themax/Tip/18958 I am too lazy to try it... :D


Ok, let's say that once you convert the status line into binary, you get 0100100. Since there is a "1" in the 7th bit spot, then pin 10 is high.

if the number is 00001110, then bit 7 is 0, which means pin 10 is high.



I have to go eat supper now, so let me know if more help is needed. If so, i will pull out my laptop with vb on it, and actually write some of my own code if you would like.
 

Attachments

  • Inpout32.zip
    11.7 KB · Views: 715
Ok thanks alot. Will try what you posted when I get to work, maybe not right now but tomorrow. Maybe youll be on to see if I have any further questions.

I have looked at some projects/sites/tutorials about this with interfacing parallel port in windows and actual programs that do this. ie read or write to it using vb or vc++.
I am a student and have knowledge of electronics/electrical some programing so hopefully I can get this to work.
This is basicaly an addition to a project that an engineer is already doing for a robot arm thats automated from a system that has Win XP and VB or something that send code through serial port to the ARM and I am suspoed to add a VB program to implement to the one already built I think that controls the ARM(seperate programs on same system than but will comunicate somehow between eachother). When an infrared beam is interfered(which surounds the robo arm), the arm will have to automaticaly stop for that duration and we're using LPT1 and pin 10 ackn. pin to read that state that the infrared beam has been interupted. As of now I just have SW circuit to implement the pin 10 status to test the program and hardware will later be implemented when all is ready. But program interaction has to be done first offcourse. Getting the time critical (no more than 1 sec. delay lets say) status of pin 10 of LPT1.
 
Last edited:
I should be home all day tomorrow, so i will be here (no, i dont' have a life... :D). I am not sure how to make programs interact with each other, so you may have to do some searching on that... I would like to know if you find out. ;)
 
Quick question... should I assign IRQ to LPT1, or does that complicate anything? Under windows you can tell it to assign and IRQ7 automatically or non at all.
 
Quick question... should I assign IRQ to LPT1, or does that complicate anything? Under windows you can tell it to assign and IRQ7 automatically or non at all.

No. I don't have an IRQ assigned for mine.


378...thats in hex I assuming.

Yes, it is. That is 888 in decimal. ;)
 
Im not sure how to use that

"' convert from decimal to binary
' if you pass the Digits argument, the result is truncated
' to that number of digits
'
' NOTE: requires Power2()

Function Bin(ByVal value As Long, Optional digits As Long = -1) As String
Dim result As String, exponent As Integer
' this is faster than creating the string by appending chars
result = String$(32, "0")
Do
If value And Power2(exponent) Then
' we found a bit that is set, clear it
Mid$(result, 32 - exponent, 1) = "1"
value = value Xor Power2(exponent)
End If
exponent = exponent + 1
Loop While value
If digits < 0 Then
' trim non significant digits, if digits was omitted or negative
Bin = Mid$(result, 33 - exponent)
Else
' else trim to the requested number of digits
Bin = Right$(result, digits)
End If
End Function"
 
hi pablome,
Try this, make sure you have inpout32.dll in your Windows/System directory.

Code:
'******* VB5 prog Read Status of Parallel Port Pin #10 ***********

'1...place a Command button on the Form

'2...Dll paste this code into a Module
'''''''''''''''''''''''''''''''
 'Public Declare Function Inp Lib "DllPort.dll" _
 'Alias "Inp32" (ByVal PortAddress As Integer) As Integer

 'Public Declare Sub Out Lib "DllPort.dll" _
 'Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
''''''''''''''''''''''''''''

'Program.................

Option Explicit

Dim Pin10 As Integer

'Printer port LPT1 addresses
Const Data = &H378, Status = &H379, Sync = &H37A

Private Sub Form_Load()

Form1.Show

End Sub

Private Sub Command1_Click()
MyRead
End Sub

Private Sub MyRead()
     
        Pin10 = Inp(Status) And 64 ' pin #10

        If Pin10 = 64 Then
        'do whatever if pin10 is high
        Print "pin10 is high"
      Else
        'do whatever if pin10 is low
        Print "pin10 is low"
        End If
            

End Sub
 
Ok thanks ILL TRY IT. I found other sites/programs sorta that already try to read or something from LPT1 and not sure but I can look at their work, some do though give errors. Id show you where I get them but now sure/remember the links.
 
pablome said:
Compile error: Argument no optional:

(status) is balded in " Pin10 = Inp(Status) And 64 ' pin #10 "

Hi,
I am using VB5 for the program, it runs without errors in the design environment and as a compiled exe??
Other users have not experienced this problem when using the program.

Unless there is some difference in VB net, I cannot explain the error at this time.
Is the expression 'balded' a VB net term, I am not familiar with that error.

Did you you remove the 'rems'... single quotes, from the code that you had to paste into a Module???
Also do you have 'input32.dll' in your Windows/System, I would appreciate a reply as I dont like unexplained errors.

Regards
 
Last edited:
I'll try to redo or check what I did wrong.
I should have inpout32.dll in both the program directory and windows system32 folder. I think its registered/installed correctly.
I am using VB6 on WinXP pro.
Iv tried other programs too as mentioned earlier and they dos ometimes work with exception of dll errors or i just get a reading of 120 in one program even though I have a circuit hooked up to the parallel cable that suposed to changed status of pin10. Another program also actualy doess see FF or 4 hen I toggle the switch for pin 10. But someone else has made these VB programs and dll file etc. Not me and woudnt be sure how to implement them for my needs.
If you'd like I can try to find a way for you to download them from and try them on your VB environment, see what they did and compare or modify it for personal understanding.
Again thanks though for the support. I want to try to get the program going soon by today, thatd be great. Hope this stuff works :)
 
ericgibbs said:
Hi,


Unless there is some difference in VB net, I cannot explain the error at this time.
Is the expression 'balded' a VB net term, I am not familiar with that error.

Regards

No sorry,when i mean its bolded, its because thats wat causing it, the actual error message is "Compile error: Argument not optional"
 
pablome said:
No sorry,when i mean its bolded, its because thats wat causing it, the actual error message is "Compile error: Argument not optional"
Hi,
I dont have VB6, but I am just wondering whether the VB6 compiler is unhappy with word 'Status'... it maybe a reserved token.:confused:
The program has been used many times without problems.

Try changing all the word 'Status' to say, 'PortRead' through out the program listing. Lets know what you find.

EDIT:
I also found this that someone made but I get errors.
**broken link removed**

Hi,
I have just tried your program in VB5 it works fine, toggles the Port OK.
Is it possible your VB6 is suspect??

Eric
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top