Esempio n. 1
0
LZERO = long(0)
DZERO = double(0)
cInstCheckForWLM = long(-1)
cInstResetCalc = long(0)
cInstReturnMode = cInstResetCalc
cInstNotification = long(1)
cInstCopyPattern = long(2)
cInstCopyAnalysis = cInstCopyPattern
cInstControlWLM = long(3)
cInstControlDelay = long(4)
cInstControlPriority = long(5)


# # print wlm.Instantiate(cInstResetCalc, LZERO, LZERO, LZERO)
# print wlm.Instantiate(cInstReturnMode, long(0), LZERO, LZERO)

getfreq = wlm.GetFrequency
getfreq.restype = double

while True:
    try:
        freq = getfreq(DZERO)
        out = {"wavelength" : { "channel": 3, "value": freq}}
        print out
        s.emit('message', out)
        # sleep(0.001)
    except (KeyboardInterrupt):
        print("Stopping")
        break
Esempio n. 2
0
class RemoteClient(asyncore.dispatcher):

    def __init__(self, host, path, rQ, sQ, switch):
        asyncore.dispatcher.__init__(self)
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.connect(('localhost', port))  # needs it on windows otherwise doesn't write
        self.mysocket = SocketIO('localhost', port)
        self.rQ = rQ
        self.sQ = sQ
        self.switch = switch

    def handle_connect(self):
        logger.debug("RC connected")
        pass

    def handle_close(self):
        logger.debug("RC Closing")

    def readable(self):
        """ Check if data is readable """
        workaround = True
        # workaround = os.name in ['nt']
        reading = not workaround
        # logger.debug("RC checking readable, %s", reading)
        if workaround:
            # call manually the read function, because somehow
            # on Windows this doesn't get called even if the
            # function returns True
            self.handle_read()
        return reading

    def handle_read(self):
        logger.debug("RC reading data")
        try:
            data = self.mysocket.recv()
            try:
                splits = data.split(":")
                idnum = int(splits[0])
                if idnum == 5:
                    try:
                        realdata = json.loads(":".join(splits[3:]))
                        print "Realdata", realdata
                        if realdata['name'] == 'settings':
                            channels = []
                            for k in realdata['args'][0]:
                                channels += [(realdata['args'][0][k])]
                            self.sQ.put({'channels' : channels})
                    except:
                        raise
            except:
                raise
        except(socket.timeout):
            pass

    def writable(self):
        logger.debug("RC checking writable, %s", (not self.rQ.empty()))
        return not self.rQ.empty()

    def handle_write(self):
        logger.debug("RC writing data")
        while not self.rQ.empty():
            self.mysocket.emit('message', self.rQ.get())