一种基于python的socket客户机,用于通过CIP与快思聪控制处理器通信。

python-cipclient的Python项目详细描述


python cipclient

LicensePyPIPython VersionPyPI - WheelBlackIssues

一个Python模块,用于通过 Crestron over IP(CIP)协议。在


注意:本模块不是由快思聪电子公司生产、认可、维护或支持的XPanel、Smart Graphics和simplwindows都是快思聪的商标。作者与快思聪没有任何关系,除了拥有和使用他们的一些硬件。

这是一个基于Python的socket客户机,使用Crestron over IP(CIP)协议促进与快思聪控制处理器的通信。熟悉并使用快思聪的开发工具、流程和术语,才能以允许使用该模块的方式配置控制处理器。在

安装

此模块可通过Python Package Index获得,并可使用pip包管理系统进行安装:

pip install python-cipclient

用法和API

此模块通过连接到simplwindows程序中定义的“xpanel2.0智能图形”符号来工作。一旦控制处理器被相应地编程,您就可以使用下面描述的API与它通信。在

入门

下面是一个简单的示例,演示如何使用此模块设置和获取连接状态。在

importcipclient# set up the client to connect to hostname "processor" at IP-ID 0x0Acip=cipclient.CIPSocketClient("processor",0x0A)# initiate the socket connection and start worker threadscip.start()# you can force this client and the processor to resync using an update requestcip.update_request()# note that this also occurs automatically on first connection# for joins coming from this client going to the processorcip.set("d",1,1)# set digital join 1 highcip.set("d",132,0)# set digital join 132 lowcip.set("a",12,32456)# set analog join 12 to 32456cip.set("s",101,"Hello Crestron!")# set serial join 101 to "Hello Crestron!"cip.pulse(2)# pulses digital join 2 (sets it high then immediately sets it low again)cip.press(3)# emulates a touchpanel button press on digital join 3 (stays high until released)cip.release(3)# emulates a touchpanel button release on digital join 3# for joins coming from the processor going to this clientdigital_34=cip.get("d",34)# returns the current state of digital join 34analog_109=cip.get("a",109)# returns the current state of analog join 109serial_223=cip.get("s",223)# returns the current state of serial join 223# you should really subscribe to incoming (processor > client) joins rather than pollingdefmy_callback(sigtype,join,state):print(f"{sigtype}{join} : {state}")cip.subscribe("d",1,my_callback)# run 'my_callback` when digital join 1 changes# this will close the socket connection when you're finishedcip.stop()

详细说明

在实例化CIPSocketClient之后,应该调用一次start(),以启动套接字连接并启动所需的工作线程。当第一次建立套接字连接时,将自动执行标准CIP注册和更新请求过程。在

完成CIPSocketClient后,应调用一次stop(),以关闭套接字连接并关闭工作线程。在

连接时可以使用update_request()来启动更新请求(双向同步)过程。在

set(sigtype, join, value)用于设置控制处理器看到的来自CIPSocketClient的连接的状态。sigtype可以是"d"用于数字连接,"a"用于模拟连接,或{}用于串行连接。join是连接号。value对于数字连接可以是0或{},对于模拟连接,0-65535对于串行连接,可以是字符串。在

press(join)使用特殊的CIP处理将数字join设置为高,如果连接断开或意外超时,连接应自动重置为低状态。在

release(join)设置数字join低。与press()结合使用。在

pulse(join)通过将连接设置为高,然后立即再次将其设置为低,在数字join上发送一个瞬时脉冲。在

get(sigtype, join, direction="in")返回指定联接在CIPSocketClient的状态机中时的当前状态。(连接更改总是在更改时从控制处理器发送到客户端。客户机跟踪所有传入消息并将每个连接的当前状态存储在其状态机中。)sigtype可以是"d""a"或{},用于数字、模拟或串行信号。join是连接号。direction是一个可选参数,默认设置为"in",以检索传入联接的状态。如果需要获取从客户端发送到控制处理器的连接的最后状态,可以指定direction="out"。在

subscribe(sigtype, join, callback, direction="in")用于指定一个回调函数,该函数应在指定的联接更改状态时调用。sigtypejoin和{}的功能与上述get方法相同。callback是每次更改时应调用的函数的名称。sigtypejoin和{}将按该顺序传递给指定的回调。请参阅上面的Getting Started部分中的示例。在

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

推荐PyPI第三方库


热门话题
java Eclipse内存分析器(MAT):不显示当前正在运行的进程   java Apache Velocity:转义字符不能作为关联数组键用于PHP   不截断零的java格式十进制输出   在另一个类文件中调用时返回空值的java getter   java集合获取连接   java解析json使用Gson登录系统应用程序强制关闭   java DelferredResult带有两个请求的ajax请求   java可降低功耗,同时应使用无线   java BoxLayout无法共享错误?   java如何使用计时器制作闹钟   java使用OAuth2保护RESTWeb服务:一般原则   java在一个jframe上显示多个图像和按钮