Page 1 of 2

Cannot use channel 0 anymore

Posted: Fri Apr 08, 2022 6:26 pm
by carnaby
I was using an absolute pressure sensor on channel 0 until the latest firmware update from Phidget and now channel 0 always says it is already open when I run in debug and try to attach the sensor. I've tried rebooting, shutting down the control panel, all that stuff, but it's still showing the following when I try to open the channel after an attach event on channel 0:

Failed to open Channel <PhidgetVoltageRatioInput> on local device: <VOLTAGERATIOINPUT_PORT (Hub Port - Voltage Ratio Mode) v100 -> HUB0000 Port:0 S/N:636524> because Channel: <VINT Hub Ch:0 -> HUB0000 S/N:636524> is opened on the same Hub Port, and these channels are mutually exclusive.

I have a parameter that sets the channel. I can change to any other channel and attach the sensor and it opens no problem except for channel 0. It works *sometimes* if I build and run my program as an executable.

Re: Cannot use channel 0 anymore

Posted: Mon Apr 11, 2022 12:08 pm
by carnaby
So if I restart several times it sometimes works. That's all I have at the moment. Any ideas?

Re: Cannot use channel 0 anymore

Posted: Mon Apr 11, 2022 4:17 pm
by Patrick
Hi,

It looks like you have the Hub itself open, and are also trying to open the first Hub port, and the library is mistakenly stopping you - this is a bug in the library. I'll have a fix published in the next release.

Out of curiosity - what are you using the Hub channel for?

-Patrick

Re: Cannot use channel 0 anymore

Posted: Mon Apr 11, 2022 6:18 pm
by carnaby
Hi Patrick,

I'm using it for a 1141 absolute pressure sensor.

Thanks!

Re: Cannot use channel 0 anymore

Posted: Tue Apr 12, 2022 9:28 am
by Patrick
Hi,

Just to confirm though - you are opening more than one Phidget channel in your program? From the log, it looks like you're opening the Hub channel - this would only be useful if you need to control the power to the hub ports: https://www.phidgets.com/?view=api&api=Hub&lang=CSharp

-Patrick

Re: Cannot use channel 0 anymore

Posted: Tue Apr 12, 2022 10:10 am
by carnaby
I'm using three sensors, one 1141 absolute sensor and two 1139 differential sensors and nothing else. The absolute sensor is always on channel 0 and the differential sensors are on channels 1 and 2. The differential sensors aren't having any trouble, just the absolute on channel 0.

Re: Cannot use channel 0 anymore

Posted: Tue Apr 12, 2022 10:11 am
by carnaby
Patrick wrote:Hi,

Just to confirm though - you are opening more than one Phidget channel in your program? From the log, it looks like you're opening the Hub channel - this would only be useful if you need to control the power to the hub ports: https://www.phidgets.com/?view=api&api=Hub&lang=CSharp

-Patrick
Is there a reason I would want to control power to the hub ports for absolute and differential pressure sensors? I don't see the use case.

Re: Cannot use channel 0 anymore

Posted: Tue Apr 12, 2022 1:52 pm
by Patrick
Hi,

I don't think you would want to control power to the hub ports - the Hub channel is almost never used, so I'm surprised to see that you are opening it - and it sounds like maybe you don't mean to be opening it?

From your error message, I see: <VINT Hub Ch:0 -> HUB0000 S/N:636524>

The only way this should be able to happen if if you are doing something like:

Code: Select all

Hub ch = new Hub();
ch.DeviceSerialNumber = 636524;
ch.Open();
In addition to opening the HubPort channels to talk to your three sensors.

-Patrick

Re: Cannot use channel 0 anymore

Posted: Tue Apr 12, 2022 4:24 pm
by carnaby
The only time I open anything is here:

Code: Select all

