File: usb.py

package info (click to toggle)
pyvisa-sim 0.6.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 428 kB
  • sloc: python: 1,749; makefile: 129
file content (41 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download
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
# -*- coding: utf-8 -*-
"""USB simulated session class.

:copyright: 2014-2022 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.

"""
from typing import Union

from pyvisa import constants, rname

from . import session


class BaseUSBSession(session.MessageBasedSession):
    parsed: Union[rname.USBInstr, rname.USBRaw]

    def after_parsing(self) -> None:
        self.attrs[constants.ResourceAttribute.interface_number] = int(
            self.parsed.board
        )
        self.attrs[
            constants.ResourceAttribute.manufacturer_id
        ] = self.parsed.manufacturer_id
        self.attrs[constants.ResourceAttribute.model_code] = self.parsed.model_code
        self.attrs[
            constants.ResourceAttribute.usb_serial_number
        ] = self.parsed.serial_number
        self.attrs[constants.ResourceAttribute.usb_interface_number] = int(
            self.parsed.board
        )


@session.Session.register(constants.InterfaceType.usb, "INSTR")
class USBInstrumentSession(BaseUSBSession):
    parsed: rname.USBInstr


@session.Session.register(constants.InterfaceType.usb, "RAW")
class USBRawSession(BaseUSBSession):
    parsed: rname.USBRaw