Not attached programming

Supporting Visual Studio on Windows
blackjack102

Not attached programming

Postby blackjack102 » Tue Oct 27, 2009 9:11 pm

I use three stepper motors and three phidgetstepper bipolar chips. I wrote a software in visual studio 2005, basic net. It can run the positions repeatly, and I had to use thread to make possible to run all three motors at the same time. The software requests the information from the chips million times; however, it crashes when an error message appears EPHIDGET_NOTATTACHED at runtime. When I debugged the program and found that it crashes at any requesting instruction from the chip randomly.

I am not sure what is the end problem. Is it loose cable? or programming?

Thanks

User avatar
Patrick
Lead Developer
Posts: 3078
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Not attached programming

Postby Patrick » Wed Oct 28, 2009 10:14 am

Are you trying to access the board right after calling open, without first calling waitForAttachment or waiting for the attach event to fire?

-Patrick

blackjack102

Re: Not attached programming

Postby blackjack102 » Wed Oct 28, 2009 3:33 pm

I can access the boards after the open, and they fire the events smoothly. After 1 to 5 minutes of running program, one of three boards just detaches and could not reattach. When it detaches, I call the waitforattachment. It waits forever as it will not reattach. Or the program will crash after the detachment. I decided to open phidget control panel or manager, and I found that it could attach the detached board but not another boards. You could check out the picture and code. I tried to rewrite some codes and got same result. See New and old codes below

Picture

I am not sure if the codes could be helpful

Code: Select all


Wheel = New Phidgets.Stepper
Wheel.open()

Private Sub Wheel_Detach(ByVal sender As Object, ByVal e As Phidgets.Events.DetachEventArgs) Handles Wheel.Detach
        MessageBox.Show("Wheel detaches")
        'Wheel.waitForAttachment(0)
    End Sub


'********* OLD CODE **********
   Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        If Wheel.Attached Then
            Try
                If Not IsWheelDone And Wheel.steppers(0).CurrentPosition = WheelPos(WheelIndex) Then
                    WheelIndex += 1
                    If WheelIndex >= 10 Then
                        Timer1.Enabled = False
                        IsWheelDone = True
                    Else
                        Wheel.steppers(0).TargetPosition = WheelPos(WheelIndex)
                        Wheel.steppers(0).VelocityLimit = WheelVel(WheelIndex)
                    End If
                End If

            Catch ex As Exception
                MessageBox.Show(ex.Message, "Wheel Tick")
            End Try
        End If
    End Sub


'********* NEW CODE **********     
Private Sub Wheel_PositionChange(ByVal sender As Object, ByVal e As Phidgets.Events.StepperPositionChangeEventArgs) Handles Wheel.PositionChange
        WheCurPosDis.Text = Wheel.steppers(0).CurrentPosition.ToString

        If IsRun And Not IsWheelDone And Wheel.steppers(0).CurrentPosition = WheelPos(WheelIndex) Then
            WheelIndex += 1
            If WheelIndex >= 10 Then
                IsWheelDone = True
            Else
                Wheel.steppers(0).TargetPosition = WheelPos(WheelIndex)
                Wheel.steppers(0).VelocityLimit = WheelVel(WheelIndex)
            End If
        End If
    End Sub


Thanks

blackjack102

Re: Not attached programming

Postby blackjack102 » Fri Oct 30, 2009 8:19 am

I still have issue with detach on my laptop, Vista, so I decide to run on another computer with Window XP. And I find that the program runs fine on XP.

Is there issue with Vista or Dell? By the way, when I run debugger in laptop, I do not find the issue during debugger.

Thanks

User avatar
Patrick
Lead Developer
Posts: 3078
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Not attached programming

Postby Patrick » Fri Oct 30, 2009 9:36 am

You can't call waitForAttachment in the detach handler because it's a blocking call, and blocking the event handlers will always cause issues.

-Patrick


Return to “VB .NET”

Who is online

Users browsing this forum: No registered users and 1 guest