예제 #1
0
	def __init__( self , serialport , romcode = '', label = 'TEMPERATURESENSOR' , plot_title = None , max_buffer_points = 500 , fig_w = 6.5 , fig_h = 5 , has_plot_window = True , has_external_plot_window = None):
		'''
		temperaturesensor_VIRTUAL.__init__( serialport , romcode, label = 'TEMPERATURESENSOR' , plot_title = None , max_buffer_points = 500 , fig_w = 6.5 , fig_h = 5 , has_plot_window = True , has_external_plot_window = None )
		
		Initialize TEMPERATURESENSOR object (VIRTUAL)
		
		INPUT:
		serialport: device name of the serial port for 1-wire connection to the temperature sensor, e.g. serialport = '/dev/ttyUSB3'
		romcode: ROM code of the temperature sensor chip (you can find the ROM code using the digitemp program or using the pydigitemp package). If there is only a single temperature sensor connected to the 1-wire bus on the given serial port, romcode can be left empty.
		label (optional): label / name of the TEMPERATURESENSOR object (string) for data output. Default: label = 'TEMPERATURESENSOR'
		plot_title (optional): title string for use in plot window. If plot_title = None, the sensor label is used. Default: label = None
		max_buffer_points (optional): max. number of data points in the PEAKS buffer. Once this limit is reached, old data points will be removed from the buffer. Default value: max_buffer_points = 500
		fig_w, fig_h (optional): width and height of figure window used to plot data (inches)
		has_external_plot_window (optional): flag to indicate if there is a GUI system that handles the plotting of the data buffer on its own. This flag can be set explicitly to True of False, or can use None to ask for automatic 'on the fly' check if the has_external_plot_window = True or False should be used. Default: has_external_plot_window = None
		
		OUTPUT:
		(none)
		'''
		
		self._label = label
		
		# Check for has_external_plot_window flag:
		if has_external_plot_window is None:
			has_external_plot_window = misc.have_external_gui()

		# Check plot title:
		if plot_title == None:
			self._plot_title = self._label
		else:
			self._plot_title = plot_title

		# data buffer for temperature values:
		self._tempbuffer_t = numpy.array([])
		self._tempbuffer_T = numpy.array([])
		self._tempbuffer_unit = ['x'] * 0 # empty list
		self._tempbuffer_max_len = max_buffer_points
		self._tempbuffer_lastupdate_timestamp = -1

		# set up plotting environment
		if has_external_plot_window:
			# no need to set up plotting
			self._has_external_display = True
			self._has_display = False
		else:
			self._has_external_display = False
			self._has_display = misc.plotting_setup() # check for graphical environment, import matplotlib
		
		if self._has_display: # prepare plotting environment and figure

			import matplotlib.pyplot as plt

			# set up plotting environment
			self._fig = plt.figure(figsize=(fig_w,fig_h))
			t = 'VIRUTAL_TSENSOR'
			if self._plot_title:
				t = t + ' (' + self._plot_title + ')'
			self._fig.canvas.set_window_title(t)

			# set up panel for temperature history plot:
			self._tempbuffer_ax = plt.subplot(1,1,1)
			t = 'TEMPBUFFER'
			if self._plot_title:
				t = t + ' (' + self._plot_title + ')'
			self._tempbuffer_ax.set_title(t,loc="center")
			self._tempbuffer_ax.set_xlabel('Time (s)')
			self._tempbuffer_ax.set_ylabel('Temperature')
		
			# add (empty) line to plot (will be updated with data later):
			self._tempbuffer_ax.plot( [], [] , 'ko-' , markersize = 10 )

			# get some space in between panels to avoid overlapping labels / titles
			self._fig.tight_layout()
		
			# enable interactive mode:
			plt.ion()

			self._figwindow_is_shown = False


		print ( 'Successfully configured VIRTUAL temperature sensor.' )
