def __init__(self, hostname='localhost', port=1972, n_channels=16, window_delay=50): self.client = Client() self.n_channels = n_channels self.data_x = np.zeros((0, n_channels)) self.data_y = [] while not self.client.isConnected: try: self.client.connect(hostname, port) except socket.error: print("Failed to connect at " + hostname + ":" + str(port)) time.sleep(1) self.buffer_start_index = self.client.poll()[0] self.transition_indexes = [self.client.poll()[0] - self.buffer_start_index] self.transition_classes = [] self.min_rows_per_chunk = sys.float_info.max self.window_delay = window_delay
def connect(header=True, verbose=True): """Connects to the buffer. And waits for a header (unless otherwise specified). The ftc variable contains the client connection.""" global ftc, event ftc = Client() event = Event() adress = "localhost" port = 1972 if verbose: adress = raw_input("Buffer adress (default is \"localhost:1972\"):") if adress == "": adress = "localhost" else: try: split = adress.split(":") adress = split[0] port = int(split(1)) except ValueError: print "Invalid port formatting " + split[1] except IndexError: print "Invalid adress formatting " + adress while not ftc.isConnected: try: ftc.connect(adress, port) except socket.error: print "Failed to connect at " + adress + ":" + str(port) sleep(1) if header: hdr = waitforheader(verbose) return ftc, hdr return ftc