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.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
Code: Select all
Hub ch = new Hub();
ch.DeviceSerialNumber = 636524;
ch.Open();
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;
}
}
}
Code: Select all
public void Open()
{
try
{
_voltageRatioSensor.Open(OPEN_CHANNEL_TIMEOUT_MS);
}
catch(PhidgetException ex)
{
Debug.WriteLine($"Error opening device {_sensorName}: {ex.Message}");
}
}
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}");
}
}
Users browsing this forum: No registered users and 0 guests