예제 #2
0
    def __init__(self,
                 serialport,
                 romcode='',
                 label='TEMPERATURESENSOR',
                 plot_title=None,
                 max_buffer_points=500,
                 fig_w=6.5,
                 fig_h=5,
                 has_plot_window=True,
                 has_external_plot_window=None):
        '''
		temperaturesensor_MAXIM.__init__( serialport , romcode, label = 'TEMPERATURESENSOR' , plot_title = None , max_buffer_points = 500 , fig_w = 6.5 , fig_h = 5 , has_plot_window = True , has_external_plot_window = None )
		
		Initialize TEMPERATURESENSOR object (MAXIM), configure serial port / 1-wire bus for connection to DS18B20 temperature sensor chip
		
		INPUT:
		serialport: device name of the serial port for 1-wire connection to the temperature sensor, e.g. serialport = '/dev/ttyUSB3'
		romcode: ROM code of the temperature sensor chip (you can find the ROM code using the digitemp program or using the pydigitemp package). If there is only a single temperature sensor connected to the 1-wire bus on the given serial port, romcode can be left empty.
		label (optional): label / name of the TEMPERATURESENSOR object (string) for data output. Default: label = 'TEMPERATURESENSOR'
		plot_title (optional): title string for use in plot window. If plot_title = None, the sensor label is used. Default: label = None
		max_buffer_points (optional): max. number of data points in the PEAKS buffer. Once this limit is reached, old data points will be removed from the buffer. Default value: max_buffer_points = 500
		fig_w, fig_h (optional): width and height of figure window used to plot data (inches)
		has_external_plot_window (optional): flag to indicate if there is a GUI system that handles the plotting of the data buffer on its own. This flag can be set explicitly to True of False, or can use None to ask for automatic 'on the fly' check if the has_external_plot_window = True or False should be used. Default: has_external_plot_window = None
		
		OUTPUT:
		(none)
		'''

        self._label = label

        # Check for has_external_plot_window flag:
        if has_external_plot_window is None:
            has_external_plot_window = misc.have_external_gui()

        # Check plot title:
        if plot_title == None:
            self._plot_title = self._label
        else:
            self._plot_title = plot_title

        # data buffer for temperature values:
        self._tempbuffer_t = numpy.array([])
        self._tempbuffer_T = numpy.array([])
        self._tempbuffer_unit = ['x'] * 0  # empty list
        self._tempbuffer_max_len = max_buffer_points
        self._tempbuffer_lastupdate_timestamp = -1

        # set up plotting environment
        if has_external_plot_window:
            # no need to set up plotting
            self._has_external_display = True
            self._has_display = False
        else:
            self._has_external_display = False
            self._has_display = misc.plotting_setup(
            )  # check for graphical environment, import matplotlib

        try:

            # configure 1-wire bus for communication with MAXIM temperature sensor chip
            r = AddressableDevice(
                UART_Adapter(serialport)).get_connected_ROMs()

            if r is None:
                print('Couldn not find any 1-wire devices on ' + serialport)
            else:
                bus = UART_Adapter(serialport)
                if romcode == '':
                    if len(r) == 1:
                        # print ('Using 1-wire device ' + r[0] + '\n')
                        self._sensor = DS18B20(bus)
                        self._ROMcode = r[0]
                    else:
                        print(
                            'Too many 1-wire devices to choose from! Try again with specific ROM code...'
                        )
                        for i in range(1, len(r)):
                            print('Device ' + i + ' ROM code: ' + r[i - 1] +
                                  '\n')
                else:
                    self._sensor = DS18B20(bus, rom=romcode)
                    self._ROMcode = romcode

                self._UART_locked = False

            if self._has_display:  # prepare plotting environment and figure

                import matplotlib.pyplot as plt

                # set up plotting environment
                self._fig = plt.figure(figsize=(fig_w, fig_h))
                t = 'MAXIM DS1820'
                if self._plot_title:
                    t = t + ' (' + self._plot_title + ')'
                self._fig.canvas.set_window_title(t)

                # set up panel for temperature history plot:
                self._tempbuffer_ax = plt.subplot(1, 1, 1)
                t = 'TEMPBUFFER'
                if self._plot_title:
                    t = t + ' (' + self._plot_title + ')'
                self._tempbuffer_ax.set_title(t, loc="center")
                self._tempbuffer_ax.set_xlabel('Time (s)')
                self._tempbuffer_ax.set_ylabel('Temperature')

                # add (empty) line to plot (will be updated with data later):
                self._tempbuffer_ax.plot([], [], 'ko-', markersize=10)

                # get some space in between panels to avoid overlapping labels / titles
                self._fig.tight_layout()

                # enable interactive mode:
                plt.ion()

                self._figwindow_is_shown = False

            if hasattr(self, '_sensor'):
                print(
                    'Successfully configured DS18B20 temperature sensor (ROM code '
                    + self._ROMcode + ')')
            else:
                self.warning(
                    'Could not initialize MAXIM DS1820 temperature sensor.')

        except:
            # print ( '\n**** WARNING: An error occured during configuration of the temperature sensor at serial interface ' + serialport + '. The temperature sensor cannot be used.\n' )
            self.warning(
                'An error occured during configuration of the temperature sensor at serial interface '
                + serialport + '. The temperature sensor cannot be used.')
