Need help programming.

Supporting Visual Studio on Windows
kjetilhansen

Need help programming.

Postby kjetilhansen » Thu Oct 07, 2010 3:26 pm

Hi all.

I have a small problem...

I tryed to read, but i am way to new at this to understand it.
I am trying to rebuild the Interfacekit-full but no luck.. I have no idea what the heck im doing.

So i am woundering, could somone that understand this code, please help me make my .exe file? I think it is pretty easy for the people that knows what they are doing...

What i need is simpy, click an .exe file, and the window pops up whit 3 buttons, "up" "down" and "stop"... When you press Up one of the 16 outputs gets active, and stays active untill there is a signal to one of the 16 inputs... And Down is the same, but just vica verca... Stop will release the active output.

Is this hard to do? I have no idea... If anyone can do this for me, i can pay you, just give me an paypal acc :)

Thank you :)

Gunzedreng
Phidgetly
Posts: 33
Joined: Wed Apr 28, 2010 2:07 pm
Location: Denmark
Contact:

Re: Need help programming.

Postby Gunzedreng » Fri Oct 08, 2010 7:55 am

Hi,

I can tell you what I usually do... In short, add phidgetslibrary as reference -> write code etc -> and then just build it.... when building it visual studio creates a .exe file in the release folder in the project folder.

run that and it will work, especially when there isn't that much code in your project....

1.step
goto menu -> Project -> Add reference (need the phidget 21 installer!)
if you can't find the phidget library under the tab .NET just browse to it under C:\program files\phidgets.....etc find the Phidget21.NET1.1.dll file.

2.step
Ontop of your class in the code import the library code:
Imports Phidgets
Then add the the interface with this code in you class code:
Dim WithEvents IFK1616 as Phidgets.InterfaceKit

3.step
When double clicking your form a form1_load procedure is created and in that you'll have to add this code:
IFK1616 = New Phidgets.InterfaceKit
IFK1616.open() 'if you have several phidgets connected then IFK1616.open(serialnumber)

Next you can select the IFK1616 from the dropdown just under the tabs for Form1.vb | Form1.vb [Design] | etc
and then select the OutputChange and InputChange from the dropdown on the right.

this will create 2 new procedures in you code where you can add code to what should happen when an input is changed and output is changed.

good idea is to make a select case to attach code to a specific output index or input index.

Select case e.index
case 0
'code e.value = true or false (1 or 0)
case 1
'code
etc.......... up to case 15 cause there are 16 inputs and outputs


4.step 'The buttons
In the button click event add code and for turning an output on/off
you'll need to add something like this:
IFK1616.outputs(0) = true '(or false) 0 is the index og the output

checking if input is true or false just add if statement:
if IFK1616.inputs(3) = True Then
'code here
End If

5.step 'optional
add the procedure Form1_FormClosing... then add:
IFK1616.close()

Hope this can help. I wrote as if your a beginner so please if youre not... Sorry... :)
mail me if I can be of further help: gunnarturbo@hotmail.com

Gunze

kjetilhansen

Re: Need help programming.

Postby kjetilhansen » Fri Oct 08, 2010 3:15 pm

Thank you so much!
I did all the things you said, and now i made a button and when i press it, one output turns green. I dont know how to get an input to turn it of, but i will try reading around while i wait for an reply.


And btw, what an exelent feeling when i pushed the button and the led turned green :)



EDIT:

Okay, made a button that i manage to turn the output off whit. (again an extraordinary feeling)

BUT; How do i get it to turn itself off when it detects somthing on input 0?

erik
King of the Lab
Posts: 476
Joined: Fri Mar 06, 2009 12:42 pm
Location: Calgary, Canada
Contact:

Re: Need help programming.

Postby erik » Fri Oct 08, 2010 3:55 pm

some code similar to

Code: Select all

If ( IFKIT1616.inputs(0).Value == true ) Then
{
     IFKIT1616.outputs(0).Enabled == false;
}
End If

inside the InputChange event

Gunzedreng
Phidgetly
Posts: 33
Joined: Wed Apr 28, 2010 2:07 pm
Location: Denmark
Contact:

Re: Need help programming.

Postby Gunzedreng » Fri Oct 08, 2010 4:07 pm

Hi

That's just great :) and I know what you mean by pressing a button on-screen and led turns on.... Great feeling

And to your question.

BUT; How do i get it to turn itself off when it detects somthing on input 0?

Go with Erik's solution... couldn't be better
the VB.NET code:

