Connecting to the PIXL
As with any new technology, the first thing to do is to create a Hello World! application to ensure get to grips with the basics.
This assumes the following:
- The SI.PIXL.Client NuGet package has been added to the project. If this is not the case see Prerequisites.
- A PIXL is connected to the same network as the development machine.
- The PIXL's API feature is enabled.
In order to connect to any PIXL on the network a Channel is required. A Channel is used for all communications with the PIXL, and can be created with the GetPIXLChannel method of the PIXLClient class.
var channel = PIXLClient.GetPIXLChannel();
Alternatively, in order to connect to a specific PIXL two pieces of information are required:
- The host, that is, the IP address of the computer running the PIXL software.
- The gRPC port number of the PIXL.
Both the host and the port are displayed on the 'Settings/API' panel of the PIXL UI software. From the host and port we can determine a Channel.
var channel = PIXLClient.GetPIXLChannel("127.0.0.1", 50052);
With the Channel we can create a new instance of the PIXLClient class.
var pixl = new PIXLClient(channel);
This will open a connection to the PIXL at the provided IP address and gRPC port. To test the connection we can read the Serial Number from the PIXL and display it on the Console.
Console.WriteLine(pixl.SerialNumber);
To summarise the code should look like this:
var channel = PIXLClient.GetPIXLChannel("127.0.0.1", 50052);
var pixl = new PIXLClient(channel);
Console.WriteLine(pixl.SerialNumber);
So far we have created a channel from an IP address and gRPC port, instantiated a new instance of the PIXLClient class and read the PIXL's serial number. This is the equivalent of the PIXL saying Hello World!