aboutsummaryrefslogtreecommitdiff
path: root/qolab/hardware/scope/__init__.py
blob: 46898ac011ebffebbfa50c5d3a32c58b9ad27a40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
Provide basic class to operate scope
Created by Eugeniy E. Mikhailov 2021/11/29
"""
from qolab.hardware.scpi import SCPIinstr
from qolab.data.trace import TraceSetSameX
from qolab.file_utils import get_next_data_file

class Scope:

    # Minimal set of methods to be implemented by a scope.
    def __init__(self):
        self.numberOfChannels = 0
        self.fname_prefix = 'scope'
        self.savepath = './scope'

    def getTrace(self, chNum, availableNpnts=None, maxRequiredPoints=None):
        # Should work with minimal arguments list 
        # but might be faster if parameters provided: less IO requests
        warnings.warn( 'this function is not implemented' )

    def getAllTraces(self, availableNpnts=None, maxRequiredPoints=None):
        allTraces=TraceSetSameX('scope traces')
        for chNum in range(1, self.numberOfChannels+1):
            allTraces.addTrace( self.getTrace(chNum, availableNpnts, maxRequiredPoints) )
        return( allTraces )

    def save(self, fname=None, item_format='e', availableNpnts=None, maxRequiredPoints=None, extention='dat'):
        allTraces = self.getAllTraces(availableNpnts=availableNpnts, maxRequiredPoints=maxRequiredPoints)
        if fname is None:
            fname = get_next_data_file(self.fname_prefix, self.savepath, extention=extention)
        allTraces.save(fname, item_format=item_format)
        return(fname)


class ScopeSCPI(SCPIinstr, Scope):
    """     
    Do not instantiate directly, use
    rm = pyvisa.ResourceManager()
    ScopeSCPI(rm.open_resource('TCPIP::192.168.0.2::INSTR'))
    """
    pass
    def __init__(self, resource):
        SCPIinstr.__init__(self, resource)
        Scope.__init__(self)

from .sds1104x import SDS1104X