Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pyvisa-py/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,30 @@ def disable_event(self, session, event_type, mechanism):
def discard_events(self, session, event_type, mechanism):
# TODO: implement this for GPIB finalization
pass

def usb_control_in(self, session, request_type_bitmap_field, request_id, request_value,
index, length=0):
"""Performs a USB control pipe transfer from the device.

Corresponds to viUsbControlIn function of the VISA library.

:param session: Unique logical identifier to a session.
:param request_type_bitmap_field: bmRequestType parameter of the setup stage of a USB control transfer.
:param request_id: bRequest parameter of the setup stage of a USB control transfer.
:param request_value: wValue parameter of the setup stage of a USB control transfer.
:param index: wIndex parameter of the setup stage of a USB control transfer.
This is usually the index of the interface or endpoint.
:param length: wLength parameter of the setup stage of a USB control transfer.
This value also specifies the size of the data buffer to receive the data from the
optional data stage of the control transfer.
:return: - The data buffer that receives the data from the optional data stage of the control transfer
- return value of the library call.
:rtype: - bytes
- :class:`pyvisa.constants.StatusCode`
"""
try:
sess = self.sessions[session]
except KeyError:
return StatusCode.error_invalid_object

return sess.control_transfer(request_type_bitmap_field, request_id, request_value, index, length)
Comment thread
Zanobos marked this conversation as resolved.
Outdated
28 changes: 27 additions & 1 deletion pyvisa-py/protocols/usbtmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ def write(self, data):
:param data: bytes to be sent to the instrument
:type data: bytes
"""

try:
return self.usb_send_ep.write(data)
except usb.core.USBError as e:
Expand Down Expand Up @@ -431,3 +430,30 @@ def read(self, size):
eom = response.transfer_attributes & 1

return bytes(received)

def control_transfer(self, request_type_bitmap_field, request_id, request_value,
index, length):
"""Performs a USB control pipe transfer from the device.

:param request_type_bitmap_field: bmRequestType parameter of the setup stage of a USB control transfer.
:param request_id: bRequest parameter of the setup stage of a USB control transfer.
:param request_value: wValue parameter of the setup stage of a USB control transfer.
:param index: wIndex parameter of the setup stage of a USB control transfer.
This is usually the index of the interface or endpoint.
:param length: wLength parameter of the setup stage of a USB control transfer.
This value also specifies the size of the data buffer to receive the data from the
optional data stage of the control transfer.
:return: - The data buffer that receives the data from the optional data stage of the control transfer
:rtype: - bytes
"""

self.usb_dev.ctrl_transfer(request_type_bitmap_field,
request_id,
request_value,
index,
length,
timeout=self.timeout)

#TODO satisfy the second half of the problem -i.e. sending buffer the optional data stage

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can try using to do a direct read. Using self.read means you are starting a full USBTMC request which is not what we want here. See https://github.com/pyvisa/pyvisa-py/blob/master/pyvisa-py/usb.py#L108

# return self.read(length) does not work
return bytes()
Comment thread
Zanobos marked this conversation as resolved.
Outdated
21 changes: 21 additions & 0 deletions pyvisa-py/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@ def write(self, data):

return count, StatusCode.success

def control_transfer(self, request_type_bitmap_field, request_id, request_value, index, length):
"""Performs a USB control pipe transfer from the device.

:param request_type_bitmap_field: bmRequestType parameter of the setup stage of a USB control transfer.
:param request_id: bRequest parameter of the setup stage of a USB control transfer.
:param request_value: wValue parameter of the setup stage of a USB control transfer.
:param index: wIndex parameter of the setup stage of a USB control transfer.
This is usually the index of the interface or endpoint.
:param length: wLength parameter of the setup stage of a USB control transfer.
This value also specifies the size of the data buffer to receive the data from the
optional data stage of the control transfer.

:return: - The data buffer that receives the data from the optional data stage of the control transfer
- return value of the library call.
:rtype: - bytes
- :class:`pyvisa.constants.StatusCode`
"""
ret_val = self.interface.control_transfer(request_type_bitmap_field, request_id,
request_value, index, length)
return ret_val, StatusCode.success

def close(self):
self.interface.close()

Expand Down