-
Aug 15th, 2008, 07:15 AM
#1
Thread Starter
Addicted Member
[RESOLVED] how to on and off a relay using parallel port in vb6
how to turn on and off a relay connected on parallel port using vb6.
i created a relay kit, it has a one relay and a parallel port. i use number 2 pin for data and for the number 18 to 25 i use it for ground.
now my problem is how i can send data to turn on and off the relay through parallel port in vb6.. and i download the inpout.dll how do i use it
can anybody help me. and can any one have a sample code for this
thanks in advance
Last edited by acidsnake; Aug 15th, 2008 at 07:19 AM.
-
Aug 15th, 2008, 07:38 AM
#2
Re: how to on and off a relay using parallel port in vb6
I found this. Does it help?
-
Aug 15th, 2008, 07:45 AM
#3
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
 Originally Posted by Hack
I found this. Does it help?
yes it help. thanks. but i dont know where to start i program a lot but not electronics i program more on mis and database so im clueless about the communication between vb6,parallel port and a relay?
-
Aug 15th, 2008, 07:47 AM
#4
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
and how to send data using vb to parallel port to turn on or off a relay? please help
-
Aug 15th, 2008, 08:06 AM
#5
Re: how to on and off a relay using parallel port in vb6
google for InpOut32
you should find some examples of code and you need to download the dll file from whereever you can, i am sure it is free to download and use
you also would need to know the pin outs from the parrallel port to know which pins to change state, and if the type of relay you want to switch can be controlled by the pin voltages
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 15th, 2008, 09:05 AM
#6
-
Aug 16th, 2008, 04:05 AM
#7
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
there's a sample code that i can use as reference?
-
Aug 16th, 2008, 04:16 AM
#8
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
 Originally Posted by westconn1
google for InpOut32
you should find some examples of code and you need to download the dll file from whereever you can, i am sure it is free to download and use
you also would need to know the pin outs from the parrallel port to know which pins to change state, and if the type of relay you want to switch can be controlled by the pin voltages
i understand the pin outs now i use pin 2 as my data in and out and the relay switch has it's external voltage supply. my problem is how i can turn on or off the relay and what type of code that i use to send a data to pin 2 to turn on / off the realy switch?
for example i create commandbutton1
then 1 is on and 2 is off
i write the code like this
if commandbutton1 = 1 then (i dont know what next statement that i use to send a data to pin 2)
else
commandbutton1 = 2
( it must be turn it off) (i dont know what next statement that i use to send a data to pin 2)
please need help.
Last edited by acidsnake; Aug 16th, 2008 at 04:24 AM.
-
Aug 16th, 2008, 06:47 AM
#9
Re: how to on and off a relay using parallel port in vb6
http://www.codeproject.com/KB/vb/Inpout32_read.aspx
here is some stuff on switching pins on parallel port, but it is for vb dot net, although there is nothing much involved to converting to vb6, but you need to understand the binary to send to a single pin, pin 2 is data 0, i believe send "1" to switch on "0" to switch off to address of your printer port
i have no way to test this as my laptop has no printer (parallel) port
you would need to declare the functions for inp & out from the inpout32.dll file and download the file then your code in command button would be
out &H378, 1 to switch on (if i got it right)
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 16th, 2008, 07:57 AM
#10
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
 Originally Posted by westconn1
http://www.codeproject.com/KB/vb/Inpout32_read.aspx
here is some stuff on switching pins on parallel port, but it is for vb dot net, although there is nothing much involved to converting to vb6, but you need to understand the binary to send to a single pin, pin 2 is data 0, i believe send "1" to switch on "0" to switch off to address of your printer port
i have no way to test this as my laptop has no printer (parallel) port
you would need to declare the functions for inp & out from the inpout32.dll file and download the file then your code in command button would be
out &H378, 1 to switch on (if i got it right)
thanks i will try it
-
Aug 16th, 2008, 08:14 AM
#11
Re: how to on and off a relay using parallel port in vb6
If you decide to use the serial port instead then you can use this.
Code:
Option Explicit
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.PortOpen = True
MSComm1.DTREnable = False
End Sub
Private Sub Command1_Click()
MSComm1.DTREnable = Not MSComm1.DTREnable = True
End Sub
Last edited by CDRIVE; Aug 16th, 2008 at 08:19 AM.
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Aug 16th, 2008, 08:18 AM
#12
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
lets make it simple, can you teach me how to turn on and off the light led connected to LTP1 "parallel" port using vb6 command
-
Aug 16th, 2008, 08:20 AM
#13
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
what is better to use serial od parallel port?
-
Aug 16th, 2008, 08:23 AM
#14
Re: how to on and off a relay using parallel port in vb6
 Originally Posted by acidsnake
