Skip to content

VirtualDevice ¤

Classes:

Name Description
Driver

driver template

Driver(addr: str = '', timeout: float = 3.0, **kw) ¤

Bases: BaseDriver

driver template

Warning

All drivers must inherit from the base class(with fixed class name Driver) and methods open/close/read/write must be implemented!

Methods:

Name Description
open

open device

close

close device

write

write to device

read

read from device

Attributes:

Name Type Description
__abstractmethods__

frozenset() -> empty frozenset object

__annotations__

dict() -> new empty dictionary

__doc__

str(object='') -> str

__module__

str(object='') -> str

__weakref__

list of weak references to the object

Source code in quark/driver/VirtualDevice.py
136
137
138
139
140
def __init__(self, addr: str = '', timeout: float = 3.0, **kw):
    super().__init__(addr=addr, timeout=timeout, **kw)
    self.model = 'VirtualDevice'  # device model
    self.timeout = 1.0
    self.srate = 1e9  # sampling rate

__abstractmethods__ = frozenset({'open', 'read', 'write', 'close'}) class-attribute ¤

frozenset() -> empty frozenset object frozenset(iterable) -> frozenset object

Build an immutable unordered collection of unique elements.

__annotations__ = {'segment': 'tuple', 'CHs': 'list[int | str]', 'quants': 'list[Quantity]'} class-attribute ¤

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

__doc__ = 'Base class for all drivers and methods open/close/read/write are required.\n\n See template **VirtualDevice**\n ' class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.

__module__ = 'quark.driver.common.basedriver' class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.

__weakref__ property ¤

list of weak references to the object

open(**kw) ¤

open device

Source code in quark/driver/VirtualDevice.py
142
143
144
145
def open(self, **kw):
    """open device
    """
    self.handle = 'DeviceHandler'

close(**kw) ¤

close device

Source code in quark/driver/VirtualDevice.py
148
149
150
151
def close(self, **kw):
    """close device
    """
    self.handle.close()

write(name: str, value, **kw) ¤

write to device

Source code in quark/driver/VirtualDevice.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
def write(self, name: str, value, **kw):
    """write to device
    """
    if name == 'Wait':
        time.sleep(value)
    elif name == 'Waveform':
        if isinstance(value, list):
            t0 = time.time()
            wf = Waveform.fromlist(value)
            t1 = time.time()
            wf.sample()
        if isinstance(value, Waveform):
            t0 = time.time()
            value.sample()
        # 如,self.set_offset(value, ch=1)
    elif name == 'Shot':
        pass
    elif name == 'Coefficient':
        data, f_list, numberOfPoints, phase = get_coef(value, self.srate)
        # coef_data = np.moveaxis([data.real,data.imag],0,-2)
        self.setValue('PointNumber', numberOfPoints, **kw)
        # self.update('Coefficient', data, channel=ch)
        return data
        # 如,self.set_shot(value, ch=2)
    return value

read(name: str, **kw) ¤

read from device

Source code in quark/driver/VirtualDevice.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
def read(self, name: str, **kw):
    """read from device
    """
    if name == 'TraceIQ':
        shot = self.getValue('Shot', **kw)
        point = self.getValue('PointNumber', **kw)
        # test = 1/0
        return np.ones((shot, point)), np.ones((shot, point))
    elif name == 'IQ':
        shot = self.getValue('Shot', **kw)
        fnum = self.getValue('Coefficient', **kw).shape[0]
        # time.sleep(0.1)
        si = np.random.randint(20) + np.random.randn(shot, fnum)
        sq = np.random.randint(20) + np.random.randn(shot, fnum)
        return si, sq
    elif name == 'S':
        points = self.getValue('NumberOfPoints')
        return np.array([np.linspace(3, 7, points) * 1e9, np.random.randn(points)])