예제 #3
0
	def __init__( self , serialport , label = 'PRESSURESENSOR' , plot_title = None , max_buffer_points = 500 , fig_w = 6.5 , fig_h = 5 , has_plot_window = True , has_external_plot_window = None):
		'''
		pressuresensor_OMEGA.__init__( serialport , label = 'PRESSURESENSOR' , plot_title = None , max_buffer_points = 500 , fig_w = 6.5 , fig_h = 5 , has_plot_window = True , has_external_plot_window = None )
		
		Initialize PRESSURESENSOR object (OMEGA), configure serial port connection
		
		INPUT:
		serialport: device name of the serial port, e.g. serialport = '/dev/ttyUSB3'
		label (optional): label / name of the PRESSURESENSOR object for data output (string). Default: label = 'PRESSURESENSOR'
		plot_title (optional): title string for use in plot window. If plot_title = None, the sensor label is used. Default: label = None
		max_buffer_points (optional): max. number of data points in the PEAKS buffer. Once this limit is reached, old data points will be removed from the buffer. Default value: max_buffer_points = 500
		fig_w, fig_h (optional): width and height of figure window used to plot data (inches)
		has_external_plot_window (optional): flag to indicate if there is a GUI system that handles the plotting of the data buffer on its own. This flag can be set explicitly to True of False, or can use None to ask for automatic 'on the fly' check if the has_external_plot_window = True or False should be used. Default: has_external_plot_window = None
		
		OUTPUT:
		(none)
		'''
	
		self._label = label
		
		# Check for has_external_plot_window flag:
		if has_external_plot_window is None:
			has_external_plot_window = misc.have_external_gui() 

		# Check plot title:
		if plot_title == None:
			self._plot_title = self._label
		else:
			self._plot_title = plot_title

		# data buffer for PEAK values:
		self._pressbuffer_t = numpy.array([])
		self._pressbuffer_p = numpy.array([])
		self._pressbuffer_unit = ['x'] * 0 # empty list
		self._pressbuffer_max_len = max_buffer_points
		self._pressbuffer_lastupdate_timestamp = -1
		
		# set up plotting environment
		if has_external_plot_window:
			# no need to set up plotting
			self._has_external_display = True
			self._has_display = False
		else:
			self._has_external_display = False
			self._has_display = misc.plotting_setup() # check for graphical environment, import matplotlib

		try:

			# open and configure serial port for communication with VICI valve (9600 baud, 8 data bits, no parity, 1 stop bit

			from pkg_resources import parse_version
			if parse_version(serial.__version__) >= parse_version('3.3') :
				# open port with exclusive access:
				ser = serial.Serial(
					port     = serialport,
					baudrate = 115200,
					parity   = serial.PARITY_NONE,
					stopbits = serial.STOPBITS_ONE,
					bytesize = serial.EIGHTBITS,
					timeout  = 5,
					exclusive = True
				)

			else:
				# open port (can't ask for exclusive access):
				ser = serial.Serial(
					port     = serialport,
					baudrate = 115200,
					parity   = serial.PARITY_NONE,
					stopbits = serial.STOPBITS_ONE,
					bytesize = serial.EIGHTBITS,
					timeout  = 5
				)

			ser.flushOutput()   # make sure output is empty
			time.sleep(0.1)
			ser.flushInput()    # make sure input is empty
		
			self.ser = ser
			self._ser_locked = False
			
			# get serial number of pressure sensor
			self.get_serial_lock()
			self.ser.write(('SNR\r').encode('utf-8')) # send command with check sum to serial port
			ans = self.ser.readline().decode('utf-8') # read response and decode ASCII	
			ser.flushInput()   # make sure input is empty
			self.release_serial_lock()
			self._serial_number = int(ans.rstrip().split('=')[1]) # parse response to integer number

			if self._has_display: # prepare plotting environment and figure

				import matplotlib.pyplot as plt

				# set up plot figure:
				self._fig = plt.figure(figsize=(fig_w,fig_h))
				t = 'OMEGA PXM409'
				if self._plot_title:
					t = t + ' (' + self._plot_title + ')'
				self._fig.canvas.set_window_title(t)

				# set up panel for pressure history plot:
				self._pressbuffer_ax = plt.subplot(1,1,1)
				t = 'PRESSBUFFER'
				if self._plot_title:
					t = t + ' (' + self._plot_title + ')'
				self._pressbuffer_ax.set_title(t,loc="center")
				self._pressbuffer_ax.set_xlabel('Time (s)')
				self._pressbuffer_ax.set_ylabel('Pressure')

				# add (empty) line to plot (will be updated with data later):
				self._pressbuffer_ax.plot( [], [] , 'ko-' , markersize = 10 )

				# get some space in between panels to avoid overlapping labels / titles
				self._fig.tight_layout()
			
				# enable interactive mode:
				plt.ion()

				self._figwindow_is_shown = False

			print ('Successfully configured OMEGA pressure sensor with serial number ' + str(self._serial_number) + ' on ' + serialport )


		except:
			self.warning ( 'An error occured during configuration of the pressure sensor at serial interface ' + serialport + '. The pressure sensor cannot be used.' )