lets make it simple, can you teach me how to turn on and off the light led connected to LTP1 "parallel" port using vb6 command
I have no parallel port on this machine. The MSComm code I gave you is as simple as it gets. The Serial port was designed for this sort of thing. It's used thoughout industry for control.
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Aug 16th, 2008, 08:34 AM
#15
Re: how to on and off a relay using parallel port in vb6
 Originally Posted by acidsnake
what is better to use serial od parallel port?
There is no contest here. The Serial Port!
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Aug 16th, 2008, 08:35 AM
#16
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
another one how to declare inpout32.dll in module
-
Aug 16th, 2008, 08:44 AM
#17
Re: how to on and off a relay using parallel port in vb6
 Originally Posted by acidsnake
another one how to declare inpout32.dll in module
You don't need that dll when using MSComm. Just put a CommControl on your form and run the code I gave you.
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Aug 16th, 2008, 08:53 AM
#18
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
 Originally Posted by CDRIVE
You don't need that dll when using MSComm. Just put a CommControl on your form and run the code I gave you.
im still using a parallel port. coz it's already solderd to the board with relay im using D0 or pin 2 as data in and out and all grounds are solderd together.
-
Aug 16th, 2008, 05:38 PM
#19
Re: how to on and off a relay using parallel port in vb6
have you downloaded the inpout32.dll?
when you get that there is simple sample project that shows how to declare the functions in the dll and call the functions, you can put the declarations either in the form or a module
but here they are to save you looking
vb Code:
'Inp and Out declarations for port I/O using inpout32.dll. 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)
make sure the dll file is copied into windows\system32 or in the same folder as the project
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 17th, 2008, 04:03 AM
#20
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
 Originally Posted by westconn1
have you downloaded the inpout32.dll?
when you get that there is simple sample project that shows how to declare the functions in the dll and call the functions, you can put the declarations either in the form or a module
but here they are to save you looking
vb Code:
'Inp and Out declarations for port I/O using inpout32.dll.
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)
make sure the dll file is copied into windows\system32 or in the same folder as the project
yes i download the inpout32.dll and i declare it in the module. now i create a textbox to show the status of the pin and command button to send 0 or 1 to turn the pin on and off. can you help me with the textbox and command button? please thanks in advance
-
Aug 17th, 2008, 05:53 AM
#21
Re: how to on and off a relay using parallel port in vb6
try like this, but i haven't tested at all
vb Code:
retval = inp &H378 ' should read all data pins if (retval and 1 ) = 1 then ' data 0 on out &H378, retval - 1 ' off data 0, but leave other pins n same state if (retval and 1) = 1 then text1.text = "not connected" else out &H378, retval +1 ' on data 0 if (retval and 1) = 1 then text1.text = "connected" end if
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 17th, 2008, 07:47 AM
#22
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
 Originally Posted by westconn1
try like this, but i haven't tested at all
vb Code:
retval = inp &H378 ' should read all data pins
if (retval and 1 ) = 1 then ' data 0 on
out &H378, retval - 1 ' off data 0, but leave other pins n same state
if (retval and 1) = 1 then text1.text = "not connected"
else
out &H378, retval +1 ' on data 0
if (retval and 1) = 1 then text1.text = "connected"
end if
ok i will try it. thanks
-
Aug 17th, 2008, 07:59 AM
#23
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
 Originally Posted by westconn1
