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
from __future__ import division from time import sleep from random import gauss, shuffle from socketIO import SocketIO s = SocketIO('localhost', 3000) """ Driver module for NI USB-6259 DAQ """ import ctypes import numpy from time import sleep wlm = ctypes.windll.wlmData # load the DLL int32 = ctypes.c_long uInt32 = ctypes.c_ulong uInt64 = ctypes.c_ulonglong float64 = ctypes.c_double double = ctypes.c_double long = ctypes.c_long # print wlm # for i in range(1, 9): # freq = float64(wlm.GetFrequencyNum(int32(i), float64(0))) # print freq LZERO = long(0) DZERO = double(0) cInstCheckForWLM = long(-1) cInstResetCalc = long(0) cInstReturnMode = cInstResetCalc
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())