Skip to content

2.1 Console Example

Kirk edited this page Aug 26, 2016 · 13 revisions

This example console application demonstrates how to use the SonyAPILib v5.2 in your own applications.

This example includes many lines of documentation that will explain what each line is doing to help users understand the structure and syntax of the API library. It is suggested that you review the code for this example before executing. This will allow you to understand each step and action that is being preformed. Also, this example only utilizes the IRCC service actions and properties.

This example will preform 10 steps. Each step below is also documented in the example code. This example also demonstrates the correct order or procedure to follow when using this API.

Step 1:

Create an instance of the API library.
SonyAPILib mySonyLib = new SonyAPILib();

Step 2:

Set API Logging properties.
mySonyLib.Log.Enable = true;
mySonyLib.Log.Level = "All";
mySonyLib.Log.Path = null;
mySonyLib.Log.Name = "SonyAPILib_LOG.txt";

Step 3:

Locate all UPnP/DLNA devices on network
List<string> foundDevices = mySonyLib.Locate.LocateDevices();

Step 4:

Build a Device object based on the URL's returned in step 3.
SonyAPILib.SonyDevice mySonyDevice = new SonyAPILib.SonyDevice();
mySonyDevice.DocumentURL = foundDevices[Convert.ToInt16(cki)].ToString();
mySonyDevice.BuildFromDocument(new Uri(mySonyDevice.DocumentURL));

Step 5:

Check the status of the Device
string status = mySonyDevice.Ircc.GetStatus(mySonyDevice);

Step 6:

register the device if not already registered
mySonyDevice.Register();
mySonyDevice.SendAuth("1234");

Step 7:

If registration is TRUE, display device information.
if (mySonyDevice.Registered == true)

Step 8:

Retrieve and Populate the device Remote Command List.
string CmdList = mySonyDevice.GetRemoteCommandList();

Step 9:

Demonstrate how to retrieve the Command Value String
string irccCmd = mySonyDevice.GetCommandString("VolumeUp");

Step 10:

Send several IRCC commands to device

string results = mySonyDevice.Ircc.SendIRCC(mySonyDevice,irccCmd);  
string results = mySonyDevice.Ircc.SendIRCC(mySonyDevice, mySonyDevice.GetCommandString("VolumeUp"));  
string results = mySonyDevice.SendText("Hello World"));