try like this, but i haven't tested at all
vb Code:
retval = inp &H378 ' should read all data pins
if (retval and 1 ) = 1 then ' data 0 on
out &H378, retval - 1 ' off data 0, but leave other pins n same state
if (retval and 1) = 1 then text1.text = "not connected"
else
out &H378, retval +1 ' on data 0
if (retval and 1) = 1 then text1.text = "connected"
end if
can i dim the retval as integer?
-
Aug 17th, 2008, 04:18 PM
#24
Re: how to on and off a relay using parallel port in vb6
yes, it will always return a value between 0 and 255
check your printer port address is 378 (default printer port address) or change the code to suit
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 21st, 2008, 04:00 AM
#25
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
 Originally Posted by westconn1
yes, it will always return a value between 0 and 255
check your printer port address is 378 (default printer port address) or change the code to suit
your coding is work but im confuse with this line
if (retval and 1) = 1
the retval is the address port, what's with 1 inside open and close parenthesis?
and what is the = 1 value?
can you brief me about this 1.
thanks in advance
-
Aug 21st, 2008, 04:12 AM
#26
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
other one question how can i read the status from inp &H378 form a textbox?
-
Aug 21st, 2008, 07:51 AM
#27
Re: how to on and off a relay using parallel port in vb6
there are 8 data bits on port H38
data 0 is bit 0 sending 1 to the port turns data0 on
data 1 is bit 1 sending 2 to the port turns data1 on
data 2 is bit 2 sending 4 to the port turns data2 on
data 3 is bit 3 sending 8 to the port turns data3 on
data 4 is bit 4 sending 16 to the port turns data4 on
data 5 is bit 5 sending 32 to the port turns data5 on
data 6 is bit 6 sending 64 to the port turns data6 on
data 7 is bit 7 sending 128 to the port turns data7 on
total of 8 bits
the values can be added together to turn on a multiple of bits
sending max value of 255 turns all data bits on
when you read the ports it returns the state of all the databits in a value between 0 (all off) and 255 (all on)
if (retval and 1) = 1
compare the bits of the value read from the port to 1 = true or false
to work with all the data bits (8 relays) you would have to use more sophisticated code to switch, the correct relay without switching off others, the normal way to do this is to 2 to the power of bit no
bit 0 2^0 to
bit 7 2^7
this makes it much easier to pass varaibles as values to the port
my code on line 7 should have read
if (retval and 1) = 0 then text1.text = "connected"
to read the status into the textbox, depends what you want to display
text1.text = inp &H378
will display a value between 0 and 255, which is the state of all data bits
the code i posted (error apart) shows connected on not on data 0
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 21st, 2008, 08:17 AM
#28
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
thank you for all the time and support to build this program.. and test this code in a light led to check if the code is working thanks to westconn1 greate job. now i can turn on and off the lead light and build a new one for the relay to apply this code thanks..
-
Aug 21st, 2008, 09:05 AM
#29
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
 Originally Posted by westconn1
