Package: python-cipclient
python-cipclientA Python module for communicating with Crestron control processors via the
Crestron-over-IP (CIP) protocol.NOTICE: This module is not produced, endorsed, maintained or supported by Crestron Electronics Incorporated. 'XPanel', 'Smart Graphics' and 'SIMPL Windows' are all trademarks of Crestron. The author is not affiliated in any way with Crestron with the exception of owning and using some of their hardware.This is a Python-based socket client that facilitates communications with a Crestron control processor using the Crestron-over-IP (CIP) protocol. Familiarity with and access to Crestron's development tools, processes and terminology are required to configure the control processor in a way that allows this module to be used.InstallationThis module is available throught thePython Package Index, and can be installed using the pip package-management system:pip install python-cipclientUsage and APIThis module works by connecting to an "XPanel 2.0 Smart Graphics" symbol defined in a SIMPL Windows program.  Once the control processor has been programmed accordingly, you can communicate with it using the API as described below.Getting StartedHere is a simple example that demonstrates setting and getting join states using this module.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()Detailed Descriptionsstart()should be called once after instantiating a CIPSocketClient to initiate the socket connection and start the required worker threads.  When the socket connection is first established, the standard CIP registration and update request procedures are performed automatically.stop()should be called once when you're finished with the CIPSocketClient to close the socket connection and shut down the worker threads.update_request()can be used while connected to initiate the update request (two-way synchronization) procedure.set(sigtype, join, value)is used to set the state of joins coming from the CIPSocketClient as seen by the control processor.sigtypecan be"d"for digital joins,"a"for analog joins or"s"for serial joins.joinis the join number.valuecan be0or1for digital joins,0-65535for analog joins or a string for serial joins.press(join)sets digitaljoinhigh using special CIP processing intended for joins that should be automatically reset to a low state if the connection is broken or times out unexpectedly.release(join)sets digitaljoinlow.  Used in conjunction withpress().pulse(join)sends a momentary pulse on digitaljoinby setting the join high then immediately setting it low again.get(sigtype, join, direction="in")returns the current state of the specified join as it exists within the CIPSocketClient's state machine.  (Join changes are always sent from the control processor to the client at the moment they change.  The client tracks all incoming messages and stores the current state of every join in its state machine.)sigtypecan be"d","a"or"s"for digital, analog or serial signals.joinis the join number.directionis an optional argument, which is set to"in"by default to retrieve the state of incoming joins.  If you need to get the last state of a join that was sent from the client to the control processor, you can specifydirection="out".subscribe(sigtype, join, callback, direction="in")is used to specify a callback function that should be called any time the specified join changes state.sigtype,joinanddirectionfunction the same as in thegetmethod described above.callbackis the name of the function that should be called on each change.sigtype,joinandstatewill be passed to the specified callback in that order.  See the example above in theGetting Startedsection.