Page 1 of 1

Help With Exception please

Posted: Thu Jun 19, 2014 11:01 am
by chunt
Hello All. Below is a exception that I have been getting and the code that throws it. I can't seem to figure it out. I was hoping that someone could shed some light on it or let me know how to handle it. I have tried catching it but it still closes the program. Thanks


Exception:
An unhandled exception of type 'Phidgets.PhidgetException' occurred in Phidget21.NET.dll

Additional information: PhidgetException 9 (Value is Unknown (State not yet received from device, or not yet set by user)

Program Code:
Public Class ReservoirCalibration
Dim WithEvents Bridge1 As Phidgets.Bridge
Public Sub New()
' This call is required by the Windows Form Designer.

InitializeComponent()

' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub ReservoirCalibration_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
Bridge1 = New Phidgets.Bridge
Bridge1.open()
Timer1.Start()

Bridge1.bridges(0).Enabled = True

Catch outofrange As System.ArgumentOutOfRangeException



Catch ex As Phidgets.PhidgetException

MessageBox.Show(ex.ToString())

End Try
End Sub


Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
LoadCell1Raw.Text = Bridge1.bridges(0).BridgeValue.ToString
End Sub
End Class

Re: Help With Exception please

Posted: Thu Jun 19, 2014 3:20 pm
by erik
This is happening because you are setting the Enabled property before the bridge has enough time to set up communication with the device.

After you call open() you should call waitForAttachment(). This is a blocking call that returns once the device hardware has been initialized by the drivers in the library and is ready to receive commands.

Re: Help With Exception please

Posted: Mon Jun 23, 2014 1:17 pm
by chunt
Excellent, thank you for the reply. So do I need to release the bridge when I close the form.

Private Sub Close1_Click(sender As Object, e As EventArgs) Handles Close1.Click
LoadCell1.close()
Me.Close()
End Sub

Sometimes when I close the form the program locks up and I have to stop debugging to continue. Thanks gain.

Re: Help With Exception please

Posted: Tue Mar 28, 2017 1:22 am
by DenisFerrari
As just written in a new Thread, I've the exact same problem often when closing the Bridge.

I still do not understand why.

I use 3 forms in my VB2008 application, Bridge works fine.

Only problem is that often - while doing a Me.Close + Bridge.Close() + Newform.Show, the application freezes (and stop responding) exactly on the Bridge.Close() row.

I still cannot figure out where's the problem and why it does that.

Any help ?

Thank you

Re: Help With Exception please

Posted: Tue Mar 28, 2017 8:33 am
by Patrick
This generally happen if you have the bridge data event handler set up, and then close the bridge in a form closing event. This will cause a deadlock. You need to deregister the event 1st, then call Application.DoEvents(), then close the bridge.

-Patrick

Re: Help With Exception please

Posted: Tue Mar 28, 2017 8:50 am
by DenisFerrari
Hi Patrick,
this is exactly what I do, look below :

If (Bridge.Attached) Then
RemoveHandler Bridge.Attach, AddressOf Bridge_Attach
RemoveHandler Bridge.Detach, AddressOf Bridge_Detach
RemoveHandler Bridge.Error, AddressOf Bridge_Error
RemoveHandler Bridge.BridgeData, AddressOf Bridge_BridgeData

Application.DoEvents()

Bridge.close()
End If

Re: Help With Exception please

Posted: Fri Mar 31, 2017 3:33 am
by DenisFerrari
Hi, just an update about my application often freezing while losing focus on a Form, locking on Bridge.Close() row :
after using Phidget21.NET.dll in place of Phidget21.NET1.1.dll, all my problems went away.
Tested on my W10 pc, using Visula Basic 2008, Visual Basic 2010 and eVisual Studio 2017 : no problems at all :)