Question parallel port And relay control

spookyman60

New member
Joined
Oct 26, 2009
Messages
3
Programming Experience
Beginner
hi guys/gals im new around here and also to VB.NET infact any aspect of programming, im hoping to be able to some useful stuff but at the momment im a little stuck i only have basic knoweldge so anyway here goes

im programming in VB.NET 2008 Express edition, im also using inpout32.dll which is running ok and also controlling the parallel port fine.
the problem i have is as follows the program so far is controlling the 8 outputs at the momment, i can turn each individual one on but when i try to turn multiple outputs on it will only turn on one and the other that was turned on goes off i understand its controlled in a 255 bit array but how to decode it is a little tough

p.s im sorry if this is in the wrong section thanks in advance for the help spook
 
I expect the answer is easy, but can you please post some of the code you are using so we can give a precise answer :)
 
VB.NET:
    Private Sub Test_InpOutt32_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        PortAddress = &H378S
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label1.Text = 1
        Out(PortAddress, 2)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Label2.Text = 1
        Out(PortAddress, 4)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Label3.Text = 1
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Label1.Text = 0
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Label2.Text = 0
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Label3.Text = 0
    End Sub
End Class

im still learning so i hope this helps you help me
 
As expected, everytime you send something like :-

VB.NET:
Out(PortAddress, 2)

although you are turning one output on, you are also turning all the other outputs off. You need to think in binary. So, for example, you have two lines :-

VB.NET:
Out(PortAddress, 2)
Out(PortAddress, 4)

If you want to have both of these on, you need to add the 2 and 4 together and actually send

VB.NET:
Out(PortAddress, 6)

Your best bet would be to use a integer variable to store the outputs required. So, for example :-

VB.NET:
Public OutputsRequired as Integer = 0

and then change your code to be something like :-

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        OutputsRequired = OutputsRequired Xor 2
        Out(PortAddress, OutputsRequired)
    End Sub

XOR will turn the relevant output on and off as required.
 
hi thanks for the help so far but i am still not sure how integer work and how it would work can you break it down a bit more thanks
 
Output 1 = 1
Output 2 = 2
Output 3 = 4
Output 4 = 8
Output 5 = 16
Output 6 = 32
Output 7 = 64
Output 8 = 128

So Outputs 1 and 4 = 1 + 8 = 9

So if you send 9, you will get outputs 1 and 8 on :D
 
Back
Top