def main(): a, bp = dac.find_first_dac() d = dac.DAC(a) scale = .35 pps = 20000 target = liblo.Address(a, 60000) liblo.send(target, "/geom/tl", int(-1), int(1)) liblo.send(target, "/geom/tr", int(1), int(1)) liblo.send(target, "/geom/bl", int(-1), int(-1)) liblo.send(target, "/geom/br", int(1), int(-1)) liblo.send(target, "/geom/pps", pps) liblo.send(target, "/geom/size", scale) with open('ildatest.ild', 'rb') as f: frames = list(readFrames(f)) def stream_points(): while True: for f in frames: for p in f.iterPoints(): yield p.encode() itr = iter(stream_points()) d.play_iter(pps, bp.buffer_capacity, itr)
def dac_thread(): while True: try: d = dac.DAC(dac.find_first_dac()) d.play_stream(laser) except Exception as e: import sys, traceback print '\n---------------------' print 'Exception: %s' % e print '- - - - - - - - - - -' traceback.print_tb(sys.exc_info()[2]) print "\n" pass
def dac_thread(): while True: try: #etherIP = dac.find_first_dac() print(type(etherIP),etherIP) d = dac.DAC(etherIP) d.play_stream(laser) except Exception as e: import sys, traceback print ('\n---------------------') print ('Exception: %s' % e) print ('- - - - - - - - - - -') traceback.print_tb(sys.exc_info()[2]) print ("\n")
def playshow(self, scale, pps): a, bp = dac.find_first_dac() d = dac.DAC(a) target = liblo.Address(a, 60000) liblo.send(target, "/geom/tl", int(-1), int(1)) liblo.send(target, "/geom/tr", int(1), int(1)) liblo.send(target, "/geom/bl", int(-1), int(-1)) liblo.send(target, "/geom/br", int(1), int(-1)) liblo.send(target, "/geom/pps", pps) liblo.send(target, "/geom/size", scale) def fun(t): self.phase[0] = (self.phase[0] + self.freq) self.phase[1] = (self.phase[1] + (1 - self.k) / self.k * self.freq) self.phase[2] = (self.phase[2] + self.rot_freq) x = self.R * ((1 - self.k) * cos(self.phase[0]) + self.l * self.k * cos(self.phase[1])) y = self.R * ((1 - self.k) * sin(self.phase[0]) - self.l * self.k * sin(self.phase[1])) x_rot = x * cos(self.phase[2]) - y * sin(self.phase[2]) y_rot = x * sin(self.phase[2]) + y * cos(self.phase[2]) x_rot = min(COORD_MAX, max(COORD_MIN, x_rot)) y_rot = min(COORD_MAX, max(COORD_MIN, y_rot)) return x_rot, y_rot def stream_points(): t = 0 while True: x, y = fun(t) p = (x, y, 0, 0, COORD_MAX) yield p self.recv(0) t += 1 itr = iter(stream_points()) d.play_iter(pps, bp.buffer_capacity, itr)
def playshow(self, scale, pps): a, bp = dac.find_first_dac() d = dac.DAC(a) target = liblo.Address(a, 60000) liblo.send(target, "/geom/tl", int(-1), int(1)) liblo.send(target, "/geom/tr", int(1), int(1)) liblo.send(target, "/geom/bl", int(-1), int(-1)) liblo.send(target, "/geom/br", int(1), int(-1)) liblo.send(target, "/geom/pps", pps) liblo.send(target, "/geom/size", scale) phase = [0, 0] def fun(): phase[0] += self.freq phase[1] += self.freq2 x = COORD_MAX*(sin(phase[0])+sin(phase[1]+self.offset))/2 y = 0 x_rot = x*cos(self.rot)-y*sin(self.rot) y_rot = x*sin(self.rot)+y*cos(self.rot) return x_rot, y_rot def stream_points(): last_dwell = 0 while True: x, y = fun() yield (x, y, 0, 0, COORD_MAX) self.recv(0) itr = iter(stream_points()) d.play_iter(pps, bp.buffer_capacity, itr)
def __init__(self, EIO_IP, Host_IP='0.0.0.0', EIO_Port=IO_UDP_PORT, Host_Port=IO_UDP_PORT): """ @param EIO_IP @param Host_IP @param EIO_Port @param Host_Port """ self.EIO_IP = EIO_IP self.EIO_Port = EIO_Port self.Host_IP = Host_IP self.Host_Port = Host_Port self.DACs = [] self.ADCs = [] self.QEs = [] # Quadrature Encoders for ii in range(8): self.DACs.append(dac.DAC()) self.ADCs.append(adc.ADC()) for ii in range(10): self.QEs.append(quadrature.QuadEnc()) self.curSeq = 0xabcd self.pad = 0xBB self.sock = socket.socket( socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP # Bind it for reception of responses self.sock.bind((self.Host_IP, self.Host_Port)) self.Debug = False
class SquarePointStream(object): def produce(self): pmax = 15000 pstep = 750 cmax = 65535 while True: for x in xrange(-pmax, pmax, pstep): yield (x, pmax, cmax, 0, 0) for y in xrange(pmax, -pmax, -pstep): yield (pmax, y, 0, cmax, 0) for x in xrange(pmax, -pmax, -pstep): yield (x, -pmax, 0, 0, cmax) for y in xrange(-pmax, pmax, pstep): yield (-pmax, y, cmax, cmax, cmax) def __init__(self): self.stream = self.produce() def read(self, n): return [self.stream.next() for i in xrange(n)] class NullPointStream(object): def read(self, n): return [(0, 0, 0, 0, 0)] * n d = dac.DAC(dac.find_first_dac()) d.play_stream(SquarePointStream())
pmax = 32600 pstep = 200 cmax = 65535 while True: for x in xrange(-pmax, pmax, pstep): yield (x, pmax, cmax, 0, 0) for y in xrange(pmax, -pmax, -pstep): yield (pmax, y, 0, cmax, 0) for x in xrange(pmax, -pmax, -pstep): yield (x, -pmax, 0, 0, cmax) for y in xrange(-pmax, pmax, pstep): yield (-pmax, y, cmax, cmax, cmax) def __init__(self): self.stream = self.produce() def read(self, n): return [self.stream.next() for i in xrange(n)] class NullPointStream(object): def read(self, n): return [(0, 0, 0, 0, 0)] * n #dac.find_dac() d = dac.DAC("169.254.13.29") d.play_stream(SquarePointStream())
################################################################################ # Dac Basic # # Created by Zerynth Team 2015 CC # Authors: L. Rizzello ################################################################################ import streams import adc # for analogRead import dac def readInput(): while True: print("reading A1: ", analogRead(A1)) sleep(500) streams.serial() pinMode(A1, INPUT) # read input in a separate thread thread(readInput) my_dac = dac.DAC(D8.DAC) my_dac.start() # circular mode: continuously repeat the input buffer my_dac.write([100, 200, 900, 800], 1000, MILLIS, circular=True)