from pydcpf.appliances.DAS1210 import Device import sys from pygolem_lite.utilities import read_config config = read_config('das.cfg') IP_address = config['io_config']['ip'] port = int(config['io_config']['port']) file_name = config['io_config']['file'] #IP_address = '192.168.2.221' #port = 10001 number_of_samples = 10 * 4096 #TODO should calculate from used frequency and recorded time debug = False error_tolerance = 3 #how many errors to tolerate per channel from socket import timeout as TimeoutError timeout = 2 papouch = Device(IP_address, port, timeout=timeout) if sys.argv[1] == "arming": from time import sleep if not papouch.set_ready(): #set all channels to armed state RuntimeError("Cannot arm device ..") sleep(0.01) # must not terminate the connection immediately elif sys.argv[1] == "acquisition": from pydcpf.protocols.spinel97 import CheckSumError, ACKError import numpy as np #papouch.get_data(number_of_samples, 1) from threading import Thread #multiprocessing would copy data for channel in xrange(1, 13): if debug: print "Acquisition of channel %i" % channel error_count = 0 while True: try: Thread(target=np.savez_compressed, args=(file_name+'_%02i' % channel,), kwargs=dict( data = np.hstack( [ np.frombuffer(buf, ' error_tolerance: print "Too many (more than %i) errors on channel %i, aborting acquisition of this channel" % (error_tolerance, channel) break