本文整理汇总了Python中usb._interop.as_array函数的典型用法代码示例。如果您正苦于以下问题:Python as_array函数的具体用法?Python as_array怎么用?Python as_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了as_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ctrl_transfer
def ctrl_transfer(self,
dev_handle,
bmRequestType,
bRequest,
wValue,
wIndex,
data_or_wLength,
timeout):
request = _openusb_ctrl_request()
request.setup.bmRequestType = bmRequestType
request.setup.bRequest = bRequest
request.setup.wValue
request.setup.wIndex
request.timeout = timeout
direction = usb.util.ctrl_direction(bmRequestType)
if direction == usb.util.CTRL_OUT:
buffer = data_or_wLength
else:
buffer = _interop.as_array('\x00' * data_or_wLength)
payload, request.length = buffer.buffer_info()
request.payload = cast(payload, POINTER(c_uint8))
_check(_lib.openusb_ctrl_xfer(dev_handle, 0, 0, byref(request)))
if direction == usb.util.CTRL_OUT:
return request.result.transferred_bytes
else:
return buffer[:request.result.transferred_bytes]
示例2: ctrl_transfer
def ctrl_transfer(self, bmRequestType, bRequest, wValue=0, wIndex=0, data_or_wLength=None, timeout=None):
r"""Do a control transfer on the endpoint 0.
This method is used to issue a control transfer over the
endpoint 0(endpoint 0 is required to always be a control endpoint).
The parameters bmRequestType, bRequest, wValue and wIndex are the
same of the USB Standard Control Request format.
Control requests may or may not have a data payload to write/read.
In cases which it has, the direction bit of the bmRequestType
field is used to infere the desired request direction. For
host to device requests (OUT), data_or_wLength parameter is
the data payload to send, and it must be a sequence type convertible
to an array object. In this case, the return value is the number of data
payload written. For device to host requests (IN), data_or_wLength
is the wLength parameter of the control request specifying the
number of bytes to read in data payload. In this case, the return
value is the data payload read, as an array object.
"""
if util.ctrl_direction(bmRequestType) == util.CTRL_OUT:
a = _interop.as_array(data_or_wLength)
elif data_or_wLength is None:
a = 0
else:
a = data_or_wLength
self._ctx.managed_open()
return self._ctx.backend.ctrl_transfer(
self._ctx.handle, bmRequestType, bRequest, wValue, wIndex, a, self.__get_timeout(timeout)
)
示例3: ctrl_transfer
def ctrl_transfer(self,
dev_handle,
bmRequestType,
bRequest,
wValue,
wIndex,
data_or_wLength,
timeout):
if usb.util.ctrl_direction(bmRequestType) == usb.util.CTRL_OUT:
buff = data_or_wLength
else:
buff = _interop.as_array((0,) * data_or_wLength)
addr, length = buff.buffer_info()
length *= buff.itemsize
ret = _check(_lib.libusb_control_transfer(dev_handle,
bmRequestType,
bRequest,
wValue,
wIndex,
cast(addr,
POINTER(c_ubyte)),
length,
timeout))
if usb.util.ctrl_direction(bmRequestType) == usb.util.CTRL_OUT:
return ret.value
else:
return buff[:ret.value]
示例4: write
def write(self, endpoint, data, timeout = None):
r"""Write data to the endpoint.
This method is used to send data to the device. The endpoint parameter
corresponds to the bEndpointAddress member whose endpoint you want to
communicate with.
The data parameter should be a sequence like type convertible to
the array type (see array module).
The timeout is specified in miliseconds.
The method returns the number of bytes written.
"""
backend = self._ctx.backend
fn_map = {
util.ENDPOINT_TYPE_BULK:backend.bulk_write,
util.ENDPOINT_TYPE_INTR:backend.intr_write,
util.ENDPOINT_TYPE_ISO:backend.iso_write
}
intf, ep = self._ctx.setup_request(self, endpoint)
fn = fn_map[util.endpoint_type(ep.bmAttributes)]
return fn(
self._ctx.handle,
ep.bEndpointAddress,
intf.bInterfaceNumber,
_interop.as_array(data),
self.__get_timeout(timeout)
)
示例5: ctrl_transfer
def ctrl_transfer(self,
dev_handle,
bmRequestType,
bRequest,
wValue,
wIndex,
data_or_wLength,
timeout):
if usb.util.ctrl_direction(bmRequestType) == usb.util.CTRL_OUT:
address, length = data_or_wLength.buffer_info()
length *= data_or_wLength.itemsize
return _check(_lib.usb_control_msg(
dev_handle,
bmRequestType,
bRequest,
wValue,
wIndex,
cast(address, c_char_p),
length,
timeout
))
else:
data = _interop.as_array((0,) * data_or_wLength)
read = int(_check(_lib.usb_control_msg(
dev_handle,
bmRequestType,
bRequest,
wValue,
wIndex,
cast(data.buffer_info()[0],
c_char_p),
data_or_wLength,
timeout
)))
return data[:read]
示例6: write
def write(self, endpoint, data, interface=None, timeout=None):
r"""Write data to the endpoint.
This method is used to send data to the device. The endpoint parameter
corresponds to the bEndpointAddress member whose endpoint you want to
communicate with. The interface parameter is the bInterfaceNumber field
of the interface descriptor which contains the endpoint. If you do not
provide one, the first one found will be used, as explained in the
set_interface_altsetting() method.
The data parameter should be a sequence like type convertible to
array type (see array module).
The timeout is specified in miliseconds.
The method returns the number of bytes written.
"""
backend = self._ctx.backend
fn_map = {
util.ENDPOINT_TYPE_BULK: backend.bulk_write,
util.ENDPOINT_TYPE_INTR: backend.intr_write,
util.ENDPOINT_TYPE_ISO: backend.iso_write,
}
intf = self._ctx.get_interface(self, interface)
fn = fn_map[self._ctx.get_endpoint_type(self, endpoint, intf)]
self._ctx.managed_claim_interface(self, intf)
return fn(
self._ctx.handle, endpoint, intf.bInterfaceNumber, _interop.as_array(data), self.__get_timeout(timeout)
)
示例7: intr_read
def intr_read(self, dev_handle, ep, intf, size, timeout):
request = _openusb_intr_request()
buffer = _interop.as_array('B', '\x00' * size)
memset(byref(request), 0, sizeof(request))
payload, request.length = buffer.buffer_info()
request.payload = cast(payload, POINTER(c_uint8))
request.timeout = timeout
_check(_lib.openusb_intr_xfer(dev_handle, intf, ep, byref(request)))
return buffer[:request.result.transferred_bytes]
示例8: ctrl_transfer
def ctrl_transfer(self, bmRequestType, bRequest, wValue=0, wIndex=0,
data_or_wLength = None, timeout = None):
r"""Do a control transfer on the endpoint 0.
This method is used to issue a control transfer over the endpoint 0
(endpoint 0 is required to always be a control endpoint).
The parameters bmRequestType, bRequest, wValue and wIndex are the same
of the USB Standard Control Request format.
Control requests may or may not have a data payload to write/read.
In cases which it has, the direction bit of the bmRequestType
field is used to infer the desired request direction. For
host to device requests (OUT), data_or_wLength parameter is
the data payload to send, and it must be a sequence type convertible
to an array object. In this case, the return value is the number
of bytes written in the data payload. For device to host requests
(IN), data_or_wLength is either the wLength parameter of the control
request specifying the number of bytes to read in data payload, and
the return value is an array object with data read, or an array
object which the data will be read to, and the return value is the
number of bytes read.
"""
try:
buff = util.create_buffer(data_or_wLength)
except TypeError:
buff = _interop.as_array(data_or_wLength)
self._ctx.managed_open()
# Thanks to Johannes Stezenbach to point me out that we need to
# claim the recipient interface
recipient = bmRequestType & 3
rqtype = bmRequestType & (3 << 5)
if recipient == util.CTRL_RECIPIENT_INTERFACE \
and rqtype != util.CTRL_TYPE_VENDOR:
interface_number = wIndex & 0xff
self._ctx.managed_claim_interface(self, interface_number)
ret = self._ctx.backend.ctrl_transfer(
self._ctx.handle,
bmRequestType,
bRequest,
wValue,
wIndex,
buff,
self.__get_timeout(timeout))
if isinstance(data_or_wLength, array.array) \
or util.ctrl_direction(bmRequestType) == util.CTRL_OUT:
return ret
elif ret != len(buff) * buff.itemsize:
return buff[:ret]
else:
return buff
示例9: __read
def __read(self, fn, dev_handle, ep, intf, size, timeout):
data = _interop.as_array((0,) * size)
address, length = data.buffer_info()
length *= data.itemsize
ret = int(_check(fn(
dev_handle,
ep,
cast(address, c_char_p),
length,
timeout
)))
return data[:ret]
示例10: __read
def __read(self, fn, dev_handle, ep, intf, size, timeout):
data = _interop.as_array((0,) * size)
address, length = data.buffer_info()
length *= data.itemsize
transferred = c_int()
_check(fn(dev_handle,
ep,
cast(address, POINTER(c_ubyte)),
length,
byref(transferred),
timeout))
return data[:transferred.value]
示例11: clear_halt
def clear_halt(self, dev_handle, ep):
bmRequestType = util.build_request_type(
util.CTRL_OUT,
util.CTRL_TYPE_STANDARD,
util.CTRL_RECIPIENT_ENDPOINT)
self.ctrl_transfer(
dev_handle,
bmRequestType,
0x03,
0,
ep,
_interop.as_array(),
1000)
示例12: __read
def __read(self, fn, dev_handle, ep, intf, size, timeout):
data = _interop.as_array((0,) * size)
address, length = data.buffer_info()
length *= data.itemsize
transferred = c_int()
retval = fn(dev_handle,
ep,
cast(address, POINTER(c_ubyte)),
length,
byref(transferred),
timeout)
# do not assume LIBUSB_ERROR_TIMEOUT means no I/O.
if not (transferred.value and retval == LIBUSB_ERROR_TIMEOUT):
_check(retval)
return data[:transferred.value]
示例13: __read
def __read(self, fn, dev_handle, ep, intf, data, size, timeout):
read_into = (data != None)
if not read_into:
data = _interop.as_array((0,) * size)
address, length = data.buffer_info()
length *= data.itemsize
ret = int(_check(fn(
dev_handle,
ep,
cast(address, c_char_p),
length,
timeout
)))
if read_into:
return ret
else:
return data[:ret]
示例14: to_array
def to_array(data):
return _interop.as_array(data)
示例15: get_array_data2
def get_array_data2(length=10):
data = list(range(length))
data.reverse()
return _interop.as_array(data)