there are 8 data bits on port H38
data 0 is bit 0 sending 1 to the port turns data0 on
data 1 is bit 1 sending 2 to the port turns data1 on
data 2 is bit 2 sending 4 to the port turns data2 on
data 3 is bit 3 sending 8 to the port turns data3 on
data 4 is bit 4 sending 16 to the port turns data4 on
data 5 is bit 5 sending 32 to the port turns data5 on
data 6 is bit 6 sending 64 to the port turns data6 on
data 7 is bit 7 sending 128 to the port turns data7 on
total of 8 bits
the values can be added together to turn on a multiple of bits
sending max value of 255 turns all data bits on
when you read the ports it returns the state of all the databits in a value between 0 (all off) and 255 (all on)
if (retval and 1) = 1
compare the bits of the value read from the port to 1 = true or false
to work with all the data bits (8 relays) you would have to use more sophisticated code to switch, the correct relay without switching off others, the normal way to do this is to 2 to the power of bit no
bit 0 2^0 to
bit 7 2^7
this makes it much easier to pass varaibles as values to the port
my code on line 7 should have read
if (retval and 1) = 0 then text1.text = "connected"
to read the status into the textbox, depends what you want to display
text1.text = inp &H378
will display a value between 0 and 255, which is the state of all data bits
the code i posted (error apart) shows connected on not on data 0
where i put the 1 to send a 2? like this
if (retval and 1) = 2 then
out &h378, retval -2 'to off the data1 and to return value to 0
else
out&h378, retval + 2 ' to on the data1?
-
Aug 21st, 2008, 04:38 PM
#30
Re: how to on and off a relay using parallel port in vb6
only retval + or - 1 (2^0) to switch on and off data 0
retval + or - 2 (2^1) will switch data 1, to
retval + or - 128 (2^7) will switch data 7
retval = 0 switch all data bits off
retval = (2^0) + (2^5) will set data0 and data 5 on and switch off all others
to find if data 1 on already
if (retval and 2) = 2 then
do some searches on bitwise comparisons (AND / OR) for comparing binary values, to get a better understanding of how this works, and what the return from either should be
have another look at the code project link i posted in #9, as even though it is for dot net, it explains some of the logic, which is the same any way,
i have seen some explanations for comparing binary values in this forum too, so a search here should produce some results
Last edited by westconn1; Aug 21st, 2008 at 04:45 PM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 29th, 2008, 04:51 AM
#31
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
one last question? how can i put a timer to send data to pin2 and pin3
example: if 1min equals timer then the timer send data to pin2 to turn it on, when it's 2min then the timer send data to pin3 to on it and turn off the pin2. thanks in advance
-
Aug 29th, 2008, 04:58 AM
#32
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
by the way thanks to westconn1 and to all who help me to build this project thanks.
-
Aug 29th, 2008, 05:15 AM
#33
Re: how to on and off a relay using parallel port in vb6
there are several methods to do this with a timer, but something like
vb Code:
if (retval and (2^2)) = (2^2) then ' if data2 on out &H378 , retval - (2^2) + (2^3) 'data2 off data3 on else out &h378, retval + (2^2) - (2^3) ' data 2 on, data3 off end if
this will alternate data2 and data3 each time the timer fires
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Sep 1st, 2008, 01:10 AM
#34
Thread Starter
Addicted Member
Re: how to on and off a relay using parallel port in vb6
ok thanks for the code i will try it.
-
Nov 12th, 2009, 01:05 PM
#35
Junior Member
Re: [RESOLVED] how to on and off a relay using parallel port in vb6
 Originally Posted by acidsnake
how to turn on and off a relay connected on parallel port using vb6.
i created a relay kit, it has a one relay and a parallel port. i use number 2 pin for data and for the number 18 to 25 i use it for ground.
now my problem is how i can send data to turn on and off the relay through parallel port in vb6.. and i download the inpout.dll how do i use it
can anybody help me. and can any one have a sample code for this
thanks in advance
acidsnake - did you get your problem resolved?
I am having the same trouble with inpout32.dll - it was supplied with the parallel port controlled relay board I purchased from robotkitworld in India. Their vb6 interface code reference the legacy port (H378). I can change and recompile the vb6 code, but I don't know how to make the dll see that change.
tx ftbrady
-
Nov 12th, 2009, 03:06 PM
#36
Re: [RESOLVED] how to on and off a relay using parallel port in vb6
is your board connected to lpt1: ?
if not change the port number for the calls to the dll
retval = inp(&h278)
for lpt2 and i think, 3bc for lpt3:
any other lpt port would be a custom address
the dll does not have to see the changes to your code, it only sees the information you send to it
what code do you have now and what is the problem with it?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 12th, 2009, 05:09 PM
#37
Junior Member
Re: [RESOLVED] how to on and off a relay using parallel port in vb6
Thank you
I misinterpreted the vb6 examples for my inpout.dll.
Now I understand - the inp and out calls define the port address.
Thanks for making me think.
I now have all the pieces I need for my parallel port relay driver project.
ftbrady
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|