forked from shaunhogan/gui-step1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.py
46 lines (39 loc) · 1.47 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
#
#client.py
#client /library/ with which to send commands to server
#websocket (install websocket-client)
from websocket import create_connection
################################################################################
# webBus class
################################################################################
class webBus:
def __init__(self, serverAddress = "pi5", VERBOSITY = 2):
self.VERBOSITY = VERBOSITY
self.messages = []
a = "ws://%s:1738/ws" % serverAddress
self.ws = create_connection(a)
def read(self, address, numbytes):
m = "r %i %i" % (address, numbytes)
self.messages.append(m)
def write(self, address, byteArray):
m = "w %i " % address
for h in byteArray:
m += str(h) + " "
self.messages.append(m)
def sleep(self, n):
m = "s %i" % n
self.messages.append(m)
def sendBatch(self):
self.ws.send('|'.join(self.messages))
ret = self.ws.recv().split('|')
if self.VERBOSITY >= 1:
for e in xrange(len(self.messages)):
print "SENT: %s" % self.messages[e]
print "RECEIVED: %s" % ret[e]
self.messages = []
return ret
################################################################################
if __name__ == "__main__":
print "What you just ran is a library."
print "Correct usage is to import this file and use its class(es) and functions."