Пример #1
0
 def __init__(self, library):
     global USBDevice
     self.logger = logging.getLogger('pywws.WeatherStation.CUSBDrive')
     if not USBDevice and library in ('auto', 'cython-hidapi'):
         try:
             from device_cython_hidapi import USBDevice
         except ImportError:
             if library != 'auto':
                 raise
     if not USBDevice:
         from device_pyusb import USBDevice
     self.logger.info('using %s', USBDevice.__module__)
     self.dev = USBDevice(0x1941, 0x8021)
Пример #2
0
 def __init__(self, library):
     global USBDevice
     self.logger = logging.getLogger('pywws.WeatherStation.CUSBDrive')
     if not USBDevice and library in ('auto', 'cython-hidapi'):
         try:
             from device_cython_hidapi import USBDevice
         except ImportError:
             if library != 'auto':
                 raise
     if not USBDevice:
         from device_pyusb import USBDevice
     self.logger.info('using %s', USBDevice.__module__)
     self.dev = USBDevice(0x1941, 0x8021)
Пример #3
0
class CUSBDrive(object):
    """Low level interface to weather station via USB.

    Loosely modeled on a C++ class obtained from
    http://site.ambientweatherstore.com/easyweather/ws_1080_2080_protocol.zip.
    I don't know the provenance of this, but it looks as if it may
    have come from the manufacturer.

    """
    EndMark          = 0x20
    ReadCommand      = 0xA1
    WriteCommand     = 0xA0
    WriteCommandWord = 0xA2

    def __init__(self, library):
        global USBDevice
        self.logger = logging.getLogger('pywws.WeatherStation.CUSBDrive')
        if not USBDevice and library in ('auto', 'cython-hidapi'):
            try:
                from device_cython_hidapi import USBDevice
            except ImportError:
                if library != 'auto':
                    raise
        if not USBDevice:
            from device_pyusb import USBDevice
        self.logger.info('using %s', USBDevice.__module__)
        self.dev = USBDevice(0x1941, 0x8021)

    def read_block(self, address):
        """Read 32 bytes from the weather station.

        If the read fails for any reason, :obj:`None` is returned.

        :param address: address to read from.

        :type address: int

        :return: the data from the weather station.

        :rtype: list(int)

        """
        buf = [
            self.ReadCommand,
            address // 256,
            address % 256,
            self.EndMark,
            self.ReadCommand,
            address // 256,
            address % 256,
            self.EndMark,
            ]
        if not self.dev.write_data(buf):
            return None
        return self.dev.read_data(32)

    def write_byte(self, address, data):
        """Write a single byte to the weather station.

        :param address: address to write to.

        :type address: int

        :param data: the value to write.

        :type data: int

        :return: success status.

        :rtype: bool

        """
        buf = [
            self.WriteCommandWord,
            address // 256,
            address % 256,
            self.EndMark,
            self.WriteCommandWord,
            data,
            0,
            self.EndMark,
            ]
        if not self.dev.write_data(buf):
            return False
        buf = self.dev.read_data(8)
        if buf is None:
            return False
        for byte in buf:
            if byte != 0xA5:
                return False
        return True
Пример #4
0
class CUSBDrive(object):
    """Low level interface to weather station via USB.

    Loosely modeled on a C++ class obtained from
    http://site.ambientweatherstore.com/easyweather/ws_1080_2080_protocol.zip.
    I don't know the provenance of this, but it looks as if it may
    have come from the manufacturer.

    """
    EndMark          = 0x20
    ReadCommand      = 0xA1
    WriteCommand     = 0xA0
    WriteCommandWord = 0xA2

    def __init__(self, library):
        global USBDevice
        self.logger = logging.getLogger('pywws.WeatherStation.CUSBDrive')
        if not USBDevice and library in ('auto', 'cython-hidapi'):
            try:
                from device_cython_hidapi import USBDevice
            except ImportError:
                if library != 'auto':
                    raise
        if not USBDevice:
            from device_pyusb import USBDevice
        self.logger.info('using %s', USBDevice.__module__)
        self.dev = USBDevice(0x1941, 0x8021)

    def read_block(self, address):
        """Read 32 bytes from the weather station.

        If the read fails for any reason, :obj:`None` is returned.

        :param address: address to read from.

        :type address: int

        :return: the data from the weather station.

        :rtype: list(int)

        """
        buf = [
            self.ReadCommand,
            address // 256,
            address % 256,
            self.EndMark,
            self.ReadCommand,
            address // 256,
            address % 256,
            self.EndMark,
            ]
        if not self.dev.write_data(buf):
            return None
        return self.dev.read_data(32)

    def write_byte(self, address, data):
        """Write a single byte to the weather station.

        :param address: address to write to.

        :type address: int

        :param data: the value to write.

        :type data: int

        :return: success status.

        :rtype: bool

        """
        buf = [
            self.WriteCommandWord,
            address // 256,
            address % 256,
            self.EndMark,
            self.WriteCommandWord,
            data,
            0,
            self.EndMark,
            ]
        if not self.dev.write_data(buf):
            return False
        buf = self.dev.read_data(8)
        if buf is None:
            return False
        for byte in buf:
            if byte != 0xA5:
                return False
        return True