def wait_for_transmission(self, unit, module, port_number, when=None, time=None): """Wait until a 'Stop'stream is done, or terminate a 'CONT'stream after x seconds on a port. :param unit: the unit (generator) number as a string to be selected :param module: the module (network card) number as a string to be selected :param port_number: the port number as a string to be selected :param when: Choose between CONT or STOP. 'CONT' means a continuous stream, a time must be given to the time parameter. 'STOP' means wait for the stream to end, then stop all remaining actions. :param time: how many seconds to wait for the continuous stream before ending it """ self.checkstopped = port.transmit_state() if when == 'CONT': self.stop = port.stop_all(unit, module, port_number) if time == None: raise ValueError('no time given') else: sleep(int(time)) self.send_msg(self.stop) elif when == 'STOP' or when == None: #print('waiting for transmission to end on port' + port_number) while 1: self.data = self.send_recv_msg(self.checkstopped) stdout.write('.') stdout.flush() if self.data == '0\n': print '.' break elif self.data == '1\n': sleep(1) elif self.data == '2\n': print('starting/halting ' + port_number) sleep(1)
def stop_all(self, unit, module, port_number, when=None, time=None): """Stop all running actions(i.e. counting, transmitting and capturing) on a port. :param unit: the unit (generator) number as a string to be selected :param module: the module (network card) number as a string to be selected :param port_number: the port number as a string to be selected :param when: Choose between CONT or STOP. 'CONT' means a continuous stream, a time must be given to the time parameter. 'STOP' means wait for the stream to end, then stop all remaining actions. :param time: how many seconds to wait for the continuous stream before ending it """ self.stop = port.stop_all(unit, module, port_number) self.checkstopped = port.transmit_state() if when == 'CONT': if time == None: raise ValueError('no time given') else: sleep(int(time)) send_msg(stop) elif when == 'STOP': self.stopped = False print('waiting for transmission to end on port' + port_number) while self.stopped == False: self.data = self.send_recv_msg(self.checkstopped) if self.data == '0\n': print('stopped counters on port ' + port_number) self.stopped = True elif self.data == '1\n': sleep(1) elif self.data == '2\n': print('starting/halting ' + port_number) sleep(1) self.send_msg(self.stop) elif when == None: print('when == None') else: print(when)