o add bsnes
This commit is contained in:
14
pyusb/PKG-INFO
Normal file
14
pyusb/PKG-INFO
Normal file
@@ -0,0 +1,14 @@
|
||||
Metadata-Version: 1.0
|
||||
Name: pyusb
|
||||
Version: 0.4.1
|
||||
Summary: USB access extension module
|
||||
Home-page: http://pyusb.berlios.de
|
||||
Author: Wander Lairson Costa
|
||||
Author-email: wander.lairson@gmail.com
|
||||
License: BSD
|
||||
Description:
|
||||
PyUSB provides easy USB access to python.
|
||||
The module contains classes and methods to
|
||||
support the most USB operations.
|
||||
|
||||
Platform: UNKNOWN
|
||||
144
pyusb/README
Normal file
144
pyusb/README
Normal file
@@ -0,0 +1,144 @@
|
||||
PyUSB - USB Access from Python
|
||||
==============================
|
||||
|
||||
The PyUSB module provides Python with easy access to the host
|
||||
machine's Universal Serial Bus (USB) system. Although not yet
|
||||
complete, PyUSB does provide a core set of functionality around which
|
||||
useful applications can be developed.
|
||||
|
||||
As with most Python modules, PyUSB's documentation is based on Python
|
||||
doc strings and can therefore be manipulated by tools such as pydoc.
|
||||
|
||||
PyUSB was developed and tested on the Slackware GNU/Linux
|
||||
distribution and Windows XP Professional. Some testing has been done on Ubuntu,
|
||||
Mac OS X and FreeBSD.
|
||||
|
||||
If you have any question about PyUSB, you can contact the author at
|
||||
wander (dot) lairson (at) gmail (dot) com.
|
||||
|
||||
Installing PyUSB on GNU/Linux Systems
|
||||
=====================================
|
||||
|
||||
These instructions are for Debian-based systems. Instructions for
|
||||
other flavors of GNU/Linux should be similar.
|
||||
|
||||
You will first need to install the following packages:
|
||||
|
||||
1) python (PyUSB is useless without it)
|
||||
2) gcc (the compiler, linker, etc.)
|
||||
3) python-dev (includes header files needed to compile PyUSB)
|
||||
4) libusb-dev (C library upon which PyUSB is based)
|
||||
|
||||
For example, the command
|
||||
|
||||
sudo apt-get install python gcc python-dev libusb-dev
|
||||
|
||||
should install all these packages on most Debian-based systems with
|
||||
access to the proper package repositories.
|
||||
|
||||
Once the above packages are installed, you can build and install PyUSB
|
||||
with the command
|
||||
|
||||
python setup.py install
|
||||
|
||||
run as root from within the same directory as this README file.
|
||||
|
||||
Installing PyUSB on Windows
|
||||
===========================
|
||||
|
||||
These instructions are for installing PyUSB in a Cygwin environment.
|
||||
See the end of this section for notes on installing in a Visual C++
|
||||
environment.
|
||||
|
||||
You will first need to install the following software:
|
||||
|
||||
1) Cygwin: A Linux-like environment for Windows available from
|
||||
http://www.cygwin.com. Be sure to include GCC and Python with the
|
||||
Cygwin installation.
|
||||
|
||||
2) libusb-win32: a Windows version of the libusb C library available
|
||||
from http://libusb-win32.sourceforge.net.
|
||||
|
||||
From within a Cygwin terminal, copy the libusb.a file from the
|
||||
libusb-win32 lib/ directory to $(CYGWINDIR)/usr/lib/, and copy the
|
||||
usb.h file from the libusb-win32 include/ directory to
|
||||
$(CYGWINDIR)/usr/include/. You can build and install PyUSB with the
|
||||
command
|
||||
|
||||
python setup.py install
|
||||
|
||||
run from within the same directory as this README file.
|
||||
|
||||
To build PyUSB using Visual C++, use Python's distutils tool, which
|
||||
might request that .NET SDK Framework be installed first.
|
||||
Alternatively, you can use the Visual C++ .NET 2005 project solution
|
||||
included in the same directory as this README file. In this case, you
|
||||
will need to manually change the project settings to include the
|
||||
Python and libusb-win32 headers and libraries in the Visual C++ path.
|
||||
|
||||
USAGE
|
||||
=====
|
||||
|
||||
This Python program is an example of how PyUSB can be used.
|
||||
|
||||
#
|
||||
# Open a device, look at the alternate interfaces, use the device, and
|
||||
# then close the connection.
|
||||
#
|
||||
|
||||
import usb # import the usb module
|
||||
|
||||
bus = usb.busses() # get a list of all available busses
|
||||
|
||||
dev = bus[0].devices[0] # choose the first device on the first bus
|
||||
|
||||
handle = dev.open() # open the device
|
||||
|
||||
for alt in dev.configurations[0].interfaces[0]:
|
||||
print alt # look at the alternate settings.
|
||||
|
||||
handle.setConfiguration(0) # choose the first configuration
|
||||
|
||||
handle.claimInterface(0) # choose the first interface
|
||||
|
||||
### Use the device here. ###
|
||||
|
||||
handle.releaseInterface() # also called automatically on __del__
|
||||
|
||||
|
||||
TODO/ROADMAP
|
||||
============
|
||||
|
||||
- more tests
|
||||
- more samples
|
||||
- better documentation
|
||||
- utility functions to find devices
|
||||
|
||||
|
||||
ACKNOWLEDGEMENTS
|
||||
================
|
||||
|
||||
Thanks to the following people for their help and contributions to the
|
||||
PyUSB project. Where possible, there contributions are noted in the
|
||||
source code.
|
||||
|
||||
- Damian Staniforth
|
||||
- Brenno Diegoli
|
||||
- Israel Florentino
|
||||
- Xiaofan Chen
|
||||
- Mario Olimpio de Menezes
|
||||
- Renato Manzan
|
||||
- Ray Schumacher
|
||||
- Mark Rages
|
||||
- James Barabas
|
||||
- Andrew Rogers
|
||||
- Juha Torkkel
|
||||
- Josh Lifton
|
||||
- David Merrill
|
||||
- Srikanth Jandhyala
|
||||
- Alexander Krause
|
||||
- Yael Maguire
|
||||
- Lucio Torre
|
||||
- Simeon Miteff
|
||||
|
||||
PS: this great README file was written by Josh Lifton... :-)
|
||||
28
pyusb/license.txt
Normal file
28
pyusb/license.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
Copyright (C) 2005 - 2007 Wander Lairson Costa
|
||||
|
||||
The following terms apply to all files associated
|
||||
with the software unless explicitly disclaimed in individual files.
|
||||
|
||||
The authors hereby grant permission to use, copy, modify, distribute,
|
||||
and license this software and its documentation for any purpose, provided
|
||||
that existing copyright notices are retained in all copies and that this
|
||||
notice is included verbatim in any distributions. No written agreement,
|
||||
license, or royalty fee is required for any of the authorized uses.
|
||||
Modifications to this software may be copyrighted by their authors
|
||||
and need not follow the licensing terms described here, provided that
|
||||
the new terms are clearly indicated on the first page of each file where
|
||||
they apply.
|
||||
|
||||
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
|
||||
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
||||
ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
|
||||
DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
|
||||
IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
|
||||
NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||
MODIFICATIONS.
|
||||
|
||||
2149
pyusb/pyusb.c
Normal file
2149
pyusb/pyusb.c
Normal file
File diff suppressed because it is too large
Load Diff
248
pyusb/pyusb.h
Normal file
248
pyusb/pyusb.h
Normal file
@@ -0,0 +1,248 @@
|
||||
#ifndef __pyusb_h__
|
||||
#define __pyusb_h__
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
#include <usb.h>
|
||||
#ifdef unix
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#endif /* unix */
|
||||
#if 0 /* defined _WIN32 */
|
||||
/*
|
||||
* I were having many problems trying compile with windows.h
|
||||
* because the Visual C++ .NET language extensions
|
||||
*/
|
||||
#include <windows.h>
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#define STRING_ARRAY_SIZE 256
|
||||
|
||||
#define PYUSB_STATIC static
|
||||
|
||||
#if defined _WIN32 && !defined unix
|
||||
|
||||
#ifndef u_int8_t
|
||||
typedef unsigned char u_int8_t;
|
||||
#endif /* u_int8_t */
|
||||
|
||||
#ifndef u_int16_t
|
||||
typedef unsigned short int u_int16_t;
|
||||
#endif /* u_int16_t */
|
||||
|
||||
#ifndef u_int32_t
|
||||
typedef unsigned long u_int32_t;
|
||||
#endif /* u_int32_t */
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 255
|
||||
#endif /* PATH_MAX */
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
/*
|
||||
* EndpointDescriptor object
|
||||
*/
|
||||
typedef struct _Py_usb_Endpoint {
|
||||
PyObject_HEAD
|
||||
u_int8_t address;
|
||||
u_int8_t type;
|
||||
u_int16_t maxPacketSize;
|
||||
u_int8_t interval;
|
||||
u_int8_t refresh;
|
||||
} Py_usb_Endpoint;
|
||||
|
||||
|
||||
/*
|
||||
* Interface Object
|
||||
*/
|
||||
typedef struct _Py_usb_Interface {
|
||||
PyObject_HEAD
|
||||
u_int8_t interfaceNumber;
|
||||
u_int8_t alternateSetting;
|
||||
u_int8_t interfaceClass;
|
||||
u_int8_t interfaceSubClass;
|
||||
u_int8_t interfaceProtocol;
|
||||
u_int8_t iInterface;
|
||||
PyObject *endpoints;
|
||||
} Py_usb_Interface;
|
||||
|
||||
/*
|
||||
* Configuration object
|
||||
*/
|
||||
typedef struct _Py_usb_Configuration {
|
||||
PyObject_HEAD
|
||||
u_int16_t totalLength;
|
||||
u_int8_t value;
|
||||
u_int8_t iConfiguration;
|
||||
u_int8_t selfPowered;
|
||||
u_int8_t remoteWakeup;
|
||||
u_int16_t maxPower;
|
||||
PyObject *interfaces;
|
||||
} Py_usb_Configuration;
|
||||
|
||||
/*
|
||||
* Device object
|
||||
*/
|
||||
typedef struct _Py_usb_Device {
|
||||
PyObject_HEAD
|
||||
char usbVersion[STRING_ARRAY_SIZE];
|
||||
u_int8_t deviceClass;
|
||||
u_int8_t deviceSubClass;
|
||||
u_int8_t deviceProtocol;
|
||||
u_int8_t maxPacketSize;
|
||||
u_int16_t idVendor;
|
||||
u_int16_t idProduct;
|
||||
char deviceVersion[STRING_ARRAY_SIZE];
|
||||
u_int8_t iManufacturer;
|
||||
u_int8_t iProduct;
|
||||
u_int8_t iSerialNumber;
|
||||
char filename[PATH_MAX + 1];
|
||||
PyObject *configurations;
|
||||
struct usb_device *dev; // necessary for usb_open
|
||||
} Py_usb_Device;
|
||||
|
||||
/*
|
||||
* Bus Object
|
||||
*/
|
||||
typedef struct _Py_usb_Bus {
|
||||
PyObject_HEAD
|
||||
char dirname[PATH_MAX + 1];
|
||||
u_int32_t location;
|
||||
PyObject *devices;
|
||||
} Py_usb_Bus;
|
||||
|
||||
/*
|
||||
* DeviceHandle object
|
||||
*/
|
||||
typedef struct _Py_usb_DeviceHandle {
|
||||
PyObject_HEAD
|
||||
usb_dev_handle *deviceHandle;
|
||||
int interfaceClaimed;
|
||||
} Py_usb_DeviceHandle;
|
||||
|
||||
/*
|
||||
* Functions prototypes
|
||||
*/
|
||||
|
||||
PYUSB_STATIC void set_Endpoint_fields(
|
||||
Py_usb_Endpoint *endpoint,
|
||||
struct usb_endpoint_descriptor *ep
|
||||
);
|
||||
|
||||
PYUSB_STATIC Py_usb_Endpoint *new_Endpoint(
|
||||
struct usb_endpoint_descriptor *ep
|
||||
);
|
||||
|
||||
PYUSB_STATIC void set_Interface_fields(
|
||||
Py_usb_Interface *interface,
|
||||
struct usb_interface_descriptor *i
|
||||
);
|
||||
|
||||
PYUSB_STATIC Py_usb_Interface *new_Interface(
|
||||
struct usb_interface_descriptor *i
|
||||
);
|
||||
|
||||
PYUSB_STATIC void set_Configuration_fields(
|
||||
Py_usb_Configuration *configuration,
|
||||
struct usb_config_descriptor *config
|
||||
);
|
||||
|
||||
PYUSB_STATIC Py_usb_Configuration *new_Configuration(
|
||||
struct usb_config_descriptor *conf
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_Device_open(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
PYUSB_STATIC void set_Device_fields(
|
||||
Py_usb_Device *device,
|
||||
struct usb_device *dev
|
||||
);
|
||||
|
||||
PYUSB_STATIC Py_usb_Device *new_Device(
|
||||
struct usb_device *dev
|
||||
);
|
||||
|
||||
PYUSB_STATIC Py_usb_Bus *new_Bus(
|
||||
struct usb_bus *b
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_DeviceHandle_controlMsg(
|
||||
PyObject *self,
|
||||
PyObject *args,
|
||||
PyObject *kwds
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_DeviceHandle_setConfiguration(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_DeviceHandle_claimInterface(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_DeviceHandle_detachKernelDriver(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_DeviceHandle_releaseInterface(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_DeviceHandle_setAltInterface(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_DeviceHandle_bulkWrite(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_DeviceHandle_bulkRead(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_DeviceHandle_interruptWrite(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_DeviceHandle_interruptRead(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_DeviceHandle_resetEndpoint(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_DeviceHandle_reset(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *Py_usb_DeviceHandle_clearHalt(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
PYUSB_STATIC Py_usb_DeviceHandle *new_DeviceHandle(
|
||||
Py_usb_Device *device
|
||||
);
|
||||
|
||||
PYUSB_STATIC PyObject *busses(
|
||||
PyObject *self,
|
||||
PyObject *args
|
||||
);
|
||||
|
||||
#endif /* __pyusb_h__ */
|
||||
19
pyusb/pyusb.sln
Normal file
19
pyusb/pyusb.sln
Normal file
@@ -0,0 +1,19 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pyusb", "pyusb.vcproj", "{D59C735D-D69F-42BD-8664-3CA8BC1CED3C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D59C735D-D69F-42BD-8664-3CA8BC1CED3C}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{D59C735D-D69F-42BD-8664-3CA8BC1CED3C}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{D59C735D-D69F-42BD-8664-3CA8BC1CED3C}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{D59C735D-D69F-42BD-8664-3CA8BC1CED3C}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
40
pyusb/samples/usbenum.py
Normal file
40
pyusb/samples/usbenum.py
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Enumerate usb devices
|
||||
#
|
||||
#Copyright 2005 - 2007 Wander Lairson Costa
|
||||
|
||||
import usb
|
||||
|
||||
busses = usb.busses()
|
||||
|
||||
for bus in busses:
|
||||
devices = bus.devices
|
||||
for dev in devices:
|
||||
print "Device:", dev.filename
|
||||
print " Device class:",dev.deviceClass
|
||||
print " Device sub class:",dev.deviceSubClass
|
||||
print " Device protocol:",dev.deviceProtocol
|
||||
print " Max packet size:",dev.maxPacketSize
|
||||
print " idVendor:",dev.idVendor
|
||||
print " idProduct:",dev.idProduct
|
||||
print " Device Version:",dev.deviceVersion
|
||||
for config in dev.configurations:
|
||||
print " Configuration:", config.value
|
||||
print " Total length:", config.totalLength
|
||||
print " selfPowered:", config.selfPowered
|
||||
print " remoteWakeup:", config.remoteWakeup
|
||||
print " maxPower:", config.maxPower
|
||||
for intf in config.interfaces:
|
||||
print " Interface:",intf[0].interfaceNumber
|
||||
for alt in intf:
|
||||
print " Alternate Setting:",alt.alternateSetting
|
||||
print " Interface class:",alt.interfaceClass
|
||||
print " Interface sub class:",alt.interfaceSubClass
|
||||
print " Interface protocol:",alt.interfaceProtocol
|
||||
for ep in alt.endpoints:
|
||||
print " Endpoint:",hex(ep.address)
|
||||
print " Type:",ep.type
|
||||
print " Max packet size:",ep.maxPacketSize
|
||||
print " Interval:",ep.interval
|
||||
|
||||
125
pyusb/samples/usbprint.py
Normal file
125
pyusb/samples/usbprint.py
Normal file
@@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Provides an interface to USB Printer Class devices.
|
||||
"""
|
||||
|
||||
import usb
|
||||
import types
|
||||
|
||||
PRINTER_CLASS = 0x07
|
||||
PRINTER_SUBCLASS = 0x01
|
||||
UNIDIRECTIONAL_PROTOCOL = 0x01
|
||||
BIDIRECTIONAL_PROTOCOL = 0x02
|
||||
IEEE1284_4_PROTOCOL = 0x03
|
||||
VENDOR_PROTOCOL = 0xff
|
||||
|
||||
class Printer:
|
||||
def __init__(self, device, configuration, interface):
|
||||
"""
|
||||
__init__(device, configuration, interface) -> None
|
||||
|
||||
Initialize the device.
|
||||
device: printer usb.Device object.
|
||||
configuration: printer usb.Configuration object of the Device or configuration number.
|
||||
interface: printer usb.Interface object representing the
|
||||
interface and altenate setting.
|
||||
|
||||
"""
|
||||
if PRINTER_CLASS != interface.interfaceClass:
|
||||
raise TypeError, "Wrong interface class"
|
||||
|
||||
self.__devhandle = device.open()
|
||||
self.__devhandle.setConfiguration(configuration)
|
||||
self.__devhandle.claimInterface(interface)
|
||||
self.__devhandle.setAltInterface(interface)
|
||||
|
||||
self.__intf = interface.interfaceNumber
|
||||
self.__alt = interface.alternateSetting
|
||||
|
||||
self.__conf = (type(configuration) == types.IntType \
|
||||
or type(configuration) == types.LongType) and \
|
||||
configuration or \
|
||||
configuration.value
|
||||
|
||||
# initialize members
|
||||
# TODO: automatic endpoints detection
|
||||
self.__bulkout = 1
|
||||
self.__bulkin = 0x82
|
||||
|
||||
def __del__(self):
|
||||
try:
|
||||
self.__devhandle.releaseInterface(self.__intf)
|
||||
del self.__devhandle
|
||||
except:
|
||||
pass
|
||||
|
||||
def getDeviceID(self, maxlen, timeout = 100):
|
||||
"""
|
||||
getDeviceID(maxlen, timeout = 100) -> device_id
|
||||
|
||||
Get the device capabilities information.
|
||||
maxlen: maxlength of the buffer.
|
||||
timeout: operation timeout.
|
||||
"""
|
||||
return self.__devhandle.controlMsg(requestType = 0xa1,
|
||||
request = 0,
|
||||
value = self.__conf - 1,
|
||||
index = self.__alt + (self.__intf << 8),
|
||||
buffer = maxlen,
|
||||
timeout = timeout)
|
||||
|
||||
def getPortStatus(self, timeout = 100):
|
||||
"""
|
||||
getPortStatus(timeout = 100) -> status
|
||||
|
||||
Get the port status.
|
||||
timeout: operation timeout.
|
||||
"""
|
||||
return self.__devhandle.controlMsg(requestType = 0xa1,
|
||||
request = 1,
|
||||
value = 0,
|
||||
index = self.__intf,
|
||||
buffer = 1,
|
||||
timeout = timeout)[0]
|
||||
|
||||
def softReset(self, timeout = 100):
|
||||
"""
|
||||
softReset(timeout = 100) -> None
|
||||
|
||||
Request flushes all buffers and resets the Bulk OUT
|
||||
and Bulk IN pipes to their default states.
|
||||
timeout: the operation timeout.
|
||||
"""
|
||||
self.__devhandle.controlMsg(requestType = 0x21,
|
||||
request = 2,
|
||||
value = 0,
|
||||
index = self.__intf,
|
||||
buffer = 0)
|
||||
|
||||
|
||||
def write(self, buffer, timeout = 100):
|
||||
"""
|
||||
write(buffer, timeout = 100) -> written
|
||||
|
||||
Write data to printer.
|
||||
buffer: data buffer.
|
||||
timeout: operation timeout.
|
||||
"""
|
||||
return self.__devhandle.bulkWrite(self.__bulkout,
|
||||
buffer,
|
||||
timeout)
|
||||
|
||||
def read(self, numbytes, timeout = 100):
|
||||
"""
|
||||
read(numbytes, timeout = 100) -> data
|
||||
|
||||
Read data from printer.
|
||||
numbytes: number of bytes to read.
|
||||
timeout: operation timeout.
|
||||
"""
|
||||
return self.__devhandle.bulkRead(self.__bulkin,
|
||||
numbytes,
|
||||
timeout)
|
||||
|
||||
|
||||
64
pyusb/setup.py
Normal file
64
pyusb/setup.py
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# PyUSB setup script
|
||||
#
|
||||
# Copyright 2005 - 2007 Wander Lairson Costa
|
||||
|
||||
from distutils.core import setup, Extension
|
||||
import sys
|
||||
|
||||
extra_link_args = []
|
||||
extra_compile_args = []
|
||||
platform = sys.platform.lower()
|
||||
libraries = ["usb"]
|
||||
|
||||
# necessary to work fine in MacOS
|
||||
# many thanks to Damian Staniforth! :-)
|
||||
if -1 != platform.find("mac"):
|
||||
extra_link_args = ['-framework',
|
||||
'CoreFoundation',
|
||||
'-framework',
|
||||
'IOKit']
|
||||
elif -1 != platform.find("win32"):
|
||||
libraries = ["libusb"]
|
||||
# necessary to work fine in darwin
|
||||
# Many thanks to James Barabas!
|
||||
elif -1 != platform.find("darwin"):
|
||||
extra_link_args = ['-framework',
|
||||
'CoreFoundation',
|
||||
'-framework',
|
||||
'IOKit',
|
||||
'-L/opt/local/lib']
|
||||
extra_compile_args = ['-I/opt/local/include']
|
||||
# Juha Torkkel has reported problems compiling on freebsd
|
||||
# when libusb is in /usr/local tree. I don't know on freebsd, but
|
||||
# on Linux the paths to usr/local are in $PATH.
|
||||
# Thanks Juha... ;)
|
||||
elif -1 != platform.find("freebsd"):
|
||||
extra_link_args = ['-L/usr/local/lib']
|
||||
extra_compile_args = ['-I/usr/local/include']
|
||||
|
||||
|
||||
usbmodule = Extension(name = 'usb',
|
||||
libraries = libraries,
|
||||
sources = ['pyusb.c'],
|
||||
extra_link_args = extra_link_args,
|
||||
extra_compile_args = extra_compile_args,
|
||||
depends = ['pyusb.h'])
|
||||
|
||||
setup(name = 'pyusb',
|
||||
version = '0.4.1',
|
||||
description = "USB access extension module",
|
||||
long_description =
|
||||
"""
|
||||
PyUSB provides easy USB access to python.
|
||||
The module contains classes and methods to
|
||||
support the most USB operations.
|
||||
""",
|
||||
author = 'Wander Lairson Costa',
|
||||
author_email = 'wander.lairson@gmail.com',
|
||||
url = 'http://pyusb.berlios.de',
|
||||
license = 'BSD',
|
||||
ext_modules = [usbmodule])
|
||||
|
||||
# vim:ts=4
|
||||
Reference in New Issue
Block a user