### Navigation

- index
- modules |
- next |
- previous |
- pywws 14.03.dev1177 documentation »
- Python programs and modules »

# pywws.device_ctypes_hidapi

Low level USB interface to weather station, using ctypes to access hidapi.

## Introduction

This module handles low level communication with the weather station via ctypes and the hidapi library. Alternative modules, pywws.device_cython_hidapi and pywws.device_pyusb, use other libraries. The choice of which module to use depends on which libraries are available for you computer.

Users of recent versions of Mac OS have less choice. The operating system makes it very difficult to access HID devices (such as the weather station) directly, so the `hidapi` library has to be used.

Users of OpenWRT and similar embedded Linux platforms will probably not be able to install `ctypes` or `cython-hidapi`, so are constrained to use `libusb` and its `PyUSB` Python interface.

## Installation

Some of this software may already be installed on your machine, so do check before downloading sources and compiling them yourself.

1. Install hidapi.

   Create a local copy of the git repository, change to the new directory and then follow the instructions in `README.txt`:

       git clone https://github.com/signal11/hidapi.git
       cd hidapi
       more README.txt

2. Install ctypes.

   This should be available as a package for your operating system. For example:

       sudo zypper install python-ctypes

## Testing

Run `TestWeatherStation.py` with increased verbosity so it reports which USB device access module is being used:

    python TestWeatherStation.py -vv
    18:10:27:pywws.WeatherStation.CUSBDrive:using pywws.device_ctypes_hidapi
    0000 55 aa ff ff ff ff ff ff ff ff ff ff ff ff ff ff 05 20 01 51 11 00 00 00 81 00 00 07 01 00 d0 56
    0020 61 1c 61 1c 00 00 00 00 00 00 00 12 02 14 18 09 41 23 c8 00 32 80 47 2d 2c 01 2c 81 5e 01 1e 80
    0040 a0 00 c8 80 a0 28 80 25 a0 28 80 25 03 36 00 05 6b 00 00 0a 00 f4 01 18 00 00 00 00 00 00 00 00
    0060 00 00 54 1c 63 0a 2f 01 71 00 7a 01 59 80 7a 01 59 80 e4 00 f5 ff 69 54 00 00 fe ff 00 00 b3 01
    0080 0c 02 d0 ff d3 ff 5a 24 d2 24 dc 17 00 11 09 06 15 40 10 03 07 22 18 10 08 11 08 30 11 03 07 12
    00a0 36 08 07 24 17 17 11 02 28 10 10 09 06 30 14 29 12 02 11 06 57 09 06 30 14 29 12 02 11 06 57 08
    00c0 08 31 14 30 12 02 14 18 04 12 02 01 10 12 11 09 13 17 19 11 08 21 16 53 11 09 13 17 19 12 01 18
    00e0 07 17 10 02 22 11 06 11 11 06 13 12 11 11 06 13 12 11 11 10 11 38 11 11 10 11 38 10 02 22 14 43

## API

Functions

`find_library`(name) |

Classes

`USBDevice`(vendor_id, product_id) | Low level USB device access via hidapi library.

class `pywws.device_ctypes_hidapi.``USBDevice`(vendor_id, product_id)

  Low level USB device access via hidapi library.

  Parameters: | idVendor (int) – the USB “vendor ID” number, for example 0x1941. idProduct (int) – the USB “product ID” number, for example 0x8021.

  `read_data`(size)

    Receive data from the device.

    If the read fails for any reason, an `IOError` exception is raised.

    Parameters: | size (int) – the number of bytes to read.
    Returns: | the data received.
    Return type: | list(int)

  `write_data`(buf)

    Send data to the device.

    Parameters: | buf (list(int)) – the data to send.
    Returns: | success status.
    Return type: | bool

### Navigation

- index
- modules |
- next |
- previous |
- pywws 14.03.dev1177 documentation »
- Python programs and modules »