SonyAPILib
一个C# API库,用于发现、注册和控制配备LAN或WiFi端口的Sony设备。
引言
此C# API提供4个阶段的方法和属性,用于发现、注册和控制配备LAN或WiFi端口且安装了IRCC UPnP服务的Sony智能设备。
SonyAPILib 阶段
1 发现
2 注册
3 初始化
4 远程控制
Sony智能设备加载了3种不同代基于Linux的Web服务器API之一。设备的年份将决定加载在设备上的API代。第1代和第2代主要使用UPnP SOAP服务进行通信或发送命令。第3代设备目前主要使用JSON进行通信或发送命令。
要访问任何代设备的全部功能,**必须**完成注册过程!(用户已确定注册不是发送命令所必需的,但其他功能将不可用。) 设备代将决定遵循正确的注册过程。例如,第1代设备将在设备(电视)上自动显示确认屏幕以完成注册。第2代设备在尝试注册之前必须置于“注册模式”。第3代设备将在屏幕上显示一个PIN码,在注册完成前必须与设备确认。
所有代设备都使用IRCC名称:值对向设备发送命令。从设备检索此列表取决于设备代。第1代和第2代设备将有一个actionList_Url,其中包含用于从设备检索remoteCommandList的URL方法。**必须**在设备返回此信息之前完成注册过程。第1代和第2代设备将返回一个XML文件(字符串),其中包含名称:值对。例如:<command name="VolumeUp" type="ircc" value="AAAAAQAAAAEAAAASAw==" />.
第3代设备使用JSON命令检索命令列表,并返回类似JSON的值: {"name":"VolumeUp","value":"AAAAAQAAAAEAAAASAw=="}
背景
此API库是互联网上许多不同来源和用户的汇编,以及我数月个人测试和编码的成果。非常感谢Lance Clark和Pete Brutsch在第2代和第3代设备上帮助测试此API。Mendel的贡献也极大地推动了项目进展,他在此处发布了他的发现:http://mendelonline.be/sony/
第三方文件
此API库使用了2个额外的第三方库。
ManagedUPnP库提供了用于发现和初始化设备的方法。
此库由TheToid编写,可在此处下载:http://managedupnp.codeplex.com/
NewtonSoft.Json库用于执行第3代设备使用的所有JSON命令。
此库由James Newton-King编写,可在此处下载:https://nuget.net.cn/packages/Newtonsoft.Json/
SonyAPILib 阶段
此API包含4个不同的阶段。
每个阶段都有其重要性和要求。
某些阶段要求先完成其他阶段,然后才能正常工作!
请 参阅API库类以获取更多信息 后再继续。
发现 - 第1阶段
这是API的初始阶段。
此阶段用于向加载了Sony IRCC服务的设备发送UPnP广播,然后监听任何响应。如果有设备响应,则创建一个新的SonyDevice对象,其中包含从该设备获取的信息。找到的每个SonyDevice都会被添加到返回的列表中。
例如
List<SonyAPI_Lib.SonyDevice> fDev = mySonyLib.API.sonyDiscover(null);
上面的列表fDev将包含局域网中找到的所有Sony设备。
要确定API发现了多少设备,请使用列表的Count()方法。例如
int x = fDev.Count()
要从列表中提取设备,只需指定数组元素。
请记住数组从0(零)开始,而不是1!因此,如果列表只有一个设备,那么数组就是0。如果列表包含2个或更多设备,那么数组就是0、1、2、3、...。
要检索列表中的第一个设备,请使用此示例
SonyAPI_Lib.SonyDevice myDevice = fDev[0]
或者更改数组为您想要的项。
现在您可以将设备信息保存在数据库或文本文件中,或您应用程序使用的任何介质中。保存设备的友好名称和IP地址是初始化设备而无需每次执行应用程序时都使用SonyDiscovery()方法所必需的。
例如
List<SonyAPI_Lib.SonyDevice> fDev = mySonyLib.API.sonyDiscover(null); SonyAPI_Lib.SonyDevice myDevice = fDev[0]; string sql = "INSERT INTO Devices set Name = myDevice.Name, IP = myDevice.Device_IP_Address";
初始化 - 第2阶段
初始化一个新的Sony设备类对象。
此阶段用于检索连接和通信所需的所有未知信息。初始化过程可以通过提供**仅2个**设备属性(名称和IP地址)来实现。这些信息可以手动输入,或者如上面第1阶段所述,从数据库或文本文件中检索。这为应用程序提供了一种重用设备而无需运行SonyDiscover()方法的方式。但是,即使使用了SonyDiscover()方法,设备对象**仍必须**初始化。
要初始化使用SonyDiscover()找到的第一个设备,请使用此示例
List<SonyAPI_Lib.SonyDevice> fDev = mySonyLib.API.sonyDiscover(null); SonyAPI_Lib.SonyDevice myDevice = new SonyAPI_Lib.SonyDevice(); myDevice.initialize(fDev[0]);
要初始化先前使用SonyDiscover()找到但已保存到数据库或文本文件的设备,请使用此示例
saved_Name = getinfofromfile('device_name'); saved_IP_Address = getinfofromfile('device_ip'); SonyAPI_Lib.SonyDevice myDevice = new SonyAPI_Lib.SonyDevice(); myDevice.Name = saved_Name; myDevice.Device_IP_Address = saved_IP_Address; myDevice.initialize();
注意:使用上述方法时,“名称”属性必须与设备返回的名称完全匹配!
有关更多信息,请参阅:SonyDevice 初始化
注册 - 第3阶段
将控制设备(计算机、手机、平板电脑)注册到要控制的Sony设备。
所有代Sony设备都使用IRCC UPnP服务(作者:Sony)向设备发送命令。UPnP服务不需要控制设备注册。但是,如果未完成注册过程,某些其他功能和特性可能不可用。此API编写的初衷是**将**使用注册过程,否则API可能会产生不良结果、错误或可能导致应用程序崩溃。(请在此处报告任何bug或问题:问题)。
设备代将决定遵循正确的注册过程。例如,第1代设备将在设备(电视)上自动显示确认屏幕,用户必须确认才能完成注册。第2代设备在尝试注册之前必须置于“注册模式”。第3代设备将在屏幕上显示一个PIN码,在注册完成前必须与设备确认。因此,无论设备代如何,都需要在Sony设备上进行用户交互才能完成注册过程。
注册过程使用服务器名称在设备上注册。例如,TVSideview使用您的计算机名称加上其名称,如:Your_Computer_Name(TVSideView)
。此API将自动使用名称:Your_Computer_Name(SonyAPILib)
。要使用不同的名称或您应用程序的名称,请在初始化和注册设备之前设置设备的Server_Name。此外,一旦使用此名称注册,每次使用相同名称初始化设备时都需要设置它!
例如
saved_Name = getinfofromfile('device_name'); saved_IP_Address = getinfofromfile('device_ip'); MyServer_Name = "The_Name_of_my_application" SonyAPI_Lib.SonyDevice myDevice = new SonyAPI_Lib.SonyDevice(); myDevice.Name = saved_Name; myDevice.Device_IP_Address = saved_IP_Address; myDevice.Server_Name = MyServer_Name; myDevice.initialize();
注意:在运行注册过程之前,请确保设备已初始化!
注意:如果注册返回true,则此方法**不必**在同一控制设备上再次运行。但是,如果您想在另一台计算机或控制设备上运行该应用程序,它**必须**也完成注册!
对于第1代和第2代设备,请使用此示例:(旧设备)
List<SonyAPI_Lib.SonyDevice> fDev = mySonyLib.API.sonyDiscover(null); SonyAPI_Lib.SonyDevice myDevice = new SonyAPI_Lib.SonyDevice(); myDevice.initialize(fDev[0]); bool registration = myDevice.register(); if(registration==true) { // Do whatever; }
对于第1、2、3代设备,这需要一个额外的步骤。请使用此示例:(任何设备)
List<SonyAPI_Lib.SonyDevice> fDev = mySonyLib.API.sonyDiscover(null); SonyAPI_Lib.SonyDevice myDevice = new SonyAPI_Lib.SonyDevice(); myDevice.initialize(fDev[0]); bool registration = myDevice.register(); if(myDevice.Generation == 3) { string pin = Console.ReadLine(); // Allow user to enter PIN Code. Could be a Form in a Forms App registration = myDevice.sendAuth(pin); } if(registration==true) { // Do whatever; }
有关更多信息,请参阅:Sony设备注册
远程控制 - 第4阶段
将远程控制命令发送到设备。
所有代Sony设备都使用IRCC UPnP服务(作者:Sony)向设备发送命令。在初始化过程中,SonyDevice的命令列表已填充。可以通过使用以下方法访问这些命令:myDevice.Commands
。每个命令都包含一个名称:值对。但是,设备只需要值即可执行。例如,音量增大命令的值是AAAAAQAAAAEAAAASAw==
。这就是需要发送到设备的内容。
要检索命令值字符串,请使用此示例
string irccCmd = myDevice.getIRCCcommandString("VolumeUp");
然后,要将此值发送到设备,请使用此示例
string results = myDevice.send_ircc(irccCmd);
更简洁的方法是使用此示例
string results = myDevice.send_ircc(myDevice.getIRCCcommandString("VolumeUp"));
注意:字符串results
将包含设备返回的任何信息。
有关更多信息,请参阅:Sony设备getIRCCcommandString()或send_ircc()。
SonyAPI_Lib 类
需要.NET Framework 4.0
这是API的主类。
所需引用
SonyAPILib.dll
语法
public class SonyAPI_Lib()
部分类
API - 用于设备发现的API类。
LOG - 用于API日志信息的日志类。
SonyDevice - Sony设备类包含与设备相关的所有属性和方法。
mySony - 包含局域网上发现的所有UPnP服务的类。(更多内容即将推出!)
构造函数
必需:像这样创建一个API库的新实例
SonyAPI_Lib mySonyLib = new SonyAPI_Lib();
此新实例将用于设置所有日志信息、UPnP服务和设备发现方法。
要使此API正常运行,必须创建此实例!
.API 类
此类包含用于发现Sony IRCC设备的方法和属性。
语法
public class SonyAPI_Lib.API()
方法
sonyDiscovery - 此方法仅用于向局域网发送UPnP广播,以定位加载了Sony UPnP IRCC服务的任何设备。
语法:SonyAPI_Lib.API.sonyDiscovery(service);
参数:service
- 在发现过程中要搜索的UPnP服务。
使用“null”表示默认的IRCC:1服务。
注意:如果使用的服务不是“null”,则此API可能无法正常运行!(用于未来升级)
返回:在过程中发现的所有SonyDevice对象的列表。通过sonyDiscovery()返回的SonyDevice对象仅包含设备的名称和IP地址。这些是完成设备初始化所需的唯二属性。有关更多信息,请参阅SonyDevice Initialize。
示例
List<SonyAPI_Lib.SonyDevice> fDev = mySonyLib.API.sonyDiscover(null)
列表fDev
将返回局域网上找到的所有SonyDevice的列表。
有关更多信息,请参阅:SonyDevice类
.LOG 类
SonyAPI_Lib具有自己的基本日志记录系统。
可以通过设置LOG对象属性将其实现到您自己的程序中。
此类包含API日志记录系统中使用的方法和属性。
语法
public class SonyAPI_Lib.LOG()
方法
writetolog - 将消息行写入API日志文件。
语法:mySonyLib.LOG.writetolog(message, oride);
参数message
是一个字符串,包含要写入文件的文本。
参数oride
是一个布尔值,用于设置是否无论enableLogginglev值如何都记录该行。
例如:mySonyLib.LOG.writetolog("This is my Text", true);
将把该行写入日志文件,无论日志级别设置为什么。
clearLog - 清除日志文件的内容。
语法:mySonyLib.LOG.clearLog(newName);
参数newName
如果未设置为“null”,则会在清除之前将现有日志文件重命名为newName。注意:必须是文本文件(.txt)
此示例将仅清除日志
mySonyLib.LOG.clearLog(null);
此示例会将日志文件复制到一个新文件中,然后清除日志文件
mySonyLib.LOG.clearLog("Old_LOG_File.txt");
属性
enableLogging - 设置为True或False以开启或关闭日志记录。
语法:mySonyLib.LOG.enableLogging = true
。(默认设置为FALSE)。
enableLogginglev - 设置日志记录级别。“Basic”仅记录最少信息,而“All”记录所有信息。
语法
mySonyLib.LOG.enableLogginglev = "All"
。(默认设置为“Basic”)。
loggingPath - 设置保存日志文件的位置。
语法
mySonyLib.LOG.loggingPath = "c:\tempfolder"
(默认设置为“C:\ProgramData\Sony”)。
loggingName - 设置要使用的日志文件名。
语法
mySonyLib.LOG.loggingName = "MySonyLoggingFile.txt"
(默认设置为“SonyAPILib_LOG.txt”)。
.SonyDevice 类
SonyDevice 类
此类包含初始化、注册和控制Sony设备的所有方法和属性。
语法
public class SonyAPI_Lib.SonyDevice()
构造函数
SonyAPI_Lib.SonyDevice SonyDevice = new SonyAPI_Lib.SonyDevice()
方法
.initialize - 此方法用于使用访问和控制Sony设备所需的所有信息来初始化SonyDevice。
语法1:SonyDevice.initialize();
语法2:SonyDevice.initialize(SonyDevice);
注意:此方法要求在执行**之前**设置SonyDevice的“名称”和“Device_IP_Address”属性。这可以通过用户输入手动输入,从保存的数据库或文件中检索,或使用Discovery检索(请参阅API类)。
Initialize方法将自动执行以下任务:
1. 确定设备是哪一代。
2. 定位通信所使用的端口号。
3. 检索设备MAC地址(如果需要)(Gen3)。
4. 检索计算机MAC地址(用于Gen 1 & 2注册和认证)。
5. 从设备检索IRCC远程命令列表。
6. 检查是否已成功完成注册。
7. 如果是Gen 3且Registration为TRUE,则加载已保存的cookie以进行认证。
8. 检查设备的当前状态。
重要:在执行任何其他任务(如注册、检查状态或发送命令)之前,**必须**初始化设备。
Initialize方法有2个重载,提供2种不同的初始化设备的方式。
此示例根据另一个SonyDevice对象或Discovery()方法返回的对象初始化一个新的SonyDevice对象。
List<SonyAPI_Lib.SonyDevice> fDev = mySonyLib.API.sonyDiscover(null); SonyAPI_Lib.SonyDevice mySonyDev = new SonyAPI_Lib.SonyDevice(); fDev[0].Server_Name = "TheNameofMyApplication"; mySonyDev.initialize(fDev[0]);
此示例手动初始化一个新的SonyDevice对象,而不使用Discovery()方法。
SonyAPI_Lib.SonyDevice mySonyDev = new SonyAPI_Lib.SonyDevice(); mySonyDev.Name = "Bravia KDL-48W600B"; mySonyDev.Device_IP_Address = "192.168.0.222"; mySonyDev.Server_Name = "TheNameofMyApplication"; mySonyDev.initialize();
.register - 此方法用于执行与Sony设备的注册过程。
语法:SonyDevice.register();
注意:在尝试执行register方法之前,**必须**执行initialize方法。
返回:将返回一个布尔值True或False,具体取决于注册是否成功。
重要:第3代设备将返回FALSE,因为需要一个额外的步骤来完成注册过程。设备将在屏幕上显示一个PIN码,需要与设备进行认证。为此,允许用户输入显示的PIN码,然后立即执行SonyDevice.sendAuth(pincode)
。(请参阅.sendAuth方法)。
示例
SonyAPI_Lib.SonyDevice mySonyDev = new SonyAPI_Lib.SonyDevice(); mySonyDev.Name = "Bravia KDL-48W600B"; mySonyDev.Device_IP_Address = "192.168.0.222"; mySonyDev.Server_Name = "TheNameofMyApplication"; mySonyDev.initialize(); if(mySonyDev.Registered == false) { Bool isreg = mySonyDev.register(); if(mySonyDev.Generation == 3 && isreg == false) { Console.WriteLine("Enter PIN Code displayed on device screen."); string ckii = Console.ReadLine(); isreg = mySonyDev.sendAuth(ckii); } } if(isreg == true) { // do whatever; }
注意此方法还将SonyDevice.Registered属性设置为相应的值。(请参阅属性)
.sendAuth - 此方法用于将身份验证PIN码发送到设备进行确认。这**仅**用于第3代设备。
语法:SonyDevice.sendAuth(pincode);
参数:pincode
是一个包含用户输入的PIN码的字符串。
注意:此方法必须与SonyDevice.register方法结合使用,并且必须在设备在屏幕上显示PIN信息后的30秒内调用,否则设备将“超时”。
示例
SonyAPI_Lib.SonyDevice mySonyDev = new SonyAPI_Lib.SonyDevice(); mySonyDev.Name = "Bravia KDL-48W600B"; mySonyDev.Device_IP_Address = "192.168.0.222"; mySonyDev.Server_Name = "TheNameofMyApplication"; mySonyDev.initialize(fDev[0]); if(mySonyDev.Registered == false) { Bool isreg = mySonyDev.register(); if(mySonyDev.Generation == 3 && isreg == false) { string ckii = Console.ReadLine(); Console.WriteLine("Enter PIN Code displayed on screen."); isreg = mySonyDev.sendAuth(ckii); } } if(isreg == true) { // do whatever; }
注意此方法还将SonyDevice.Registered属性设置为相应的值。(请参阅属性)
.get_remote_command_list - 此方法用于从设备检索IRCC远程命令列表。
这也会在SonyDevice.Initialize
期间执行,并将填充SonyDevice.Commands列表。
语法:SonyDevice.get_remote_command_list();
注意:返回:此方法将返回包含已检索命令列表的XML文件作为字符串供您自己使用。
示例
string cmdList = mySonyDev.get_remote_command_list();
有关更多信息,请参阅
.initialize 上方
下方属性
示例远程命令列表
.checkStatus - 此方法用于检查设备的当前状态。
语法:SonyDevice.checkStatus();
注意
返回:此方法将返回一个包含设备响应的字符串。
重要:如果设备关闭,第1代和第2代设备将不响应。第2代和第3代设备能够将网络端口设置为在断电时保持活动状态。
示例
string devStatus = mySonyDev.checkStatus() if(devStatus == "") { console.writeline("Device May be OFF!"); }
返回的示例字符串:viewing:HDMI1
或status:active
.getIRCCCommandString - 此方法用于从SonyDevice.Commands列表中检索实际的IRCC命令值。
语法:SonyDevice.getIRCCCommandString(CommandName);
参数:CommandName
- 包含要转换为IRCC值的命令名称的字符串。
返回:-此方法将返回提供命令名称的IRCC值。如果找不到命令名称,则返回空字符串(“”)。
注意:可与.sendIRCC(见下文)结合使用。
示例
string myCommand = mySonyDev.getIRCCCommandString("VolumeUp"); if(myCommand == "") { console.writeline("Command not found"); } else { mySonyDev.sendIRCC(myCommand); }
返回的示例字符串:AAAAAQAAAAEAAAASAw==
.sendIRCC - 此方法用于向设备发送IRCC命令值
语法:SonyDevice.sendIRCC(CommandValue)
参数:CommandValue
这是包含使用getIRCCCommandString方法检索到的远程命令值,或从SonyDevice.Commands列表中检索到的字符串。
返回:此方法将返回一个包含设备响应的字符串。
注意:可与.getIRCCCommandString(见上方)结合使用。
示例
string response = mySonyDev.sendIRCC(mySonyDev.getIRCCCommandString("VolumeUp")); if(response == "") { console.writeline("Command not found"); }
.send_text - 此方法用于将文本发送到设备的搜索屏幕。
语法:SonyDevice.send_text(usertext)
参数:usertext
这是包含要发送到设备的文本的字符串。
返回:此方法将返回一个包含设备响应的字符串。
注意:执行此方法之前,搜索屏幕必须可见!
示例
string response = mySonyDev.send_text("Action Movies");
.channel_set - 此方法用于将完整的频道发送到设备,而不是一次发送一个数字。
语法:SonyDevice.channel_set(channel)
参数:channel
这是包含要发送到设备的有效频道的字符串。
注意:此方法**仅**应用于具有ChannelUp或ChannelDown命令的设备!家庭影院放大器和DVD/蓝光播放器如果发送此方法将崩溃!此方法还将更新SonyDevice.current_channel属性。
示例
mySonyDev.channel_set("47.1");
属性
.Name - (string)获取或设置从设备检索到的友好名称。
在初始化之前必须手动设置或从Discovery中检索。
必须与设备返回的友好名称匹配。
示例
mySonyDevice.Name="BRAVIA KDL-48W600B";
或
String DeviceName = mySonyDevice.Name;
.Generation - (Integer)获取或设置设备的代。
代表设备内置API的代(1、2或3)。
初始化时将自动设置。
手动输入错误值可能会导致不良结果。
示例
mySonyDevice.Generation = 1;
或
int x = mySonyDevice.Generation;
.Device_IP_Address - (string)获取或设置设备的IP地址。
在初始化之前必须手动设置或从Discovery中检索。
示例
mySonyDeviec.Device_IP_Address = "192.168.1.160";
或
string deviceIP = mySonyDevice.Device_IP_Address;
.Device_Macaddress - (string)获取或设置设备的MAC地址。
这仅用于第3代设备。
初始化时将自动设置。
不建议手动设置!
示例
mySonyDeivce.Device_Macaddress = "62:32:A5:F2:10:EA";
或
string deviceMac = mySonyDevice.Device_Macaddress;
.Device_Port - (Integer)获取或设置设备的端口号。
初始化时将自动设置。
不建议手动设置!
示例
mySonyDeivce.Device_Port = 8080;
或
int devicePort = mySonyDevice.Device_Port;
.Commands - (List< Command Objects >)获取或设置设备的命令列表。
这是在初始化过程中从设备检索到的Sony Command对象的列表。
每个项目将包含命令名称和命令值。
命令值是发送到设备的IRCC字符串。此列表供您使用,并由getIRCCCommandString方法使用。
要在您自己的应用程序中执行命令搜索,请使用此示例
string cmdname = "VolumeUp"; var results = mySonyDevice.Commands.FirstOrDefault(o => o.name == cmdname); string cmdValue = results.value; string results = mySonyDevice.send_IRCC(cmdValue);
.Server_Macaddress - (String)获取或设置控制设备的MAC地址。
这代表用于控制Sony设备的计算机、平板电脑或其他设备的**MAC地址**。
初始化时将自动设置。
不建议手动设置!
示例
mySonyDeivce.Server_Macaddress = "62:32:A5:F2:10:EA";
或
string ServerMac = mySonyDevice.Server_Macaddress;
.Server_Name - (String)获取或设置在注册和授权中使用的服务器名称(应用程序名称)。
在初始化之前需要设置,否则将使用默认值。
默认服务器名称是计算机名称加上API:“MyComputer(SonyAPILib)”
这代表用于控制Sony设备的计算机或应用程序**名称**。
默认值将在初始化期间自动设置。
示例
mySonyDeivce.Server_Name = "MyApplicationName";
或
string ServerName = mySonyDevice.Server_Name;
.Cookie - (String)获取或设置用于此设备认证的Cookie字符串。
包含在注册过程中保存的Cookie.Json文件的内容。
初始化时将自动设置。
不建议手动设置!
示例
mySonyDeivce.Cookie = "[{"Comment":"","CommentUri":null,"HttpOnly":false,"Discard":false,"Domain":"192.168.1.160","Expired":false,"Expires":"\/Date(1422719955623-0700)\/","Name":"auth","Path":"/sony/","Port":"","Secure":false,"TimeStamp":"\/Date(1421510355623-0700)\/","Value":"7197b5e69d4e4fab8a24a5716d7aaadd3acfafc0ba05771c454d2c170fe00a37","Version":0}]"; or string myCookie = mySonyDevice.Cookie;
.Registered - (Boolean)获取或设置是否已完成注册。
代表控制设备与Sony设备之间注册过程的状态。
初始化时将自动设置。
不建议手动设置!
示例
bool reg = mySonyDevice.Registered;
或
mySonyDevice.Registered = true;
.actionList_URL - 获取或设置设备操作列表的URL。
将包含第1代和第2代设备使用的操作列表URL。
初始化时将自动设置。
不建议手动设置!
示例
string actionList = mySonyDevice.actionlist_URL;
或
mySonyDevice.actionList_URL = "http://192.168.1.160:50001/cers/ActionList.xml";
.control_URL - 获取或设置用于发送IRCC命令的URL。
将包含IRCC控制URL。
初始化时将自动设置。
不建议手动设置!
示例
string controlURL = mySonyDevice.control_URL;
或
mySonyDevice.control_URL = "http://192.168.1.160/upnp/control/IRCC";
.current_channel - 获取或设置设备的当前频道。
在使用channel_set方法时包含当前频道。
.current_volume - 获取或设置设备的当前音量级别。
尚未使用
示例远程命令列表
这是第1代Bravia电视的示例。
<?xml version="1.0" ?>
<remoteCommandList>
<command name="Confirm" type="ircc" value="AAAAAQAAAAEAAABlAw==" />
<command name="Up" type="ircc" value="AAAAAQAAAAEAAAB0Aw==" />
<command name="Down" type="ircc" value="AAAAAQAAAAEAAAB1Aw==" />
<command name="Right" type="ircc" value="AAAAAQAAAAEAAAAzAw==" />
<command name="Left" type="ircc" value="AAAAAQAAAAEAAAA0Aw==" />
<command name="Home" type="ircc" value="AAAAAQAAAAEAAABgAw==" />
<command name="Options" type="ircc" value="AAAAAgAAAJcAAAA2Aw==" />
<command name="Return" type="ircc" value="AAAAAgAAAJcAAAAjAw==" />
<command name="Num1" type="ircc" value="AAAAAQAAAAEAAAAAAw==" />
<command name="Num2" type="ircc" value="AAAAAQAAAAEAAAABAw==" />
<command name="Num3" type="ircc" value="AAAAAQAAAAEAAAACAw==" />
<command name="Num4" type="ircc" value="AAAAAQAAAAEAAAADAw==" />
<command name="Num5" type="ircc" value="AAAAAQAAAAEAAAAEAw==" />
<command name="Num6" type="ircc" value="AAAAAQAAAAEAAAAFAw==" />
<command name="Num7" type="ircc" value="AAAAAQAAAAEAAAAGAw==" />
<command name="Num8" type="ircc" value="AAAAAQAAAAEAAAAHAw==" />
<command name="Num9" type="ircc" value="AAAAAQAAAAEAAAAIAw==" />
<command name="Num0" type="ircc" value="AAAAAQAAAAEAAAAJAw==" />
<command name="Num11" type="ircc" value="AAAAAQAAAAEAAAAKAw==" />
<command name="Num12" type="ircc" value="AAAAAQAAAAEAAAALAw==" />
<command name="Power" type="ircc" value="AAAAAQAAAAEAAAAVAw==" />
<command name="Display" type="ircc" value="AAAAAQAAAAEAAAA6Aw==" />
<command name="VolumeUp" type="ircc" value="AAAAAQAAAAEAAAASAw==" />
<command name="VolumeDown" type="ircc" value="AAAAAQAAAAEAAAATAw==" />
<command name="Mute" type="ircc" value="AAAAAQAAAAEAAAAUAw==" />
<command name="Audio" type="ircc" value="AAAAAQAAAAEAAAAXAw==" />
<command name="SubTitle" type="ircc" value="AAAAAgAAAJcAAAAoAw==" />
<command name="Yellow" type="ircc" value="AAAAAgAAAJcAAAAnAw==" />
<command name="Blue" type="ircc" value="AAAAAgAAAJcAAAAkAw==" />
<command name="Red" type="ircc" value="AAAAAgAAAJcAAAAlAw==" />
<command name="Green" type="ircc" value="AAAAAgAAAJcAAAAmAw==" />
<command name="Play" type="ircc" value="AAAAAgAAAJcAAAAaAw==" />
<command name="Stop" type="ircc" value="AAAAAgAAAJcAAAAYAw==" />
<command name="Pause" type="ircc" value="AAAAAgAAAJcAAAAZAw==" />
<command name="Rewind" type="ircc" value="AAAAAgAAAJcAAAAbAw==" />
<command name="Forward" type="ircc" value="AAAAAgAAAJcAAAAcAw==" />
<command name="Prev" type="ircc" value="AAAAAgAAAJcAAAA8Aw==" />
<command name="Next" type="ircc" value="AAAAAgAAAJcAAAA9Aw==" />
<command name="Replay" type="ircc" value="AAAAAgAAAJcAAAB5Aw==" />
<command name="Advance" type="ircc" value="AAAAAgAAAJcAAAB4Aw==" />
<command name="TopMenu" type="ircc" value="AAAAAgAAABoAAABgAw==" />
<command name="PopUpMenu" type="ircc" value="AAAAAgAAABoAAABhAw==" />
<command name="Eject" type="ircc" value="AAAAAgAAAJcAAABIAw==" />
<command name="Rec" type="ircc" value="AAAAAgAAAJcAAAAgAw==" />
<command name="SyncMenu" type="ircc" value="AAAAAgAAABoAAABYAw==" />
<command name="ClosedCaption" type="ircc" value="AAAAAgAAAKQAAAAQAw==" />
<command name="Teletext" type="ircc" value="AAAAAQAAAAEAAAA/Aw==" />
<command name="ChannelUp" type="ircc" value="AAAAAQAAAAEAAAAQAw==" />
<command name="ChannelDown" type="ircc" value="AAAAAQAAAAEAAAARAw==" />
<command name="Input" type="ircc" value="AAAAAQAAAAEAAAAlAw==" />
<command name="GGuide" type="ircc" value="AAAAAQAAAAEAAAAOAw==" />
<command name="EPG" type="ircc" value="AAAAAgAAAKQAAABbAw==" />
<command name="DOT" type="ircc" value="AAAAAgAAAJcAAAAdAw==" />
<command name="Analog" type="ircc" value="AAAAAgAAAHcAAAANAw==" />
<command name="Exit" type="ircc" value="AAAAAQAAAAEAAABjAw==" />
<command name="Digital" type="ircc" value="AAAAAgAAAJcAAAAyAw==" />
<command name="BS" type="ircc" value="AAAAAgAAAJcAAAAsAw==" />
<command name="CS" type="ircc" value="AAAAAgAAAJcAAAArAw==" />
<command name="BSCS" type="ircc" value="AAAAAgAAAJcAAAAQAw==" />
<command name="Ddata" type="ircc" value="AAAAAgAAAJcAAAAVAw==" />
<command name="InternetWidgets" type="ircc" value="AAAAAgAAABoAAAB6Aw==" />
<command name="InternetVideo" type="ircc" value="AAAAAgAAABoAAAB5Aw==" />
<command name="SceneSelect" type="ircc" value="AAAAAgAAABoAAAB4Aw==" />
<command name="Mode3D" type="ircc" value="AAAAAgAAAHcAAABNAw==" />
<command name="iManual" type="ircc" value="AAAAAgAAABoAAAB7Aw==" />
<command name="Wide" type="ircc" value="AAAAAgAAAKQAAAA9Aw==" />
<command name="Jump" type="ircc" value="AAAAAQAAAAEAAAA7Aw==" />
<command name="PAP" type="ircc" value="AAAAAgAAAKQAAAB3Aw==" />
<command name="MyEPG" type="ircc" value="AAAAAgAAAHcAAABrAw==" />
<command name="ProgramDescription" type="ircc" value="AAAAAgAAAJcAAAAWAw==" />
<command name="WriteChapter" type="ircc" value="AAAAAgAAAHcAAABsAw==" />
<command name="TrackID" type="ircc" value="AAAAAgAAABoAAAB+Aw==" />
<command name="TenKey" type="ircc" value="AAAAAgAAAJcAAAAMAw==" />
<command name="AppliCast" type="ircc" value="AAAAAgAAABoAAABvAw==" />
<command name="acTVila" type="ircc" value="AAAAAgAAABoAAAByAw==" />
<command name="DeleteVideo" type="ircc" value="AAAAAgAAAHcAAAAfAw==" />
<command name="EasyStartUp" type="ircc" value="AAAAAgAAAHcAAABqAw==" />
<command name="OneTouchTimeRec" type="ircc" value="AAAAAgAAABoAAABkAw==" />
<command name="OneTouchView" type="ircc" value="AAAAAgAAABoAAABlAw==" />
<command name="OneTouchRec" type="ircc" value="AAAAAgAAABoAAABiAw==" />
<command name="OneTouchRecStop" type="ircc" value="AAAAAgAAABoAAABjAw==" />
</remoteCommandList>
这是Bravia电视的示例JSON命令列表。
{"id":20,"result": [{"bundled":true,"type":"RM-J1100"}, [{"name":"PowerOff","value":"AAAAAQAAAAEAAAAvAw=="}, {"name":"Input","value":"AAAAAQAAAAEAAAAlAw=="}, {"name":"GGuide","value":"AAAAAQAAAAEAAAAOAw=="}, {"name":"EPG","value":"AAAAAgAAAKQAAABbAw=="}, {"name":"Favorites","value":"AAAAAgAAAHcAAAB2Aw=="}, {"name":"Display","value":"AAAAAQAAAAEAAAA6Aw=="}, {"name":"Home","value":"AAAAAQAAAAEAAABgAw=="}, {"name":"Options","value":"AAAAAgAAAJcAAAA2Aw=="}, {"name":"Return","value":"AAAAAgAAAJcAAAAjAw=="}, {"name":"Up","value":"AAAAAQAAAAEAAAB0Aw=="}, {"name":"Down","value":"AAAAAQAAAAEAAAB1Aw=="}, {"name":"Right","value":"AAAAAQAAAAEAAAAzAw=="}, {"name":"Left","value":"AAAAAQAAAAEAAAA0Aw=="}, {"name":"Confirm","value":"AAAAAQAAAAEAAABlAw=="}, {"name":"Red","value":"AAAAAgAAAJcAAAAlAw=="}, {"name":"Green","value":"AAAAAgAAAJcAAAAmAw=="}, {"name":"Yellow","value":"AAAAAgAAAJcAAAAnAw=="}, {"name":"Blue","value":"AAAAAgAAAJcAAAAkAw=="}, {"name":"Num1","value":"AAAAAQAAAAEAAAAAAw=="}, {"name":"Num2","value":"AAAAAQAAAAEAAAABAw=="}, {"name":"Num3","value":"AAAAAQAAAAEAAAACAw=="}, {"name":"Num4","value":"AAAAAQAAAAEAAAADAw=="}, {"name":"Num5","value":"AAAAAQAAAAEAAAAEAw=="}, {"name":"Num6","value":"AAAAAQAAAAEAAAAFAw=="}, {"name":"Num7","value":"AAAAAQAAAAEAAAAGAw=="}, {"name":"Num8","value":"AAAAAQAAAAEAAAAHAw=="}, {"name":"Num9","value":"AAAAAQAAAAEAAAAIAw=="}, {"name":"Num0","value":"AAAAAQAAAAEAAAAJAw=="}, {"name":"Num11","value":"AAAAAQAAAAEAAAAKAw=="}, {"name":"Num12","value":"AAAAAQAAAAEAAAALAw=="}, {"name":"VolumeUp","value":"AAAAAQAAAAEAAAASAw=="}, {"name":"VolumeDown","value":"AAAAAQAAAAEAAAATAw=="}, {"name":"Mute","value":"AAAAAQAAAAEAAAAUAw=="}, {"name":"ChannelUp","value":"AAAAAQAAAAEAAAAQAw=="}, {"name":"ChannelDown","value":"AAAAAQAAAAEAAAARAw=="}, {"name":"SubTitle","value":"AAAAAgAAAJcAAAAoAw=="}, {"name":"ClosedCaption","value":"AAAAAgAAAKQAAAAQAw=="}, {"name":"Enter","value":"AAAAAQAAAAEAAAALAw=="}, {"name":"DOT","value":"AAAAAgAAAJcAAAAdAw=="}, {"name":"Analog","value":"AAAAAgAAAHcAAAANAw=="}, {"name":"Teletext","value":"AAAAAQAAAAEAAAA/Aw=="}, {"name":"Exit","value":"AAAAAQAAAAEAAABjAw=="}, {"name":"Analog2","value":"AAAAAQAAAAEAAAA4Aw=="}, {"name":"*AD","value":"AAAAAgAAABoAAAA7Aw=="}, {"name":"Digital","value":"AAAAAgAAAJcAAAAyAw=="}, {"name":"Analog?","value":"AAAAAgAAAJcAAAAuAw=="}, {"name":"BS","value":"AAAAAgAAAJcAAAAsAw=="}, {"name":"CS","value":"AAAAAgAAAJcAAAArAw=="}, {"name":"BSCS","value":"AAAAAgAAAJcAAAAQAw=="}, {"name":"Ddata","value":"AAAAAgAAAJcAAAAVAw=="}, {"name":"PicOff","value":"AAAAAQAAAAEAAAA+Aw=="}, {"name":"Tv_Radio","value":"AAAAAgAAABoAAABXAw=="}, {"name":"Theater","value":"AAAAAgAAAHcAAABgAw=="}, {"name":"SEN","value":"AAAAAgAAABoAAAB9Aw=="}, {"name":"InternetWidgets","value":"AAAAAgAAABoAAAB6Aw=="}, {"name":"InternetVideo","value":"AAAAAgAAABoAAAB5Aw=="}, {"name":"Netflix","value":"AAAAAgAAABoAAAB8Aw=="}, {"name":"SceneSelect","value":"AAAAAgAAABoAAAB4Aw=="}, {"name":"Mode3D","value":"AAAAAgAAAHcAAABNAw=="}, {"name":"iManual","value":"AAAAAgAAABoAAAB7Aw=="}, {"name":"Audio","value":"AAAAAQAAAAEAAAAXAw=="}, {"name":"Wide","value":"AAAAAgAAAKQAAAA9Aw=="}, {"name":"Jump","value":"AAAAAQAAAAEAAAA7Aw=="}, {"name":"PAP","value":"AAAAAgAAAKQAAAB3Aw=="}, {"name":"MyEPG","value":"AAAAAgAAAHcAAABrAw=="}, {"name":"ProgramDescription","value":"AAAAAgAAAJcAAAAWAw=="}, {"name":"WriteChapter","value":"AAAAAgAAAHcAAABsAw=="}, {"name":"TrackID","value":"AAAAAgAAABoAAAB+Aw=="}, {"name":"TenKey","value":"AAAAAgAAAJcAAAAMAw=="}, {"name":"AppliCast","value":"AAAAAgAAABoAAABvAw=="}, {"name":"acTVila","value":"AAAAAgAAABoAAAByAw=="}, {"name":"DeleteVideo","value":"AAAAAgAAAHcAAAAfAw=="}, {"name":"PhotoFrame","value":"AAAAAgAAABoAAABVAw=="}, {"name":"TvPause","value":"AAAAAgAAABoAAABnAw=="}, {"name":"KeyPad","value":"AAAAAgAAABoAAAB1Aw=="}, {"name":"Media","value":"AAAAAgAAAJcAAAA4Aw=="}, {"name":"SyncMenu","value":"AAAAAgAAABoAAABYAw=="}, {"name":"Forward","value":"AAAAAgAAAJcAAAAcAw=="}, {"name":"Play","value":"AAAAAgAAAJcAAAAaAw=="}, {"name":"Rewind","value":"AAAAAgAAAJcAAAAbAw=="}, {"name":"Prev","value":"AAAAAgAAAJcAAAA8Aw=="}, {"name":"Stop","value":"AAAAAgAAAJcAAAAYAw=="}, {"name":"Next","value":"AAAAAgAAAJcAAAA9Aw=="}, {"name":"Rec","value":"AAAAAgAAAJcAAAAgAw=="}, {"name":"Pause","value":"AAAAAgAAAJcAAAAZAw=="}, {"name":"Eject","value":"AAAAAgAAAJcAAABIAw=="}, {"name":"FlashPlus","value":"AAAAAgAAAJcAAAB4Aw=="}, {"name":"FlashMinus","value":"AAAAAgAAAJcAAAB5Aw=="}, {"name":"TopMenu","value":"AAAAAgAAABoAAABgAw=="}, {"name":"PopUpMenu","value":"AAAAAgAAABoAAABhAw=="}, {"name":"RakurakuStart","value":"AAAAAgAAAHcAAABqAw=="}, {"name":"OneTouchTimeRec","value":"AAAAAgAAABoAAABkAw=="}, {"name":"OneTouchView","value":"AAAAAgAAABoAAABlAw=="}, {"name":"OneTouchRec","value":"AAAAAgAAABoAAABiAw=="}, {"name":"OneTouchStop","value":"AAAAAgAAABoAAABjAw=="}] ] }
示例代码
控制台应用程序示例
完整的示例文本,请参阅GitHub上的项目代码。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using SonyAPILib; // SonyAPILib.dll library written by Kirk Herron. // This Example Console application shows how to use the SonyAPILib in your own applications. // This API connects to Sony Smart Devices(TV, Blue Ray, Tuners) via LAN or Wifi connection. // Provides a method to send IRCC Remote control commands throught the LAN connection and remotely control the device. // Retrives the devices Remote Command list for your own use or needs. // Uses UPnP Protocols for device discovery, sending commands and future advanced features. namespace ConsoleExample { class Program { [STAThread] static void Main(string[] args) { Console.WriteLine("SonyAPILib v5.0 by: Kirk Herron"); Console.WriteLine("Starting Console Example Program"); Console.WriteLine("================================"); // 1st create new instance of the SonyAPILib // This Class will be used to Discover Sony Devices on the LAN. SonyAPI_Lib mySonyLib = new SonyAPI_Lib(); #region Set Logging // Next Set the API logging information. // Enable Logging: default is set to FALSE. mySonyLib.LOG.enableLogging = true; // Set Logging Level. // Set to "Basic" to only Log Minimum information // Set to "All" for all Logging information // Default is set to "Basic" mySonyLib.LOG.enableLogginglev = "All"; // Set where the logging file will be saved. // Folder will be created if it does not exist! // Set to Null to use Default // Default is set to C:\ProgramData\Sony mySonyLib.LOG.loggingPath = null; // Set the name of the Logging file. // Default is set to SonyAPILib_LOG.txt mySonyLib.LOG.loggingName = "SonyAPILib_LOG.txt"; // Clears the existing log file and starts a new one // Send Null as the param to just clear the file and start a new one // Enter a new File name as the param, and log file will be copied to new name before it is cleared. // Example: mySonyLib.LOG.clearlog(datestamp + "_Old_Sony_Log_File.txt"); mySonyLib.LOG.clearLog(null); #endregion #region Discovery // Perform a Discovery to find all/any compatiable devices on the LAN. // Returns a list of all Sony Devices that matches service criteria. // Send null as default service to locate Sony devices that support the IRCC service. // If a different service is used, the SonyAPILib may NOT function properly. (To be Used in Future projects) // Return value is a list with each item containg a SonyDevice object. // Each returned object will contain only the Name of the Device along with it's IP Address // All other properties will be filled in when the device is Initialized. Console.WriteLine("Searching for Devices..."); List<SonyAPI_Lib.SonyDevice> fDev = mySonyLib.API.sonyDiscover(null); #endregion // fDev.Count will return the number of devices found #region Console Output Console.WriteLine("Device Count: " + fDev.Count); Console.WriteLine("---------------------------------"); int i = 0; foreach (SonyAPI_Lib.SonyDevice fd in fDev) { Console.WriteLine(i + " - " + fd.Name); i = i + 1; } Console.WriteLine("---------------------------------"); #endregion // TODO: Here you can perform task or other code as to which device to select or use. // You could also do a For Next loop and go through each one. // This example checks if there are any devices in the list, if not then Exit if (fDev.Count > 0) { // Allow User to select from the devices found which one to test Console.WriteLine("Enter the Device # to Test"); string cki; cki = Console.ReadLine(); SonyAPI_Lib.SonyDevice mySonyDevice = new SonyAPI_Lib.SonyDevice(); // Here you can save the device information to a database or text file. // This will allow you to Initialize a device WITHOUT having to run the sonyDiscover() method every time. // Once you have discovered the devices, saving their information will speed up your application the next time you run it! // You can Initialize a device with only the following minimimal information: // 1) The Device Name - MUST Match what the device returns as it's name. (selDev.Name) // 2) The IP address of the device. (selDev.Device_IP_Address) // Now we initialize a new sonyDevice object with the selected device above. #region initialize // The Initialize method is used to fill in all the other required properties for the device. // For example, during the Initiliation process, the device port, mac, command list and UPnP services are // discovered and set to the device object. // Also the Registered porperty is checked during this process. // However, on Generation 1 devices, this will return a false value if the device is not powered ON. // See Wiki page on GitHub for more information about the Initialize method. // You MUST perform an Initialize on the device before doing anything else! // From above, selDev or each item in the list fDev[] is a SonyDevice object. // To initialize with the default information retrieved from sonyDiscovery, use the following method: // mySonyDevice.initialize(fDev[1]) or by setting the index to the device you wish. // You can also manually initialize the sonyDevice by setting the device information yourself. // To manually initialize without using sonyDiscovery, use the following method: // mySonyDevice.Name = "NameOfMySonyDevice"; // mySonyDevice.Device_IP_Address = "192.168.0.66"; // mySonyDevice.Server_Name = "TheNameOfMyApplication"; // mySonyDevice.initialize(); // This information could be retrieved from a database or other file as your desire. // This example will use the first method to initialize the device chosen by the user. Console.WriteLine(""); Console.WriteLine(fDev[Convert.ToInt32(cki)].Name + ": Performing Initilization...."); mySonyDevice.initialize(fDev[Convert.ToInt32(cki)]); #endregion // Next we will check the status of the device. #region Check Status //The following will return the current status of the device //The value returned is: status_name:value //An example would be: viewing:TV //An emplty string "" will be returned if there is no response from the device. This could also mean the device is off. //Also, this method requires the device to be registered on Generation 1 and 2 devices. Console.WriteLine(mySonyDevice.Name + ": Checking Device Status...."); string status = mySonyDevice.checkStatus(); if (status == "" | status == null) { // NO Response!! } else { #region Console Output Console.WriteLine(""); Console.WriteLine("Get Status returned: " + status); Console.WriteLine("---------------------------------"); Console.WriteLine(""); #endregion } #endregion // Now we must register with the device #region register bool mySonyReg = false; // first check to see if the initize process determined the registration value. if (mySonyDevice.Registered == false) { Console.WriteLine(mySonyDevice.Name + ": Performing Registration...."); Console.WriteLine("Before continuing, you may need to set the device to Registration Mode,"); Console.WriteLine("Confirm Registration or enter the Registration PIN code."); Console.WriteLine("Go to the device and perfrom any step, or be ready to before ehitting enter below!"); Console.WriteLine("====================================="); Console.WriteLine("Hit any key to continue"); Console.ReadKey(); // The next method is very IMPORTANT. // YOU MUST RUN THE FOLLOWING METHOD AND RECEIVE A SUCCESSFUL RETURN at least ONCE! // Before you can send any IRCC commands or receive and data back from the device! // The very first time this is executed, you will need to be at your device (TV, Blue Ray) // to confim the registration. Also, some devices (Blue Ray, Home Theater Tuners) require you to put // the device in to "Registration" mode, before you try to register this application as // a controlling device. (Registration uses the MAC address of the computer/device trying //to gain control). If installed on more than 1 computer, each one will require registration. // Register as Controller // Returns true if successful // Returns false if not successful mySonyReg = mySonyDevice.register(); // Check if register returned false if (mySonyDevice.Registered == false) { //Check if Generaton 3. If yes, prompt for pin code if (mySonyDevice.Generation == 3) { string ckii; Console.WriteLine("Enter PIN Code."); ckii = Console.ReadLine(); // Send PIN code to TV to create Autorization cookie Console.WriteLine("Sending Authitication PIN Code."); mySonyReg = mySonyDevice.sendAuth(ckii); } } } else { mySonyReg = true; } #endregion //TODO: Add more code in case of false, or true #region Console Output Console.WriteLine("Registration returned: " + mySonyReg.ToString()); Console.WriteLine("---------------------------------"); Console.WriteLine(""); #endregion // This example will: If true, display device information #region Console Output if (mySonyReg) { Console.WriteLine("Device Information"); Console.WriteLine("Mame: " + mySonyDevice.Name); Console.WriteLine("Mac Address: " + mySonyDevice.Device_Macaddress); Console.WriteLine("IP Address: " + mySonyDevice.Device_IP_Address); Console.WriteLine("Port: " + mySonyDevice.Device_Port); Console.WriteLine("Generation: " + mySonyDevice.Generation); Console.WriteLine("Registration: " + mySonyDevice.Registered.ToString()); Console.WriteLine("Server Name: " + mySonyDevice.Server_Name); Console.WriteLine("Server Mac: " + mySonyDevice.Server_Macaddress); Console.WriteLine("Action List URL: " + mySonyDevice.actionList_URL); Console.WriteLine("IRCC Control URL: " + mySonyDevice.control_URL); Console.WriteLine("---------------------------------"); Console.WriteLine(""); } else { // Display this if NOT true Console.WriteLine("There was an error"); Console.WriteLine("---------------------------------"); Console.WriteLine(""); } #endregion // Get the IRCC command list from the device so we know it's capabilities. #region get_remote_command_list // The next command is used to retrieve the IRCC command list from the device. // ### You must register before this method will return any data ### // This method will populate the Commands list in the SonyDevice object when executed. // This Methed also returnes a string that contains the contents of the Devices Command List XML file for your own use. Console.WriteLine(mySonyDevice.Name + ": Retrieving Remote Command List"); string CmdList = mySonyDevice.get_remote_command_list(); // TODO: Parse this information as your application requires. // convert to an XMLDocument or dataset for your own use #endregion // Checks if the list contains any data #region Console Output if (CmdList != "") { Console.WriteLine("Retrieved Command List Successful"); Console.WriteLine("---------------------------------"); Console.WriteLine(""); } else { Console.WriteLine("ERROR Retrieving Command List"); Console.WriteLine("---------------------------------"); Console.WriteLine(""); } #endregion // Get the IRCC command value by searching the command name #region getIRCCcommandString // The next method is used to search for an IRCC_Command that matches the param. // param is a string containing the command name to search for. // Returns a string containing the command's value (If Successful) // Returna a Null if the search command is not found in the devices IRCC command list // This example will search for the command "ChannelUp" Console.WriteLine(mySonyDevice.Name + ": Retrieving Command Value for: VolumeUp"); string irccCmd = mySonyDevice.getIRCCcommandString("VolumeUp"); //Check if command was found if (irccCmd == "") { Console.WriteLine("Command Not Found: VolumeUp"); } else { #endregion // Displays the IRCC command value retrieved #region Console Output // Show the IRCC_Command value found information Console.WriteLine("Found Command: VolumeUp"); Console.WriteLine("Command Value: " + irccCmd); Console.WriteLine("---------------------------------"); Console.WriteLine(""); Console.WriteLine("Now we are ready to try to send a few IRCC commands to the device"); Console.WriteLine("Hit any key to continue"); Console.ReadKey(); } #endregion // Next are 4 examples of how you can send the IRCC commands to the device #region Example 1 // This first example will send a "VolumeUp" command value to the device // it asumes we already know the value to send to the device. // We will use the irccCmd we retrieved above in the getIRCCCommandString method. Console.WriteLine(mySonyDevice.Name + ": Sending Command Value " + irccCmd + " to device"); string results = mySonyDevice.send_ircc(irccCmd); System.Threading.Thread.Sleep(500); // give the device time to react before sending another command #region Console Output // Show the IRCC_Command value found information Console.WriteLine("Sent Command: VolumeUp:" + irccCmd); Console.WriteLine("Hit any key to continue"); Console.WriteLine("---------------------------------"); Console.ReadKey(); #endregion #endregion #region Example 2 // The next example will use the getIRCCcommandString("CommandName") method to get the command value for "VolumeDown". // Then send it to the device Console.WriteLine(mySonyDevice.Name + ": Sending Command VolumeDown to device"); String mycommand = mySonyDevice.getIRCCcommandString("VolumeDown"); mySonyDevice.send_ircc(mycommand); System.Threading.Thread.Sleep(500); // give the device time to react before sending another command #region Console Output // Show the IRCC_Command value found information Console.WriteLine("Sent Command: VolumeDown:" + mycommand); Console.WriteLine("Hit any key to continue"); Console.WriteLine("---------------------------------"); Console.ReadKey(); #endregion #endregion #region Example 3 // The next example will use a combination of both examples above for the command "VolumeUp". Console.WriteLine(mySonyDevice.Name + ": Sending Command VolumeUp to device again"); mySonyDevice.send_ircc(mySonyDevice.getIRCCcommandString("VolumeUp")); System.Threading.Thread.Sleep(500); // give the device time to react before sending another command #region Console Output // Show the IRCC_Command value found information Console.WriteLine("Sent Command: VolumeUp:" + mycommand); Console.WriteLine("Hit any key to continue"); Console.WriteLine("---------------------------------"); Console.ReadKey(); #endregion #endregion #region Example 4 // The next example will use the "channel_set" method to send a complete channel number. // This example will use channel 47.1 since it is a valid station in my area. You can change this to what ever you need to. // This example should only be used on TV's, as Home theater systems and DVD players will not respond to this! Console.WriteLine(mySonyDevice.Name + ": Sending a Set Channel command to device, if device is a TV"); string checkChannel = mySonyDevice.getIRCCcommandString("ChannelUp"); if (checkChannel != "") { mySonyDevice.channel_set("47.1"); System.Threading.Thread.Sleep(500); // give the device time to react before sending another command } #region Console Output // Show the Set Channel Information if (checkChannel != "") { Console.WriteLine("Sent Command: Channel_Set"); Console.WriteLine("Command Value: " + mySonyDevice.current_Channel); } else { Console.WriteLine("Set Channel Not sent, Device is NOT a TV!"); } #endregion #endregion #region Example 5 Console.WriteLine(""); Console.WriteLine("Now You Try."); Console.WriteLine("Here are the Commands: Hit any key to Continue."); Console.WriteLine("---------------------------------"); Console.ReadKey(); foreach (SonyAPI_Lib.SonyCommands cmd in mySonyDevice.Commands) { Console.WriteLine(cmd.name); } Console.WriteLine("---------------------------------"); Console.WriteLine("Enter a command from the list above."); cki = Console.ReadLine(); results = mySonyDevice.send_ircc(mySonyDevice.getIRCCcommandString(cki)); #endregion #region Example 6 Console.WriteLine("---------------------------------"); Console.WriteLine("Now, using your TV remote control, navigate to a search screen."); Console.WriteLine("This can be Pandora, Youtube or any search where you enter TEXT."); Console.WriteLine("Now, enter the text here to send."); cki = Console.ReadLine(); results = mySonyDevice.send_text(cki); Console.WriteLine("---------------------------------"); #endregion Console.WriteLine("That's about it for now. Hit enter to Quit."); Console.ReadKey(); } else { Console.WriteLine("Error: No Devices were found!"); Console.ReadKey(); } } } }
关注点
在您自己的应用程序中使用此API进行家庭自动化,或仅通过计算机、平板电脑或其他设备控制您的Sony设备!
历史
最新版本是5.0
要报告任何问题,请访问https://github.com/KHerron/SonyAPILib/issues