If IFK1616.inputs(0).value = True Then
IFK1616.outputs(0) = false
End If


Glad I could help

kjetilhansen

Re: Need help programming.

Postby kjetilhansen » Fri Oct 08, 2010 4:16 pm

How exacly does his solution work..? My code so far;

Code: Select all

Imports Phidgets
Public Class lerretstyring
    Dim WithEvents IFK1616 As Phidgets.InterfaceKit


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        IFK1616 = New Phidgets.InterfaceKit
        IFK1616.open()
    End Sub

    Private Sub IFK1616_InputChange(ByVal sender As Object, ByVal e As Phidgets.Events.InputChangeEventArgs) Handles IFK1616.InputChange
        Select Case e.Index
            Case 0
                'code e.value = true or false (1 or 0)
            Case 1
                'code e.value = true or false (1 or 0)
            Case 2
                'code e.value = true or false (1 or 0)
        End Select
    End Sub

    Private Sub IFK1616_OutputChange(ByVal sender As Object, ByVal e As Phidgets.Events.OutputChangeEventArgs) Handles IFK1616.OutputChange
        Select Case e.Index
            Case 0
                'code e.value = true or false (1 or 0)
            Case 1
                'code e.value = true or false (1 or 0)
            Case 2
                'code e.value = true or false (1 or 0)
        End Select
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        IFK1616.outputs(1) = True '(or false) 0
        If IFK1616.inputs(3) = True Then
        End If
        IFK1616.outputs(2) = False '(or true) 0
        If IFK1616.inputs(3) = False Then
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        IFK1616.outputs(1) = False '(or true) 0
        If IFK1616.inputs(3) = False Then
        End If
        IFK1616.outputs(2) = False '(or true) 0
        If IFK1616.inputs(3) = False Then
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        IFK1616.outputs(2) = True '(or false) 0
        If IFK1616.inputs(3) = True Then
        End If
        IFK1616.outputs(1) = False '(or true) 0
        If IFK1616.inputs(3) = False Then
        End If
    End Sub

    Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar1.Click

    End Sub
End Class





Where does i paste his code? And how do i get the progressBar1 to work? I guess after what i learned today, i have to use ProgressBar1.Click command, but how do i get that to show progress while the thing is running, and if i get an example on that i guess i can manage to get it to stop... :)
This is fun :p

Cerwell
Phidgeteer!
Posts: 58
Joined: Wed Nov 26, 2008 3:52 pm
Location: Norway (East)

Re: Need help programming.

Postby Cerwell » Sat Oct 09, 2010 3:20 am

Hei Kjetil!

Use the code suggested:
Gunzedreng wrote:Hi

......Go with Erik's solution... couldn't be better
the VB.NET code:

If IFK1616.inputs(0).value = True Then
IFK1616.outputs(0) = false
End If


..and place it inside a the InputChange event (Select from your dropdown menu) .
When a input is received on '0' it will close output '0'.

Gunzedreng
Phidgetly
Posts: 33
Joined: Wed Apr 28, 2010 2:07 pm
Location: Denmark
Contact:

Re: Need help programming.

Postby Gunzedreng » Sat Oct 09, 2010 4:38 am

Hi again,

well this is how your inputChange event should look like

Code: Select all

Private Sub IFK1616_InputChange(ByVal sender As Object, ByVal e As Phidgets.Events.InputChangeEventArgs) Handles IFK1616.InputChange
        If e.index = 0 Then
           If e.value = True Then
              IFK1616.outputs(0) = False
           End If
        End If
End Sub


Or could do it like this

Code: Select all

Private Sub IFK1616_InputChange(ByVal sender As Object, ByVal e As Phidgets.Events.InputChangeEventArgs) Handles IFK1616.InputChange
        If IFK1616.inputs(0) = True Then
           IFK1616.outputs(0) = False
        End If
End Sub


Or if you can't get those working :) this is alsow an option

Code: Select all

Private Sub IFK1616_InputChange(ByVal sender As Object, ByVal e As Phidgets.Events.InputChangeEventArgs) Handles IFK1616.InputChange
        Select Case e.index
           Case 0
              If e.value = True Then
                IFK1616.outputs(0) = False
              End If
           Case 1
              If e.value = True Then
                IFK1616.outputs(1) = False
              End If
           Case 2
              If e.value = True Then
                IFK1616.outputs(2) = False
              End If
        End Select
End Sub


Hope this will help... the case's can continue up to "Case 15"