예제 #4
0
    def __init__(self,
                 serialport=None,
                 label='MS',
                 cem_hv=1400,
                 tune_default_RI=[],
                 tune_default_RS=[],
                 max_buffer_points=500,
                 fig_w=10,
                 fig_h=8,
                 peakbuffer_plot_min=0.5,
                 peakbuffer_plot_max=2,
                 peakbuffer_plot_yscale='linear',
                 scan_plot_yscale='linear',
                 has_plot_window=True,
                 has_external_plot_window=None):
        '''
		rgams_SRS_virtual.__init__( serialport , label='MS' , cem_hv = 1400 , tune_default_RI = [] , tune_default_RS = [] , max_buffer_points = 500 , fig_w = 10 , fig_h = 8 , peakbuffer_plot_min=0.5 , peakbuffer_plot_max = 2 , peakbuffer_plot_yscale = 'linear' , scan_plot_yscale = 'linear' , has_plot_window = True , has_external_plot_window = None)
		
		Initialize virtual mass spectrometer (SRS RGA)
		
		INPUT:
		serialport (optional): device name of the serial port, e.g. P = '/fake/serialport/to/virtual/rga_MS'
		label (optional): label / name of the RGAMS object (string). Default: label = 'MS'
		cem_hv (optional): default bias voltage to be used with the electron multiplier (CEM). Default value: cem_hv = 1400 V.
		tune_default_RI (optional): default RI parameter value in m/z tuning. Default value: tune_RI = []
		tune_default_RS (optional): default RS parameter value in m/z tuning. Default value: tune_RS = []
		max_buffer_points (optional): max. number of data points in the PEAKS buffer. Once this limit is reached, old data points will be removed from the buffer. Default value: max_buffer_points = 500
		fig_w, fig_h (optional): width and height of figure window used to plot data (inches). 
		peakbuffer_plot_min, peakbuffer_plot_max (optional): limits of y-axis range in peakbuffer plot (default: peakbuffer_plot_min=0.5 , peakbuffer_plot_max = 2)
		peakbuffer_plot_yscale (optional) = y-axis scaling for peakbuffer plot (default: 'linear', use 'log' for log scaling)
		scan_plot_yscale (optional) = y-axis scaling for scan plot (default: 'linear', use 'log' for log scaling)

		has_plot_window (optional): flag to choose if a plot window should be opened for the rgams_SRS object (default: has_plot_window = True)
		has_external_plot_window (optional) = flag to indicate if external plot window is used instead of the "built-in" window. If set to True, this will override the 'has_plot_window' flag (default: has_external_plot_window = False).

		OUTPUT:
		(none)
		'''

        # object name label (do this first, so the label/name is set for warning or log messages or exception handling):
        self._label = label

        # Check for has_external_plot_window flag:
        if has_external_plot_window is None:
            has_external_plot_window = misc.have_external_gui()

        # general parameters:
        self._serialport = serialport
        if self._serialport is None:
            self._serialport = '/there/is/no/serial/port'
        self._serial_number = 123456789
        self._cem_hv = float(cem_hv)
        self._tune_default_RI = tune_default_RI
        self._tune_default_RS = tune_default_RS

        if not tune_default_RI == []:
            self._RI = tune_default_RI
        else:
            self._RI = -9.0
        if not tune_default_RS == []:
            self._RS = tune_default_RS
        else:
            self._RS = 1070.0

        self._DI = 116
        self._DS = -0.01

        self._EE = 70
        self._FL = 0.0
        self._hasmulti = True
        self._mzmax = 200
        self._noisefloor = 3

        # init MS settings:
        self.set_detector('F')
        self.filament_off()

        # peakbuffer:
        self._peakbuffer_t = numpy.array([])
        self._peakbuffer_mz = numpy.array([])
        self._peakbuffer_intens = numpy.array([])
        self._peakbuffer_det = ['x'] * 0  # empty list
        self._peakbuffer_unit = ['x'] * 0  # empty list
        self._peakbuffer_max_len = max_buffer_points
        self._peakbuffer_lastupdate_timestamp = -1

        # y-axis range:
        self._peakbuffer_plot_min_y = peakbuffer_plot_min
        self._peakbuffer_plot_max_y = peakbuffer_plot_max

        # y-axis scaling for peakbuffer plot:
        self._peakbufferplot_yscale = peakbuffer_plot_yscale

        # y-axis scaling for scan plot:
        self._scan_yscale = scan_plot_yscale

        # mz values and colors (defaults):
        self._peakbufferplot_colors = [
            (2, 'darkgray'), (4, 'c'), (13, 'darkgray'), (14, 'dimgray'),
            (15, 'green'), (16, 'lightcoral'), (28, 'k'), (32, 'r'), (40, 'y'),
            (44, 'b'), (84, 'm')
        ]  # default colors for the more common mz values

        # set up plotting environment
        if has_external_plot_window:
            # no need to set up plotting
            self._has_external_display = True
            self._has_display = False
        else:
            self._has_external_display = False
            self._has_display = misc.plotting_setup(
            )  # check for graphical environment, import matplotlib

        if self._has_display:
            # set up plotting environment

            import matplotlib.pyplot as plt

            self._fig = plt.figure(figsize=(fig_w, fig_h))
            t = 'SRS RGA'
            if self._label:
                t = t + ' (' + self._label + ')'
            self._fig.canvas.set_window_title(t)

            # set up upper panel for peak history plot:
            self._peakbuffer_ax = plt.subplot(2, 1, 1)
            self._peakbuffer_ax.set_title('PEAKBUFFER (' + self.label() + ')',
                                          loc="center")
            plt.xlabel('Time')
            plt.ylabel('Intensity')

            # add (empty) line to plot (will be updated with data later):
            self._peakbuffer_ax.plot([], [])
            self.set_peakbuffer_scale(self._peakbufferplot_yscale)

            # set up lower panel for scans:
            self._scan_ax = plt.subplot(2, 1, 2)
            self._scan_ax.set_title('SCAN (' + self.label() + ')',
                                    loc="center")
            plt.xlabel('mz')
            plt.ylabel('Intensity')
            self.set_scan_scale(self._scan_yscale)

            # get some space in between panels to avoid overlapping labels / titles
            self._fig.tight_layout(pad=4.0)

            self._figwindow_is_shown = False
            plt.ion()

        self.log(
            'Successfully configured virtual SRS RGA MS with serial number ' +
            str(self._serial_number) + ' on ' + self._serialport)