Cannot use channel 0 anymore

Supporting Visual Studio on Windows
carnaby
Phidgetsian
Posts: 13
Joined: Fri Feb 21, 2020 10:35 pm
Contact:

Re: Cannot use channel 0 anymore

Post 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()); }

		}
carnaby
Phidgetsian
Posts: 13
Joined: Fri Feb 21, 2020 10:35 pm
Contact:

Re: Cannot use channel 0 anymore

Post by carnaby »

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:

Re: Cannot use channel 0 anymore

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

Re: Cannot use channel 0 anymore

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

Who is online

Users browsing this forum: No registered users and 0 guests