I am trying to connect several sensors through a VINT hub and out-putting the data in a text box (similar to the Phidget_Programming_Basics video example).
https://www.phidgets.com/docs/Phidget_P ... ing_Basics
Unfortunately I am unable to see all of the code in the video so I cannot duplicate all of it, if you could post the code in that example, that might be all I need.
I tried to make use of the C# code examples, but I could not do much with them because some of the supporting files are not included.
The problem I am having now is that the attached code does not seem to be doing anything and I can't figure out why.
Nothing changes in the text box.
The Phidget Control Panel does show all the devices.
Will you please look at the code below and see if something obvious is missing?
Code: Select all
namespace Phidgets_Basic
{
public partial class Form1 : Form
{
HumiditySensor humidity_sensor;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
humidity_sensor = new HumiditySensor();
humidity_sensor.DeviceSerialNumber = 496925;
humidity_sensor.HubPort = 0;
humidity_sensor.IsHubPortDevice = true;
humidity_sensor.Attach += humidity_sensor_attach;
humidity_sensor.Detach += humidity_sensor_detach;
humidity_sensor.HumidityChange += humidity_sensor_change;
try
{
//MessageBox.Show("trying to open humidity sensor 1");
humidity_sensor = new HumiditySensor();
//MessageBox.Show("trying to open humidity sensor 2");
humidity_sensor.Open();
//MessageBox.Show("trying to open humidity sensor 3");
}
catch (PhidgetException ex)
{
MessageBox.Show("Error: " + ex.Description);
}
}
//Humidity sensor
void humidity_sensor_attach(object sender, Phidget22.Events.AttachEventArgs e)
{
textBox1.Text = ("1");
HumiditySensor attachedDevice = (HumiditySensor)sender;
try
{
attachedDevice.DataInterval = attachedDevice.MinDataInterval;
attachedDevice.HumidityChangeTrigger = attachedDevice.MinHumidityChangeTrigger;
}
catch (PhidgetException ex) { textBox1.Text = ("Error initializing device: " + ex.Message); }
}
void humidity_sensor_detach(object sender, Phidget22.Events.DetachEventArgs e)
{
}
void humidity_error(object sender, Phidget22.Events.ErrorEventArgs e)
{
MessageBox.Show(e.Description);
//errorBox.addMessage(e.Description);
}
void humidity_sensor_change(object sender, HumiditySensorHumidityChangeEventArgs e)
{
try
{
textBox1.Text = Math.Round(e.Humidity, 4).ToString() + "%";
}
catch (PhidgetException ex) { textBox1.Text=("Error reading humidity: " + ex.Message); }
}
}
}