Mercurial > code > home > repos > light9
annotate light8/dmxclient.py @ 206:851cf44cea40
rename clientid and allow it as an argument
author | drewp |
---|---|
date | Sun, 10 Apr 2005 15:13:48 +0000 |
parents | 238eede02bf9 |
children |
rev | line source |
---|---|
0 | 1 """ module for clients to use for easy talking to the dmx |
2 server. sending levels is now a simple call to | |
3 dmxclient.outputlevels(..) | |
4 | |
5 client id is formed from sys.argv[0] and the PID. """ | |
6 | |
7 import xmlrpclib,os,sys,socket,time | |
198
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
8 from twisted.web.xmlrpc import Proxy |
0 | 9 _dmx=None |
10 | |
11 _id="%s-%s" % (sys.argv[0].replace('.py','').replace('./',''),os.getpid()) | |
12 | |
206 | 13 def outputlevels(levellist,twisted=0,clientid=_id): |
0 | 14 """present a list of dmx channel levels, each scaled from |
15 0..1. list can be any length- it will apply to the first len() dmx | |
16 channels. | |
17 | |
18 if the server is not found, outputlevels will block for a | |
19 second.""" | |
20 | |
21 global _dmx,_id | |
22 | |
23 if _dmx is None: | |
167 | 24 host = os.getenv('DMXHOST', 'localhost') |
198
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
25 url = "http://%s:8030" % host |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
26 if not twisted: |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
27 _dmx=xmlrpclib.Server(url) |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
28 else: |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
29 _dmx = Proxy(url) |
0 | 30 |
198
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
31 if not twisted: |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
32 try: |
206 | 33 _dmx.outputlevels(clientid,levellist) |
198
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
34 except socket.error,e: |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
35 print "dmx server error %s, waiting"%e |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
36 time.sleep(1) |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
37 except xmlrpclib.Fault,e: |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
38 print "outputlevels had xml fault: %s" % e |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
39 time.sleep(1) |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
40 else: |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
41 def err(error): |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
42 print "dmx server error",error |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
43 time.sleep(1) |
206 | 44 d = _dmx.callRemote('outputlevels',clientid,levellist) |
198
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
45 d.addErrback(err) |
238eede02bf9
supports using twisted/deferreds for the xmlrpc connection
drewp
parents:
167
diff
changeset
|
46 |
0 | 47 |
167 | 48 dummy = os.getenv('DMXDUMMY') |
49 if dummy: | |
50 print "dmxclient: DMX is in dummy mode." | |
51 def bogus(*args): | |
52 pass | |
53 outputlevels = bogus |