public void ManageSensors(PhidgetEvent phidgetEvent, int hubPort)
		{
			if(phidgetEvent == PhidgetEvent.attach)
			{
				switch(hubPort)
				{
					case Constants.ABSOLUTE_PRESSURE_SENSOR_PORT:

AbsolutePressureSensor?.Open();
						AbsolutePressureSensor.VoltageRatioSensor.Handler = ProcessPressureData;
						Debug.WriteLine("Abs P Attached and opened");
						break;
					case Constants.DIFFERENTIAL_PRESSURE_SENSOR_PORT_1:
						DifferentialPressureSensor1?.Open();
						DifferentialPressureSensor1.VoltageRatioSensor.Handler = ProcessPressureData;
						Debug.WriteLine("Diff P 1 Attached and opened");
						break;
					case Constants.DIFFERENTIAL_PRESSURE_SENSOR_PORT_2:
						DifferentialPressureSensor2?.Open();
						DifferentialPressureSensor2.VoltageRatioSensor.Handler = ProcessPressureData;
						Debug.WriteLine("Diff P 2 Attached and opened");
						break;
					case Constants.TEMPERATURE_SENSOR_PORT:
						TemperatureSensor?.Open();
						break;
					default:
						// noop
						break;
				}
			}
			else if(phidgetEvent == PhidgetEvent.detach)
			{
				switch (hubPort)
				{
					case Constants.ABSOLUTE_PRESSURE_SENSOR_PORT:
						AbsolutePressureSensor.Close();
						break;
					case Constants.DIFFERENTIAL_PRESSURE_SENSOR_PORT_1:
						DifferentialPressureSensor1.Close();
						break;
					case Constants.DIFFERENTIAL_PRESSURE_SENSOR_PORT_2:
						DifferentialPressureSensor2.Close();
						break;
					case Constants.TEMPERATURE_SENSOR_PORT:
						TemperatureSensor.Close();
						break;
				}
			}
		}
Which results in this call:

Code: Select all

public void Open()
		{
			try
			{
				_voltageRatioSensor.Open(OPEN_CHANNEL_TIMEOUT_MS);
			}
			catch(PhidgetException ex)
			{
				Debug.WriteLine($"Error opening device {_sensorName}: {ex.Message}");
			}
		}

Re: Cannot use channel 0 anymore

Posted: Tue Apr 12, 2022 4:29 pm
by carnaby
And also this code to define the voltage ratio sensor objects

Code: Select all

public VoltageRatioSensor(string sensorName, VoltageRatioSensorType sensorType, int hubPort)
		{
			_sensorName = sensorName;
			_sensorType = sensorType;
			_filterConstant = DEFAULT_FILTER_CONSTANT;

			_voltageRatioSensor = new VoltageRatioInput();
			_voltageRatioSensor.IsHubPortDevice = true;
			_voltageRatioSensor.HubPort = hubPort;

			_voltageRatioSensor.Attach += VoltageRatioInput_Attach;
			_voltageRatioSensor.Detach += VoltageRatioInput_Detach;
			_voltageRatioSensor.VoltageRatioChange += VoltageRatioInput_VoltageRatioChange;
		}

		
		public void Dispose()
		{
			_voltageRatioSensor?.Close();
		}

		public delegate void VoltageRatioUpdateHandler(double measurement, int index);
		public VoltageRatioUpdateHandler Handler;


		private void VoltageRatioInput_Attach(object sender, Phidget22.Events.AttachEventArgs e)
		{
			VoltageRatioInput attachedDevice = (VoltageRatioInput)sender;

			// setup
			try
			{
				attachedDevice.SensorValueChangeTrigger = 0;                     // trigger whenever data interval is up
				attachedDevice.DataInterval = DATA_INTERVAL_PRESSURE_MS;

				Debug.WriteLine("VR Sensor: " + attachedDevice.HubPort.ToString());
				Debug.WriteLine("VR Channel: " + attachedDevice.Channel.ToString());
			}
			catch (PhidgetException ex)
			{
				Debug.WriteLine($"Error initializing device {_sensorName}: {ex.Message}");
			}
		}