-
Notifications
You must be signed in to change notification settings - Fork 10
Signals in labrad
Hlab edited this page May 30, 2013
·
8 revisions
Import Signal class
from labrad.server import Signal
#Create Signal object.
onEvent = Signal( ID, signal name, data_type)
#i.e ID = 543617
#name = 'signal: interesting information acquired'
#info_type = 'i' for integer data
#Note this has to be done as a global class variable, i.e
class ourserver( LabradServer):
onEvent = ...
...
def initServer(self):
...
onEvent( data, listeners)
#i.e data = 34
#i.e listeners = None if message is sent to everyone listening
#or listeners = set(context.ID) to send to a particular listener of that context
Even if signal requires no parameters, still need to do self.onEvent(None).
import labrad
from labrad.wrappers import connectAsync
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet import reactor
@inlineCallbacks
def connect():
def printSignal(x,y):
print x,y
reactor.stop()
cxn = yield connectAsync()
server = yield cxn.data_vault
#context = yield cxn.context()
yield dv.signal__new_dataset(99901)#, context = context)
yield dv.addListener(listener = printSignal, source = None, ID = 99901)#, context = context)
print 'now listening'
reactor.callWhenRunning(connect)
reactor.run()