And the thing with the progressbar, well nothing else to say you need to explain your idea/problem better for me to understand your intentions.

And your Button_click events have a slight issue with the if statements as they have no purpose.... :)

Code: Select all

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        IFK1616.outputs(2) = True 'Turns Output 2 ON
        If IFK1616.inputs(3) = True Then
          'if input 3 is ON then here is where the code executes
        End If
        IFK1616.outputs(1) = False 'Turns Output 1 OFF
End Sub


Good Weekend

kjetilhansen

Re: Need help programming.

Postby kjetilhansen » Sun Oct 10, 2010 7:52 am

The last one worked almost perfectly :)
But when i use the

Code: Select all

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If IFK1616.inputs(0) = True Then
            IFK1616.outputs(1) = False
        End If
        IFK1616.outputs(1) = True '(or true) 0
        If IFK1616.inputs(1) = False Then
        End If
        IFK1616.outputs(2) = False '(or true) 0
        If IFK1616.inputs(3) = False Then
        End If
    End Sub


But when i use the stop switch on input 0, and try to start the "motor" the light on the phidgets card flashes... It cant turn on since the input is true, but it still tries, and succseed for an fracture of a second... but the motor will still drive, so it will alwas if you hit the wrong button try do drive itself further away from the last stop switch...

And one more thing, I am googleing as a mad man here, but how do you get an timer? The story whit this is at my livingroom i have made an electric canvas, and a projector, so to make it better, i would like it to when i press a start button, there will be a sequens that starts the motor in the canvas, driving that down, a few seconds after it starts, the projector turns on, and the light turns off... But all google hits i get on visual basic timer i have no idea how to use, it is all wrong from my purpose i guess...

Thanks for alot of help guys :)

Gunzedreng
Phidgetly
Posts: 33
Joined: Wed Apr 28, 2010 2:07 pm
Location: Denmark
Contact:

Re: Need help programming.

Postby Gunzedreng » Sun Oct 10, 2010 10:15 am

Hi,

The reason why the light flashes is because when you press your button:

Code: Select all

        If IFK1616.inputs(0) = True Then
            IFK1616.outputs(1) = False
        End If
        IFK1616.outputs(1) = True '(or true) 0
        If IFK1616.inputs(1) = False Then
        End If


Look at your code.... understand it....

First: If input 0 is True then turn output 1 OFF

Code: Select all

If IFK1616.inputs(0) = True Then
   IFK1616.outputs(1) = False
End If


secondly: Turn ON output 1...

Code: Select all

IFK1616.outputs(1) = True '(or true) 0

Third: If input 1 is False Then ---- Do Nothing ??? (Why an if there!)

Code: Select all

If IFK1616.inputs(1) = False Then
End If


If this won't help explain to me in Steps what you want to happen when pressing that Button.. :)

As for your timer... well when your in the designer view (where you see your windows Form) Open the toolbox and scroll down and drag and drop the Timer control onto your form. When Done! you see the timer was created on the bottom in Visual studio... click it and goto properties and select the desired interval (in milliseconds 1000 = 1sec)
set enabled to false.... this is default

Next Double click on the timer on the bottom and you should be directed to the code with a Timer_Tick event.... Know in this event you can write code that executes every time the Interval has run... meaning your entered milliseconds.

Now as for your sequence what I usually do is make a button to start the timer.

Code: Select all

Timer1.enabled = true

Before writing code to your timer make a integer variable just under you class... (Making a class/global variable)

Code: Select all

Dim Count as Integer = 1


In your timer tick event enter something like this.

Code: Select all

Select Case Count
  Case 1
    'Start the motor
  Case 2
    'Turn Projector ON
  Case 3
    'Turn Off Lights
    Timer1.Enabled = False
    Count = 0
End Select
Count += 1


Understand that and you can do any sequence you Like :)

Explanation: (If you entered 5000 in the timer interval) When you press button to start timer, there will pass 5 seconds, then case 1 will execute as variable Count = 1, turning motor ON... Count += 1 adds a 1 to the count making it 2. 5seconds will pass and Case 2 executes turning projector ON. Again adding a 1 to Count making it 3 (2 + 1 = 3)... 5 Seconds pass and Case 3 executes turning lights off, also turning OFF timer and resetting Count variable to 0 as 0 + 1 = 1

Hope this helps.... You will have to add code for turning on motor and projector aswell as turning lights off.,

Gunze


Return to “VB .NET”

Who is online

Users browsing this forum: No registered users and 0 guests