Page 2 of 2

Re: Cannot use channel 0 anymore

Posted: Tue Apr 12, 2022 4:31 pm
by carnaby
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()); }

		}

Re: Cannot use channel 0 anymore

Posted: Tue Apr 12, 2022 4:32 pm
by carnaby
Am I missing a call to new? I.e. should I have if VintHub is null

VintHub = new Hub;

Re: Cannot use channel 0 anymore

Posted: Wed Apr 13, 2022 8:36 am
by carnaby
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.

Re: Cannot use channel 0 anymore

Posted: Wed Apr 13, 2022 2:06 pm
by Patrick
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