Help With Exception please

Comments & issues
Post Reply
chunt
Fresh meat
Posts: 2
Joined: Mon Jun 16, 2014 12:27 pm
Contact:

Help With Exception please

Post 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
erik
King of the Lab
Posts: 7
Joined: Fri Mar 06, 2009 12:42 pm
Location: Calgary, Canada
Contact:

Re: Help With Exception please

Post 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.
chunt
Fresh meat
Posts: 2
Joined: Mon Jun 16, 2014 12:27 pm
Contact:

Re: Help With Exception please

Post 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.
DenisFerrari
Phidgetsian
Posts: 12
Joined: Tue Mar 28, 2017 12:41 am
Contact:

Re: Help With Exception please

Post 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
User avatar
Patrick
Lead Developer
Posts: 614
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Help With Exception please

Post 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
DenisFerrari
Phidgetsian
Posts: 12
Joined: Tue Mar 28, 2017 12:41 am
Contact:

Re: Help With Exception please

Post 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
DenisFerrari
Phidgetsian
Posts: 12
Joined: Tue Mar 28, 2017 12:41 am
Contact:

Re: Help With Exception please

Post 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 :)
Post Reply

Who is online

Users browsing this forum: No registered users and 37 guests