• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python _interop.as_array函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中usb._interop.as_array函数的典型用法代码示例。如果您正苦于以下问题:Python as_array函数的具体用法?Python as_array怎么用?Python as_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了as_array函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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]
开发者ID:La0,项目名称:GFrun,代码行数:31,代码来源:openusb.py


示例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)
        )
开发者ID:storm9789,项目名称:pyalienfx,代码行数:32,代码来源:core.py


示例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]
开发者ID:archels,项目名称:pyusb,代码行数:30,代码来源:libusb1.py


示例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)
            )
开发者ID:mull3rcw,项目名称:python_mt_unitTest,代码行数:32,代码来源:core.py


示例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]
开发者ID:hut8,项目名称:pyalienfx,代码行数:35,代码来源:libusb01.py


示例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)
        )
开发者ID:storm9789,项目名称:pyalienfx,代码行数:32,代码来源:core.py


示例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]
开发者ID:La0,项目名称:GFrun,代码行数:9,代码来源:openusb.py


示例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
开发者ID:mull3rcw,项目名称:python_mt_unitTest,代码行数:55,代码来源:core.py


示例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]
开发者ID:hut8,项目名称:pyalienfx,代码行数:12,代码来源:libusb01.py


示例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]
开发者ID:AgustinParmisano,项目名称:pinguino32,代码行数:12,代码来源:libusb10.py


示例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)
开发者ID:dywisor,项目名称:pyusb,代码行数:13,代码来源:openusb.py


示例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]
开发者ID:archels,项目名称:pyusb,代码行数:15,代码来源:libusb1.py


示例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]
开发者ID:wmvanvliet,项目名称:pyusb,代码行数:17,代码来源:libusb0.py


示例14: to_array

def to_array(data):
    return _interop.as_array(data)
开发者ID:unknownskl,项目名称:pyRecovery,代码行数:2,代码来源:utils.py


示例15: get_array_data2

def get_array_data2(length=10):
    data = list(range(length))
    data.reverse()
    return _interop.as_array(data)
开发者ID:unknownskl,项目名称:pyRecovery,代码行数:4,代码来源:utils.py


示例16: data_len

def data_len(data):
    a = _interop.as_array(data)
    return len(data) * a.itemsize
开发者ID:unknownskl,项目名称:pyRecovery,代码行数:3,代码来源:utils.py


示例17: get_array_data1

def get_array_data1(length=10):
    return _interop.as_array(range(length))
开发者ID:unknownskl,项目名称:pyRecovery,代码行数:2,代码来源:utils.py


示例18: iso_read

 def iso_read(self, dev_handle, ep, intf, size, timeout):
     data = _interop.as_array('\x00' * size)
     handler = _IsoTransferHandler(dev_handle, ep, data, timeout)
     return data[:handler.submit(self.ctx)]
开发者ID:ElectricalTechnicalSpectacle,项目名称:usb,代码行数:4,代码来源:libusb1.py



注:本文中的usb._interop.as_array函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.endpoint_type函数代码示例发布时间:2022-05-27
下一篇:
Python usb.busses函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap