Phidget Network Server

From Phidgets Support

General Overview

The Phidget Network Server is a feature of Phidgets that makes it possible to control or interact with Phidgets connected to other computers on your local network. To understand how it works, let's first take a look at what a system looks like without the Network Server enabled:



Phidgets without NetworkServer.jpg


At the top you have your computer, which has the Phidgets drivers installed. Connected via USB are a number of USB Phidgets and/or VINT Hubs. Connected to the VINT Hubs could be VINT devices.


All of these connected Phidgets have various channels that can be opened, which allow the program running on your computer to read data from them or control their various parts.


Since the Network Server is disabled in this diagram, this computer is the only one that will be able to access these Phidgets.


Once the Phidget Network Server is enabled, your computer hosts a Phidget Server which broadcasts all connected Phidgets to other computers on your network. When another computer tries to open a channel, your Phidgets will be included in the list it selects the channel from.

NetworkServer PhidgetServer.jpg

When you open a Phidget, you have the option of opening it locally or remotely.

Opening a Phidget locally means communicating with it directly. You can only locally open Phidgets that are physically connected to the computer running your program.

Opening a Phidget remotely means communicating with it using the Network Server. You can remotely open any Phidget on your network, even ones that are physically connected to the computer running your program.

Why would you want to remotely open a Phidget that's physically attached to the computer? Well, a Phidget channel that is opened locally cannot be accessed by any other computer for as long as it's opened. A Phidget channel that is remotely opened, on the other hand, can be simultaneously opened by any number of programs.

NetworkServer Local Remote.jpg

As you can see in this example, there is a Phidget with four channels connected to one computer via USB. When it locally opens DigitalOutput channel 1, the other computer on the network is unable to open that channel remotely. Furthermore, that same computer cannot open a second instance of that channel using the network server because it's already opened it locally. On the other hand, both computers are able to open DigitalOutput channel 2 remotely, because it hasn't been opened locally by the host computer. Either computer in the diagram could remotely open several instances of DigitalOutput channel 2 in this way.

Using The Network Server

Each Operating System page has a section on how to use the Network Server on that operating system:

The operating systems pages have complete examples on how to set up a network server process and using it to remotely control or gather data from Phidgets. The pages also tell you how to start and stop the Network Server on your computer, and how to run it with or without mDNS (Bonjour, avahi, etc).

Connecting to a Network Server

There are two ways to gain access to a Phidget server that's being hosted on your network. If the server is broadcasting itself on mDNS, you can simply enable automatic server discovery in your program. In C#, for example, you would call the Net.EnableServerDiscovery(ServerType.Device) method in your program. Net is the object that is used for Phidget Networking. You can find a full list of methods and properties in the Phidget22 API by selecting "Networking API" in the drop-down menu.

If the Phidget server is not broadcasting itself on mDNS, you can connect to it by adding it specifically. In C#, for example, you would do this by calling the Net.AddServer() method. AddServer takes a number of parameters that help specify the server to connect to (e.g. IP address, port, password). For more details on how to use AddServer, take a look at the "Networking API" in the Phidget22 API.

Network Server on a Phidget Single Board Computer

The Phidget Single Board Computer (SBC) can provide a compact, inexpensive way to easily run the Network Server. It runs the Network Server in the background automatically from the moment you turn it on, and allows you to read from and control all Phidgets attached to it:

Network server sbc.jpg

In this example, a Phidget SBC physically connected to a VINT Hub which is connected to a VINT device. The SBC itself has its own channels corresponding to the on-board ports it has. By using the network server, it makes all of these channels available to any device connected to the same wireless network.

This is convenient because it allows the Phidgets and sensors to be in a remote location, like mounted on a wall or inside some kind of assembly, rather than sitting on your computer desk. The channels of this system could be conveniently accessed by a home computer on the network, a phone running some Phidgets code, or even another Phidget SBC in a different location.

The SBC runs Linux, which provides a full operating system on which to develop code, serve web pages, and control Phidgets.

For more information on controlling Phidgets with your phone, have a look at the mobile section of our languages page, or read this article where we use iOS to control a robot full of Phidgets.

Examples

Below are some quick examples showing how simple it is to open a Phidget remotely over the Network Server. In each example, a light sensor Phidget is being remotely opened on port 0 of a VINT Hub with serial number 37299.

C/C++
PhidgetLightSensorHandle ch;
PhidgetLightSensor_create(&ch);

Phidget_setDeviceSerialNumber((PhidgetHandle) ch, 37299);
Phidget_setHubPort((PhidgetHandle) ch, 0);
Phidget_setIsRemote((PhidgetHandle) ch, 1);

Phidget_open((PhidgetHandle) ch);
C#
LightSensor ch = new LightSensor();

ch.DeviceSerialNumber = 37299;
ch.HubPort = 0;
ch.IsRemote = true;

ch.Open();
Java
LightSensor ch = new LightSensor();

ch.setDeviceSerialNumber(37299);
ch.setHubPort(0);
ch.setIsRemote(true);

ch.open();
Python
ch = LightSensor()

ch.setDeviceSerialNumber(37299)
ch.setHubPort(0)
ch.setIsRemote(1)

ch.open();

For more information, have a look at the Phidget22 API and select your language from the drop-down menu. You can learn more about opening Phidgets on the Programming Basics page.

Troubleshooting

When using the Network Server, both the client and server should have the same version of the Network Server installed. The easiest way to ensure this is to update your libraries on both ends.

For other troubleshooting tips, try our General Troubleshooting page, in its Network Server section.

Further Reading

Phidget Programming Basics - Here you can find the basic concepts to help you get started with making your own programs that use Phidgets.

Data Interval/Change Trigger - Learn about these two properties that control how much data comes in from your sensors.

Using Multiple Phidgets - It can be difficult to figure out how to use more than one Phidget in your program. This page will guide you through the steps.

Polling vs. Events - Your program can gather data in either a polling-driven or event-driven manner. Learn the difference to determine which is best for your application.

Logging, Exceptions, and Errors - Learn about all the tools you can use to debug your program.

Best Phidgets Practices - Good programming habits that will save you from common problems when writing code for your Phidgets.