Supporting Visual Studio on Windows
carnaby
Phidgetsian
Posts: 13 Joined: Fri Feb 21, 2020 10:35 pm
Contact:
Post
by carnaby » Tue Apr 12, 2022 4:31 pm
Oh wait, I do have something with the hub. I think I have this so I can catch when the user phycially attaches and detaches the hub. Is this not correct?
Code: Select all
private void Manager_Attach(object sender, Phidget22.Events.ManagerAttachEventArgs e)
{
Manager man = (Manager)sender;
try
{
if (e.Channel.ChannelClass == ChannelClass.Hub)
{
if ((null == VintHub) || (VintHub != (Hub)e.Channel))
{
VintHub = (Hub)e.Channel;
VintHub.Attach += Hub_Attach;
VintHub.Detach += Hub_Detach;
VintHub.Open();
Debug.WriteLine("Hub opened");
}
}
else if(e.Channel.ChannelClass == ChannelClass.VoltageRatioInput)
{
if (e.Channel.HubPort == 0)
{
Handler?.Invoke(PhidgetEvent.attach, 0);
}
else if (e.Channel.HubPort == 1)
{
Handler?.Invoke(PhidgetEvent.attach, 1);
}
else if (e.Channel.HubPort == 2)
{
Handler?.Invoke(PhidgetEvent.attach, 2);
}
else if (e.Channel.HubPort == 3)
{
Handler?.Invoke(PhidgetEvent.attach, 3);
}
}
}
catch(PhidgetException ex) { Debug.WriteLine("Open Hub exception: " + ex.ToString()); }
}
carnaby
Phidgetsian
Posts: 13 Joined: Fri Feb 21, 2020 10:35 pm
Contact:
Post
by carnaby » Tue Apr 12, 2022 4:32 pm
Am I missing a call to new? I.e. should I have if VintHub is null
VintHub = new Hub;
carnaby
Phidgetsian
Posts: 13 Joined: Fri Feb 21, 2020 10:35 pm
Contact:
Post
by carnaby » Wed Apr 13, 2022 8:36 am
I got rid of all the hub open and attach / detach stuff but left this:
Code: Select all
public PhidgetManager()
{
// NOTE: Register attach and detach handlers for the manager before opening!
_phidgetManager = new Manager();
_phidgetManager.Attach += Manager_Attach;
_phidgetManager.Detach += Manager_Detach;
try
{
_phidgetManager.Open();
}
catch(PhidgetException ex)
{
Debug.WriteLine("Open phidget manager exception: " + ex.ToString());
}
}
Is this the correct course of action? Everything seems to be working now.
Patrick
Lead Developer
Posts: 631 Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:
Post
by Patrick » Wed Apr 13, 2022 2:06 pm
Hi,
That's right - even if you want to use the Phidget Manager to detect attach/detach of the Hub itself, you don't need to actually open the Hub channel unless you want to turn off the ports.
-Patrick
Users browsing this forum: No registered users and 2 guests