-
Notifications
You must be signed in to change notification settings - Fork 0
/
stepper_server.py
executable file
·76 lines (58 loc) · 2 KB
/
stepper_server.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from stepper import Stepper
from config import Config
from pyfirmata import Arduino, util
from gpiozero import DigitalOutputDevice
import Pyro4
Pyro4.config.REQUIRE_EXPOSE = False
# NOTE: must have nameserver running on same device
# for example: `python -m Pyro4.naming -n 192.168.0.46 -p 1234`
@Pyro4.expose
class StepperServer(Stepper):
def __init__(self, syringe='3ml', mode='rpi', port=None):
Stepper.__init__(self, port=port, syringe=syringe)
# self.arduino = Arduino(port)
print('running stepper server')
print('usb port = {}'.format(port))
print('syringe = {}'.format(syringe))
@Pyro4.oneway
def deliver_reward(self, volume):
'''
a one-way (non-blocking) method for delivering a reward
'''
self.dispense(volume)
@Pyro4.expose
def get_step_count(self):
return self.step_count
@Pyro4.expose
def set_step_count(self,value):
self.step_count = value
@Pyro4.expose
def get_volume_dispensed(self):
return self.volume_dispensed
@Pyro4.expose
def set_volume_dispensed(self,value):
self.volume_dispensed = 0
@Pyro4.expose
def get_max_limit(self):
return self.max_limit
@Pyro4.expose
def get_min_limit(self):
return self.min_limit
if __name__ == '__main__':
config = Config()
server = StepperServer(
syringe=config.syringe,
mode=config.mode,
)
daemon = Pyro4.Daemon(config.ip) # make a Pyro daemon
ns = Pyro4.locateNS() # find the name server
print("nameserver = {}".format(ns))
# register the stepper server as a Pyro object
uri = daemon.register(server)
# register the object with a name in the name server
ns.register(config.servername, uri)
# print("The daemon runs on port: {}".format(daemon.port))
print("The object's uri is: {}".format(uri))
print("Ready.")
# start the event loop of the server to wait for calls
daemon.requestLoop()