-
Notifications
You must be signed in to change notification settings - Fork 19
2.1 Console Example
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.
Create an instance of the API library.
SonyAPILib mySonyLib = new SonyAPILib();
Set API Logging properties.
mySonyLib.Log.Enable = true;
mySonyLib.Log.Level = "All";
mySonyLib.Log.Path = null;
mySonyLib.Log.Name = "SonyAPILib_LOG.txt";
Locate all UPnP/DLNA devices on network
List<string> foundDevices = mySonyLib.Locate.LocateDevices();
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));
Check the status of the Device
string status = mySonyDevice.Ircc.GetStatus(mySonyDevice);
register the device if not already registered
mySonyDevice.Register();
mySonyDevice.SendAuth("1234");
If registration is TRUE, display device information.
if (mySonyDevice.Registered == true)
Retrieve and Populate the device Remote Command List.
string CmdList = mySonyDevice.GetRemoteCommandList();
Demonstrate how to retrieve the Command Value String
string irccCmd = mySonyDevice.GetCommandString("VolumeUp");
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"));