Rotel RSP-1570处理器异步RS-232协议

rsp1570serial-pp81381的Python项目详细描述


RSp1570串行

使用RS-232协议与Rotel RSP-1570处理器通信的基于异步的包

有关协议定义,请参见this document

已知在Windows 10(Python3.7.0)和Rapbian Stretch(Python3.5.3)上使用GANA USB到RS-232 DB9电缆。

该方案类似于其他旧的Rotel试剂盒。例如,看起来rsp-1572使用了这样的协议。它有一个不同的设备ID,并且支持更多的消息,但是这个包可能会被更新以支持它。

这个库是为支持Home Assistant的rotel rsp1570媒体播放器平台实体而构建的,可以找到here

用法

rotempConn对象封装了库的所有功能:

fromrsp1570serial.connectionimportRotelAmpConntry:conn=RotelAmpConn(serial_port)awaitconn.open()except:logging.error("Could not open connection",exc_info=True)else:# Do something hereconn.close()

串行端口参数可以是任何可以传递给serial.serial_for_url()的参数。例如

  • /dev/ttyUSB0(Linux)
  • COM3(窗口)
  • socket://192.168.0.100:50000(如果使用的是tcp/ip到串行转换器)

发送命令(有关完整列表,请参见commands.py):

awaitconn.send_command('MUTE_TOGGLE')

向区域发送volume direct命令:

fromrsp1570serial.commandsimportMIN_VOLUME,MAX_VOLUMEzone=1awaitconn.send_volume_direct_command(zone,MAX_VOLUME)awaitasyncio.sleep(1)awaitconn.send_volume_direct_command(zone,MIN_VOLUME)awaitasyncio.sleep(1)awaitconn.send_volume_direct_command(zone,50)

从设备读取输入流:

asyncformessageinconn.read_messages():if(isinstance(message,(FeedbackMessage,TriggerMessage))):message.log()else:logging.warning("Unknown message type encountered")

请参阅example1.py和example2.py以获取完整的工作示例。

conn.read_messages()将返回包含消息数据的特定于消息类型的对象。可以遇到两种类型的消息:

  • FeedbackMessage:反映前面板显示的内容。显示改变时接收。
  • TriggerMessage:每当12v触发器改变状态时接收。

反馈消息

此消息反映设备显示器上显示的内容,并将在显示器更改时接收。这通常是在接收到RS-232或红外命令或按下前面板按钮之后。

对象有3个属性:

PropertyTypeDescription
^{}two element listThe two lines of the display
^{}bytesFlags representing the state of the icons on the display
^{}dict of str:boolA dictionary keyed on icon code reflecting the on/off state of each icon

感兴趣的方法是:

MethodDescription
^{}Returns a list of the icon codes of any display icons that are on. Primarily used for testing and debugging.
^{}Parse the display lines and return as much as we can infer about the state of the amp in a dict.

下表显示了parse_display_lines()方法返回的dict的内容。

KeyDescription
^{}On flag (bool)
^{}Source Name (max. 8 characters)
^{}Volume (int)
^{}Mute On Flag (bool),
^{}Party Mode Flag (bool)
^{}Display Line 2

下表显示了所有图标代码。

CodeNameCategoryFriendly Name
^{}^{}^{}Analog
^{}^{}^{}Input 5
^{}^{}^{}Input 4
^{}^{}^{}Input 3
^{}^{}^{}Input 2
^{}^{}^{}Input 1
^{}^{}^{}Coaxial
^{}^{}^{}Optical
^{}^{}^{}HDMI
^{}^{}^{}Pro Logic
^{}^{}^{}II
^{}^{}^{}x
^{}^{}^{}Dolby Digital
^{}^{}^{}EX
^{}^{}^{}dts
^{}^{}^{}ES
^{}^{}^{}7.1
^{}^{}^{}5.1
^{}^{}^{}Display Mode 0
^{}^{}^{}Display Mode 1
^{}^{}^{}Standby LED
^{}^{}^{}Zone 2
^{}^{}^{}Zone 3
^{}^{}^{}Zone 4
^{}^{}^{}Zone
^{}^{}^{}Front Right
^{}^{}^{}Center
^{}^{}^{}Front Left
^{}^{}^{}Subwoofer
^{}^{}^{}Surround Right
^{}^{}^{}Surround Left
^{}^{}^{}Center Back Left
^{}^{}^{}Center Back Right
^{}^{}^{}Center Back
^{}^{}^{}Misc <
^{}^{}^{}Misc >

TriggerMessage

此对象有一个名为flags、类型为bytes的属性,该属性按区域反映12V触发器的状态。

方法flags_to_list()返回以下形式的列表:

[['All',['on','off','off','off','off','off']],['Main',['on','off','off','off','off','off']],['Zone 2',['off','off','off','off','off','off']],['Zone 3',['off','off','off','off','off','off']],['Zone 4',['off','off','off','off','off','off']],]

模拟器

该软件包还包括一个rsp-1570模拟器,可用于演示或测试目的。

用法示例:

# Start the emulator on port 50000
python3 -m rsp1570serial.emulator

# Start the emulator on port 50002
python3 -m rsp1570serial.emulator -p 50002

# Start the emulator on port 50002 and provide aliases for some of the sources
python3 -m rsp1570serial.emulator -p 50002 --alias_video_1  CATV --alias_video_2 NMT --alias_video_3 "APPLE TV" --alias_video_4 "FIRE TV" --alias_video_5 "BLU RAY"

# Start the emulator in the on state
python3 -m rsp1570serial.emulator --is_on

选项的完整列表:

OptionDescription
^{} or ^{}Port number
^{} or ^{}If set then the emulator will be turned on initially
^{} or ^{}Alias for the CD source
^{} or ^{}Alias for the TAPE source
^{} or ^{}Alias for the TUNER source
^{} or ^{}Alias for the VIDEO 1 source
^{} or ^{}Alias for the VIDEO 2 source
^{} or ^{}Alias for the VIDEO 3 source
^{} or ^{}Alias for the VIDEO 4 source
^{} or ^{}Alias for the VIDEO 5 source
^{} or ^{}Alias for the MULTI source

该仿真器可用于家庭助理与Rotel_RSp1570媒体播放器平台。配置示例:

media_player:-platform:rotel_rsp1570name:"RotelRSP-1570emulator"device:socket://192.168.2.119:50002source_aliases:VIDEO 1:CATVVIDEO 2:NMTVIDEO 3:APPLE TVVIDEO 4:FIRE TVVIDEO 5:BLU RAY

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java提供了大量的Quartz工作线程   来自SOAPException的java抛出超时异常   java通过REST web服务同步PostgreSQL过程调用   java Hibernate:在关联表中设置值   javaimapidlechanneladapterjavax。邮政AuthenticationFailedException:[警报]同时连接太多   JavaApacheStorm:stormkafkamonitor脚本引发异常   java将jar链接到战争   Matlab与Java的集成方法   安卓公司。谷歌。ads.AdView未能实例化java。lang.ClassNotFoundException:org。json。JSONException   “String forecastStr=mForecastAdapter.getItem(position);”行中出现java错误阳光工程   java如何将Mono中的列表属性作为流量进行操作?   java DecimalFormat类不必要地给出整数   java@IfProfileValue两个spring配置文件   java如何使用SwingWorker创建多线程?   java从扩展SwingWorker的内部类触发事件   java二叉树高度实现