def __init__(self, device):
        # type: (Optional[Text]) -> None
        if None in (self.USB_VENDOR_ID, self.USB_PRODUCT_ID) and not device:
            raise exceptions.CommandLineError(
                '--device parameter is required, should point to a /dev/hidraw '
                'device node representing the meter.')

        # If the user passed a device path that does not exist, raise an
        # error. This is to avoid writing to a file instead of to a device node.
        if device and not os.path.exists(device):
            raise exceptions.ConnectionFailed(
                message='Path %s does not exist.' % device)

        # If the user passed a device, try opening it.
        if device:
            self.handle_ = open(device, 'w+b')  # type: Optional[BinaryIO]
        else:
            self.handle_ = None
            logging.info(
                'No --device parameter provided, using hidapi library.')
            try:
                import hid
                self.hidapi_handle_ = hid.device()
                self.hidapi_handle_.open(self.USB_VENDOR_ID,
                                         self.USB_PRODUCT_ID)
            except ImportError:
                raise exceptions.ConnectionFailed(
                    message='Missing requied "hidapi" module.')
            except OSError as e:
                raise exceptions.ConnectionFailed(
                    message='Unable to connect to meter: %s.' % e)
Exemple #2
0
    def __init__(self, device):
        if not device:
            raise exceptions.CommandLineError(
                '--device parameter is required, should point to the disk '
                'device representing the meter.')

        self.device_name_ = device
        self.scsi_device_ = SCSIDevice(device, readwrite=True)
        self.scsi_ = SCSI(self.scsi_device_)
        self.scsi_.blocksize = _REGISTER_SIZE
Exemple #3
0
    def __init__(self, device):
        if not device:
            raise exceptions.CommandLineError(
                '--device parameter is required, should point to /dev/hidraw '
                'for the meter')

        if not os.path.exists(device):
            raise exceptions.ConnectionFailed(
                message='Path %s does not exist.' % device)
        self.handle_ = open(device, 'w+b')
Exemple #4
0
    def __init__(self, device):
        if not device or not os.path.isdir(device):
            raise exceptions.CommandLineError(
                '--device parameter is required, should point to mount path for the '
                'meter.')

        report_files = glob.glob(os.path.join(device, '*', 'Reports', '*.csv'))
        if not report_files:
            raise exceptions.ConnectionFailed(
                'No report file found in path "%s".' % reports_path)

        self.report_file = report_files[0]
    def __init__(self, device: Optional[str]) -> None:
        if not device:
            raise exceptions.CommandLineError(
                "--device parameter is required, should point to the disk "
                "device representing the meter.")

        super().__init__(device)

        self.device_name_ = device
        self.scsi_device_ = SCSIDevice(device, readwrite=True)
        self.scsi_ = SCSI(self.scsi_device_)
        self.scsi_.blocksize = _REGISTER_SIZE
Exemple #6
0
    def __init__(self, device: Optional[str]) -> None:
        if not device or not os.path.isdir(device):
            raise exceptions.CommandLineError(
                "--device parameter is required, should point to mount path "
                "for the meter.")

        reports_path = os.path.join(device, "*", "Reports", "*.csv")
        report_files = glob.glob(reports_path)
        if not report_files:
            raise exceptions.ConnectionFailed(
                f'No report file found in path "{reports_path}".')

        self.report_file = report_files[0]
    def __init__(
        self,
        usb_id: Optional[Tuple[int, int]],
        device: Optional[str],
        timeout_ms: int = 0,
    ) -> None:
        """Construct a new session object.

        Args:
          usb_id: Optional pair of vendor_id and product_id for the session.
            This is required to use the hidapi library.
          device: Optional path to Linux hidraw-style device path. If not provided,
            usb_id needs to be provided instead.
          timeout_ms: Timeout in milliseconds for read operations. Only relevant when
            using hidapi library.
        """

        self._timeout_ms = timeout_ms

        if not usb_id and not device:
            raise exceptions.CommandLineError(
                "--device parameter is required, should point to a /dev/hidraw "
                "device node representing the meter.")

        # If the user passed a device path that does not exist, raise an
        # error. This is to avoid writing to a file instead of to a device node.
        if device and not os.path.exists(device):
            raise exceptions.ConnectionFailed(
                message=f"Path {device} does not exist.")

        # If the user passed a device, try opening it.
        if device:
            self.handle_ = open(device, "w+b")  # type: Optional[BinaryIO]
        else:
            self.handle_ = None
            logging.info(
                "No --device parameter provided, using hidapi library.")
            try:
                import hid

                assert usb_id
                vendor_id, product_id = usb_id
                self.hidapi_handle_ = hid.device()
                self.hidapi_handle_.open(vendor_id, product_id)
            except ImportError:
                raise exceptions.ConnectionFailed(
                    message='Missing requied "hidapi" module.')
            except OSError as e:
                raise exceptions.ConnectionFailed(
                    message=f"Unable to connect to meter: {e}.")
Exemple #8
0
    def __init__(self, device):
        # type: (Optional[Text]) -> None
        assert self.BAUDRATE is not None

        if not device and self.DEFAULT_CABLE_ID:
            logging.info(
                'No --device parameter provided, looking for default cable.')
            device = 'hwgrep://' + self.DEFAULT_CABLE_ID

        if not device:
            raise exceptions.CommandLineError(
                'No --device parameter provided, and no default cable known.')

        self.serial_ = serial.serial_for_url(
            device,
            baudrate=self.BAUDRATE,
            timeout=self.TIMEOUT,
            writeTimeout=None,
            bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE,
            stopbits=serial.STOPBITS_ONE,
            xonxoff=False, rtscts=False, dsrdtr=False)