<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from lantz . feat import Feat <EOL> from lantz . action import Action <EOL> from lantz . drivers . legacy . serial import SerialDriver <EOL> from lantz . errors import InvalidCommand <EOL> class TDS1012 ( SerialDriver ) : <EOL> """<STR_LIT>""" <EOL> ENCODING = '<STR_LIT:ascii>' <EOL> RECV_TERMINATION = '<STR_LIT:\n>' <EOL> SEND_TERMINATION = '<STR_LIT:\n>' <EOL> TIMEOUT = - <NUM_LIT:1> <EOL> def __init__ ( self , port ) : <EOL> super ( ) . __init__ ( port ) <EOL> super ( ) . initialize ( ) <EOL> @ Action ( ) <EOL> def initiate ( self ) : <EOL> """<STR_LIT>""" <EOL> self . send ( '<STR_LIT>' ) <EOL> @ Action ( ) <EOL> def idn ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . query ( '<STR_LIT>' ) <EOL> @ Action ( ) <EOL> def autoset ( self ) : <EOL> """<STR_LIT>""" <EOL> self . send ( '<STR_LIT>' ) <EOL> @ Action ( ) <EOL> def autocal ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . send ( '<STR_LIT>' ) <EOL> @ Feat ( limits = ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> def datasource ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . query ( '<STR_LIT>' ) <EOL> @ datasource . setter <EOL> def datasource ( self , value ) : <EOL> """<STR_LIT>""" <EOL> self . send ( '<STR_LIT>' . format ( value ) ) <EOL> @ Action ( ) <EOL> def acquire_parameters ( self ) : <EOL> """<STR_LIT>""" <EOL> values = '<STR_LIT>' <EOL> answer = self . query ( '<STR_LIT>' . format ( values ) ) <EOL> parameters = { } <EOL> for v , j in zip ( values . split ( '<STR_LIT>' ) , answer . split ( '<STR_LIT:;>' ) ) : <EOL> parameters [ v ] = float ( j ) <EOL> return parameters <EOL> @ Action ( ) <EOL> def data_setup ( self ) : <EOL> """<STR_LIT>""" <EOL> self . send ( '<STR_LIT>' ) <EOL> @ Action ( ) <EOL> def acquire_curve ( self , start = <NUM_LIT:1> , stop = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> parameters = self . acquire_parameters ( ) <EOL> self . data_setup ( ) <EOL> self . send ( '<STR_LIT>' . format ( start ) ) <EOL> self . send ( '<STR_LIT>' . format ( stop ) ) <EOL> data = self . query ( '<STR_LIT>' ) <EOL> data = data . split ( '<STR_LIT:U+002C>' ) <EOL> data = np . array ( list ( map ( float , data ) ) ) <EOL> ydata = ( data - parameters [ '<STR_LIT>' ] ) * parameters [ '<STR_LIT>' ] + parameters [ '<STR_LIT>' ] <EOL> xdata = np . arange ( len ( data ) ) * parameters [ '<STR_LIT>' ] + parameters [ '<STR_LIT>' ] <EOL> return list ( xdata ) , list ( ydata ) <EOL> @ Action ( ) <EOL> def forcetrigger ( self ) : <EOL> """<STR_LIT>""" <EOL> self . send ( '<STR_LIT>' ) <EOL> return <EOL> @ Action ( ) <EOL> def triggerlevel ( self ) : <EOL> """<STR_LIT>""" <EOL> self . send ( '<STR_LIT>' ) <EOL> @ Feat ( values = { '<STR_LIT>' , '<STR_LIT>' } ) <EOL> def trigger ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . query ( '<STR_LIT>' ) <EOL> @ trigger . setter <EOL> def trigger ( self , state ) : <EOL> """<STR_LIT>""" <EOL> self . send ( '<STR_LIT>' . format ( state ) ) <EOL> return <EOL> @ Feat ( ) <EOL> def horizontal_division ( self ) : <EOL> """<STR_LIT>""" <EOL> return float ( self . query ( '<STR_LIT>' ) ) <EOL> @ horizontal_division . setter <EOL> def horizontal_division ( self , value ) : <EOL> """<STR_LIT>""" <EOL> self . send ( '<STR_LIT>' . format ( value ) ) <EOL> return <EOL> @ Feat ( values = { <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:16> , <NUM_LIT:64> , <NUM_LIT> } ) <EOL> def number_averages ( self ) : <EOL> """<STR_LIT>""" <EOL> answer = self . query ( '<STR_LIT>' ) <EOL> answer = answer . split ( '<STR_LIT:;>' ) <EOL> if answer [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> return <NUM_LIT:0> <EOL> elif answer [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> return int ( self . query ( '<STR_LIT>' ) ) <EOL> else : <EOL> raise InvalidCommand <EOL> @ number_averages . setter <EOL> def number_averages ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if value == <NUM_LIT:0> : <EOL> self . send ( '<STR_LIT>' ) <EOL> else : <EOL> self . send ( '<STR_LIT>' . format ( value ) ) <EOL> @ Action ( values = { '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' } ) <EOL> def _measure ( self , mode ) : <EOL> """<STR_LIT>""" <EOL> self . send ( '<STR_LIT>' . format ( mode ) ) <EOL> return float ( self . query ( '<STR_LIT>' ) ) <EOL> def measure_mean ( self ) : <EOL> """<STR_LIT>""" <EOL> answer = self . _measure ( '<STR_LIT>' ) <EOL> return answer <EOL> def measure_frequency ( self ) : <EOL> """<STR_LIT>""" <EOL> answer = self . _measure ( '<STR_LIT>' ) <EOL> return answer <EOL> def measure_minimum ( self ) : <EOL> """<STR_LIT>""" <EOL> answer = self . _measure ( '<STR_LIT>' ) <EOL> return answer <EOL> def measure_maximum ( self ) : <EOL> """<STR_LIT>""" <EOL> answer = self . _measure ( '<STR_LIT>' ) <EOL> return answer <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import argparse <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = True , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:-c>' , '<STR_LIT>' , default = <NUM_LIT:1> , type = int , <EOL> help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> osc = TDS1012 ( args . port ) <EOL> osc . initiate ( ) <EOL> print ( '<STR_LIT>' . format ( osc . idn ) ) <EOL> print ( osc . trigger ) <EOL> osc . forcetrigger ( ) <EOL> osc . triggerlevel ( ) <EOL> osc . trigger = "<STR_LIT>" <EOL> print ( osc . trigger ) <EOL> params = osc . acquire_parameters ( ) <EOL> if args . view : <EOL> import matplotlib . pyplot as plt <EOL> if args . view : <EOL> osc . datasource = args . channel <EOL> x , y = osc . acquire_curve ( ) <EOL> x = np . array ( x ) <EOL> x = x - x . min ( ) <EOL> y = np . array ( y ) <EOL> plt . plot ( x , y ) <EOL> plt . show ( ) </s>
