PyUSB: reading from a USB device

后端 未结 5 1513
攒了一身酷
攒了一身酷 2021-01-22 10:36

This is an updated and shortened question.

Communicating with a USB-device should be easy via PyUSB. So, I\'m trying to read from a USB-device (oscilloscope) using PyUSB

5条回答
  •  被撕碎了的回忆
    2021-01-22 11:05

    Once you get the response from the device on *IDN? query you should be good to go. This is SCPI ;)

    Try to send :CHAN1:SCAL 10v, and watch the display. It should change the vertical scale of channel 1 to 10V/div.

    Watch this video, it will help you get a grip.

    On your question about read() parameters. Quoting the PyUSB source:

    def read(self, endpoint, size_or_buffer, timeout = None):
        r"""Read data from the endpoint.
        This method is used to receive data from the device. The endpoint
        parameter corresponds to the bEndpointAddress member whose endpoint
        you want to communicate with. The size_or_buffer parameter either
        tells how many bytes you want to read or supplies the buffer to
        receive the data (it *must* be an object of the type array).
        The timeout is specified in miliseconds.
        If the size_or_buffer parameter is the number of bytes to read, the
        method returns an array object with the data read. If the
        size_or_buffer parameter is an array object, it returns the number
        of bytes actually read.
        """
    

    When the timeout is omitted, it is used the Device.default_timeout property as the operation timeout. Values are in milliseconds.

    If you set the buffer size big enough, you will get only the bytes actually read. So your expectations are correct.

提交回复
热议问题