Template:Language - C Sharp Editing the Examples
From Phidgets Support
The C# examples are what comprise the Windows Phidget Control Panel, so you'll need to modify a few things to adapt them for your own purposes. To begin with, you can remove the following line:
commandLineData phidgetParameters = open.parseCmdLine(); //get command line parameters
Then, you can modify any line that mentions phidgetParameters
by setting it to the desired value instead of using PhidgetParameters object.
For instance:
try
{ //set all the values grabbed from command line. these values have defaults that are set in ExampleUtils.cs, you can check there to see them.
digout.Channel = phidgetParameters.Channel; //selects the channel on the device to open
digout.DeviceSerialNumber = phidgetParameters.SerialNumber; //selects the device or hub to open
digout.HubPort = phidgetParameters.HubPort; //selects the port on the hub to open
digout.IsHubPortDevice = phidgetParameters.isHubPortDevice; //is the device a port on a VINT hub?
if (phidgetParameters.isRemote) //are we trying to open a remote device?
{
digout.IsRemote = true;
Net.EnableServerDiscovery(ServerType.Device); //turn on network scan
if (phidgetParameters.Password != null && phidgetParameters.ServerName != null)
Net.SetServerPassword(phidgetParameters.ServerName, phidgetParameters.Password); //set the password if there is one
}
else
digout.IsLocal = true;
digout.Open(); //open the device specified by the above parameters
}
catch (PhidgetException ex) { errorBox.addMessage("Error opening device: " + ex.Message); }
Might become:
try
{
digout.Channel = 0;
digout.DeviceSerialNumber = 370097;
digout.HubPort = 0;
digout.IsHubPortDevice = true;
digout.IsRemote = false;
digout.Open();
}
catch (PhidgetException ex) { errorBox.addMessage("Error opening device: " + ex.Message); }
You can then manipulate the rest of the code as your application requires. A more in-depth description of programming with Phidgets will be covered in the next section.