qmi.instruments.newport.newport_843r_libusb

Basic input/output access to the Newport 843-R power meter via USB.

This Python 3 module provides access to ASCII command interface of the Newport 843-R-USB via its proprietary USB protocol.

This module uses PyUSB and works only on Linux.

Access permission

To access the instrument, read/write permission to the USB device node (/dev/usb/<bus>/<addr>) is required. This is typically accomplished on Linux by adding a suitable rule in /etc/udev/rules.d. For example:

/etc/udev/rules.d/99-newport_usb.rules: SUBYSTEM==”usb”, ATTRS{idVendor}==”0bd3”, ATTRS{idProduct}==”e345”, GROUP=”dialout”, MODE=”0660”

Command language

The USB access provided by this module enables the use of the ASCII command set of the 843-R instrument as documented by Newport. See “PMManager-User-Commands.pdf” or “Newport User Commands.pdf”.

Command strings start with “$”, followed by a two-letter command, optionally followed by parameters, and ending with ” “.

In case of success, the instrument sends a response string starting with “*”, followed by a command-specific response format, and ending with ” “.

If an error occurs, the instrument sends a response string starting with “?”, followed by an error message and ending with ” “.

Streaming mode

In addition to the command/response flow, the instrument also supports a streaming mode in which it spontaneously sends several power readings per second via the USB interrupt endpoint 0x82. A sequence of undocumented commands is required to enable this streaming mode. The streaming mode is currently not supported by this Python module.

Protocol notes

The instrument has USB vendor ID 0x0BD3, vendor string “Freescale”, product ID 0xE345, product string “843-R”.

A serial number string is present in the USB descriptor.

The USB device class is 255 (vendor-specified), subclass 0. The device supports 1 USB configuration, containing 1 interface. The interface class is 255 (vendor-specified), subclass 255.

The interface contains 4 USB endpoints:
  • EP 0x81: interrupt IN, max 512 bytes (purpose unknown)

  • EP 0x82: interrupt IN, max 512 bytes (used in streaming mode)

  • EP 0x83: bulk IN, max 512 bytes (purpose unknown)

  • EP 0x04: bulk OUT, max 512 bytes (purpose unknown)

The request/response flow based on ASCII strings is implemented via control transfers on the default control endpoint (EP 0x00).

To send a command string to the instrument, the computer initiates the following control transfer:

bmRequestType = 0x40 (host-to-device, vendor-specified, device request) bRequest = 2 wValue = 0 wIndex = 0 data = command string (starting with “$”, ending with “rn”)

To read a response string from the instrument, the computer initiates the following control transfer:

bmRequestType = 0xc0 (device-to-host, vendor-specifid, device request) bRequest = 4 wValue = 0 wIndex = 0 wLength = 2000

The device then responds with an answer string (starting with “*” or “?” and ending with ” “).

Write command and read response transactions are sent in strict alternation. Each command triggers exactly 1 response from the device.

The device-side implementation of this protocol is quite fragile. Attempting to read a response when the instrument is not ready to send a response will easily crash the USB interface to the point where it can no longer respond to USB descriptor requests.

Classes

Newport_843R_libusb(serial_number)

Basic input/output access to the Newport 843-R power meter via USB.

class qmi.instruments.newport.newport_843r_libusb.Newport_843R_libusb(serial_number: str | None)

Basic input/output access to the Newport 843-R power meter via USB.

classmethod list_instruments() List[str]

Return serial numbers of attached Newport 843-R instruments.

Scan the USB bus for attached Newport 843-R instruments and return a list of their serial numbers.

close() None

Release USB device.

Raises:

USBError – If an error occurs at the USB level.

send_command(cmd: bytes, timeout: float = 1.0) None

Send a command to the instrument and return the response.

See the Newport documentation for a list of supported commands (PMManager-User-Commands.pdf).

Parameters:

cmd – Command string to send to the instrument. The command is typically an ASCII string, starting with “$” and ending with “rn”.

Returns:

Response from the instrument.

Raises:

USBError – If an error occurs on the USB level.

read_response(timeout: float = 1.0) bytes

Read a response string from the instrument.

Warning: The USB interface in the instrument is extremely fickle. Attempting to read a response when the instrument is not ready to send a response, may crash the USB interface and require power-cycling of the instrument to recover.

Parameters:

timeout – Maximum time to wait for the response (seconds).

Returns:

Response from the instrument. The response is typically an ASCII string ending with “n”.

Raises:

USBError – If the device does not respond or when an error occurs on the USB level.