-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelay_server.py
executable file
·40 lines (34 loc) · 1.05 KB
/
relay_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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os,sys
import Pyro4
# add ../../Sources to the PYTHONPATH
sys.path.append(os.path.join("..","..","Sources"))
from yocto_api import *
from yocto_relay import *
class relay(object):
def __init__(self):
errmsg=YRefParam()
if YAPI.RegisterHub("usb", errmsg)!= YAPI.SUCCESS:
sys.exit("init error"+errmsg.value)
self.relay = YRelay.FirstRelay()
if self.relay is None: sys.exit('no device connected')
if not(self.relay.isOnline()):sys.exit('device not connected')
@Pyro4.expose
@property
def state(self):
return self.relay.get_state()
def set_state(self,val):
if val:
self.relay.set_state(YRelay.STATE_B)
else:
self.relay.set_state(YRelay.STATE_A)
def switch(self):
self.state = not self.state
daemon = Pyro4.Daemon(host='muffin')
ns = Pyro4.locateNS()
uri = daemon.register(relay())
ns.register("relay", uri)
print("server object uri:", uri)
print("attributes server running.")
daemon.requestLoop()