Page 1 of 1

Opening a new form then returning to the original

Posted: Mon Aug 19, 2013 5:47 am
by Ironbark
I open and attach my bridge phidget on my main form, then hide it and open a second form. On this second form I only enter limits etc, then close it and show the main form again.

I have based the main form essentially on the example in the downloads with very little modification.

The phidget is gone and will not re-attach.

I would greatly appreciate any guidance on the trick to getting this working.

Re: Opening a new form then returning to the original

Posted: Tue Mar 28, 2017 1:31 am
by DenisFerrari
Hi,
I just started to use Bridge and I've too started from VB2008 BridgeFull example.

I've noticed that as soon you have the Deactivate event of my current form, it's best to do Bridge.Close() and then reopen it one Activate event. Otherwise it does exactly like that, I mean, it stays disconnected and not working anymore.

Also, in my case, I've 3 forms all using the bridge.

While passing from one form to another, I do a Bridge.Close(), then Me.Close, then Newform.Show and it works.

Only problems I often have is that while loosing focus on the form, or reducing the form and getting back to it, my VB2008 app freezes and stops exaclty on current form Bridge.Close() row.

And I still do not understand why it doeas that.

Any help is highly appreciated.

Re: Opening a new form then returning to the original

Posted: Tue Mar 28, 2017 8:35 am
by Patrick
You can close/open, but you may want to move your bridge code to another class and just share as a global singleton.

-Patrick

Re: Opening a new form then returning to the original

Posted: Tue Mar 28, 2017 8:52 am
by DenisFerrari
Hi Patrick,
opening the Bridge only on start-up Form (that calls the others etc.) and pass to the rest was exactly my initial idal, but I still have not been able to do this.

Any help on this too ?

Thank you

Re: Opening a new form then returning to the original

Posted: Tue Mar 28, 2017 11:40 am
by Patrick
Create a singleton class, which your forms will all share. The forms can register/deregister for events as they come up/down.

Since the PhidgetBridge object isn't owned by your forms, you will need to handle Invoke yourself if you need to access the form directly from and Phidget events.

For example:

Code: Select all

public class BridgeSingleton
{
   private static PhidgetBridge instance;

   private BridgeSingleton() {}

   public static PhidgetBridge Bridge
   {
      get 
      {
         if (instance == null)
         {
            instance = new PhidgetBridge();
            instance.open();
            instance.waitForAttachement(500);
         }
         return instance;
      }
   }
}
Then, in your forms:

Code: Select all

BridgeSingleton.Bridge.BridgeData += BridgeDataEventHandler;
Note: this is pretty basic/untested. You would probably want to implement some sort of static connect function so you can handle waitForAttachement timeouts, or don't waitForAttachement, but handle attach/detach events, etc...

-Patrick

Re: Opening a new form then returning to the original

Posted: Tue Mar 28, 2017 1:51 pm
by DenisFerrari
Hi Patrick,
Thank you for the hint

But I'm using VB2008 , not C/C++ or Roger language.

Any help on that too ?

Thanks again.

Re: Opening a new form then returning to the original

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