In [13]:
from IPython.display import Image, HTML

Device description:

Get whatever linux know about the device:

$ lsusb -v
Bus 001 Device 005: ID 1a45:2001 Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 255 Vendor Specific Class bDeviceSubClass 255 Vendor Specific Subclass bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x1a45 idProduct 0x2001 bcdDevice 0.70 iManufacturer 1 Wavelength Electronics, Inc. iProduct 2 FL593 Dual-Channel Laser Driver iSerial 3 00B1401004-0006 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 32 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xc0 Self Powered MaxPower 0mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 255 Vendor Specific Class bInterfaceSubClass 255 Vendor Specific Subclass bInterfaceProtocol 255 Vendor Specific Protocol iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x01 EP 1 OUT bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0014 1x 20 bytes bInterval 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x82 EP 2 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0015 1x 21 bytes bInterval 1 Device Status: 0x0000 (Bus Powered)

Uhm... what?

Figuring out what that is supposed to tell me via http://www.beyondlogic.org/usbnutshell/usb5.shtml


In [4]:
Image(filename='desctree.png')


Out[4]:
All descriptors have the same format: 0: bLength: Size of descriptor in bytes 1: bDescriptorType (0x01: Device, 0x02: Configuration, 0x03: String, 0x04: Interface, 0x05: Endpoint) b... 1B integer bcd... 2B bytecode i... 1B index id... 2B integer bm... 1B bitmap w... 2B word

Diving in, starting with the top-level

Device descriptor

Device Descriptor: bLength 18 -> 18 bytes long descriptor bDescriptorType 1 -> Device descriptor bcdUSB 2.00 -> supports up to USB 2.0 bDeviceClass 255 Vendor Specific Class -> specified by vendor if 0xFF bDeviceSubClass 255 Vendor Specific Subclass -> specified by vendor if 0xFF bDeviceProtocol 0 bMaxPacketSize0 64 -> max. packet length for endpoint 0 idVendor 0x1a45 idProduct 0x2001 -> 0x2000 Laser diode driver evaluation boards. bcdDevice 0.70 -> device version iManufacturer 1 Wavelength Electronics, Inc. iProduct 2 FL593 Dual-Channel Laser Driver iSerial 3 00B1401004-0006 bNumConfigurations 1 -> only a single configuration

FL593 protocol details: http://www.teamwavelength.com/permanent/usb/docs/api/weiprot.html

"0x2000 Laser diode driver evaluation boards. Evaluation boards are typically for components or modules, and include supporting external circuitry and connectors required to quickly connect and begin operating the product."

Configuration descriptor

Configuration Descriptor: bLength 9 -> 18 bytes long descriptor bDescriptorType 2 -> Configuration descriptor wTotalLength 32 -> Total length in bytes of data returned. bNumInterfaces 1 -> Number of Interfaces bConfigurationValue 1 -> !!Value to use as an argument to select this configuration iConfiguration 0 -> Index of of human readable string descriptor bmAttributes 0xc0 -> D6 Self Powered Self Powered MaxPower 0mA -> in 2mA units (max. ~ 500mA)

Interface descriptor

Interface Descriptor: bLength 9 -> 9 bytes long interface descriptor bDescriptorType 4 -> Interface Descriptor (0x04) bInterfaceNumber 0 -> first interface (0 based indexed) bAlternateSetting 0 -> Value used to select alternative setting bNumEndpoints 2 -> 2 endpoints used for this interface bInterfaceClass 255 Vendor Specific Class -> bInterfaceSubClass 255 Vendor Specific Subclass -> bInterfaceProtocol 255 Vendor Specific Protocol -> iInterface 0 -> Index of of human readable string descriptor

Endpoint descriptors

Devices that implement Wavelength's USB Protocol must support three endpoints. The control endpoint, endpoint 0, must always be supported by all devices. In addition to the control endpoint, endpoint 1 must be configured in the device to support interrupt OUT transfers, and endpoint 2 must be configured to support interrupt IN transfers. The control endpoint is used only by the device driver and Windows during enumeration of the device. Once the device has enumerated, the device driver performs all device IO operations using the interrupt endpoints. For each command packet submitted to the device driver, the device driver transmits an interrupt OUT transfer to the device. Every time a user mode application requests the corresponding response packet, the device driver initiates an interrupt IN transfer, reading data from the device, and populates the buffer specified in the application's read call to the driver with the data received from the device.

from: http://www.teamwavelength.com/permanent/usb/docs/api/driver.html

Endpoint 1 descriptor (OUTPUT TO DEVICE)

Endpoint Descriptor: bLength 7 -> 7 byte endpoint descriptor bDescriptorType 5 -> Endpoint descriptor (0x05) bEndpointAddress 0x01 EP 1 OUT -> see below bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0014 1x 20 bytes -> Maximum Packet Size endpoint can send (or receive) bInterval 1 -> Interval for polling endpoint data transfers. Value in frame counts. Ignored for Bulk and Control Endpoints. Isochronous must equal 1 and field may range from 1 to 255 for interrupt endpoints.

Endpoint Address:


Bits 0..3b Endpoint Number.

Bits 4..6b Reserved. Set to Zero

Bits 7 Direction 0 = Out, 1 = In (Ignored for Control Endpoints)

Attributes bitmap:


Bits 0..1 Transfer Type

00 = Control
01 = Isochronous
10 = Bulk
11 = Interrupt

Bits 2..7 are reserved. If Isochronous endpoint, Bits 3..2 = Synchronisation Type (Iso Mode)

00 = No Synchonisation
01 = Asynchronous
10 = Adaptive
11 = Synchronous

Bits 5..4 = Usage Type (Iso Mode)

00 = Data Endpoint
01 = Feedback Endpoint
10 = Explicit Feedback Data Endpoint
11 = Reserved

Endpoint 2 descriptor (INPUT TO HOST)

Endpoint Descriptor: bLength 7 -> 7 byte endpoint descriptor bDescriptorType 5 -> Endpoint descriptor (0x05) bEndpointAddress 0x82 EP 2 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0015 1x 21 bytes bInterval 1

Command and response packet structure

from: http://www.teamwavelength.com/permanent/usb/docs/api/driver.html

DevType field

The DevType field indicates the type of device being accessed. This field is used by combinational devices, such as those that include a temperature controller and laser driver in the same package with a single USB interface. The DevType field can be set to a value indicating which element of the product an operation is targetting, allowing for the command code value set for each element of the product to overlap each other, and therefore match more closely the command set implemented by other Wavelength products. For products that only contain a single type of product, this field is generally ignored.

Channel field

The Channel field allows a specific channel to be targetting in a multichannel product. For example, the FL593FL dual channel laser driver has two separate channels which can be independently controlled. By specifying a channel number in this field, software can gain control over the operation of each channel. A value of 0 indicates that the target of an operation is the device itself, rather than a channel within the device.

OpType field

The OpType field indicates the type of operation requested. The possible values are 1 (TYPE_READ), 2 (TYPE_WRITE), 3 (TYPE_MIN) and 4 (TYPE_MAX). The TYPE_READ OpType value indicates that the host application wishes to read the current value for the parameter specified by the OpCode field, for example, to read what the setpoint currently is for the device. The TYPE_WRITE OpType value indicates that the host application wishes to set a new value for the parameter specified in the OpCode field. The TYPE_MIN and TYPE_MAX OpType values can be used by the host application to determine what the minimum and maximum acceptable values are for the parameter indicated in the OpCode field.

OpCode field

The OpCode field indicates the parameter of interest for the requested operation. Each requested operation, such as accessing the setpoint, limits, monitor feedbacks, operation mode controls, status flags, etc will have a specific OpCode value assigned to it. The Wavelength USB Device Protocol defines the OpCode range of 0x00 to 0x0F (inclusive) as command codes that must be supported by all devices that use the WEIUSB.SYS device driver to allow for identification of devices. OpCode values greater than or equal to 0x10 define codes specific to a particular product or type of product. For more information on these OpCode values, please refer to the datasheet for the specific product of interest.

Data field

The Data field allows the host application to transmit up to 16 bytes of information to the device. The contents of the Data field depends on the operation requested. For example, when setting the the setpoint for a device, the data field will contain the new setpoint value in units defined by the product implementation. For OpType values of TYPE_READ, TYPE_MIN and TYPE_MAX, the contents of the Data field in the command packet are ignored.

from: http://www.teamwavelength.com/permanent/usb/docs/api/weiprot.html

Command packet:

The command packet represents information sent by software running on the host computer to the device to instruct it to perform some action. This packet is transfered as binary data. The following table illustrates the internal structure of a command packet as it is transmitted on the bus:

Field: DevType Channel OpType OpCode Data
Offset: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

The following table describes each field in more detail:

Field Byte Offset Length Description
DevType 0 2 Indicates the type of device being addressed. This field is primarily used in combination units, such as one that may have a temperature controller and a laser driver integrated into the same package. Using the DevType field allows the application to target a specific command to a particular element of a product.
Channel 2 2 For multichannel devices, this indicates the channel number being operated on. For example, a command to change the setpoint on a specific channel could be issued.
OpType 4 2 Indicates the type of operation the device should perform. Some commands, such as the setpoint or limit command, can be either written to or read back by the host application. The OpCode value is the same, indicating that the application is operating on a specific quantity known to the device, and the OpType will indicate what action is being requested in regard to the OpCode specified. See more below for a listing of possible values.
OpCode 6 2 Indicates the quantity or function of interest. Each quantity within the product, such as setpoint, limit, monitors, etc, are assigned a numeric OpCode value. There are a minimal set of OpCodes that must be supported by all devices that utilize Wavelength's protocol, and there is a set of values reserved for use with calibration of the unit. Other values are free to be used as command codes corresponding to a particular device or device class.
Data 8 16 Contains data applicable to the context of the OpCode issued. Numeric and string data types are represented as strings in this field. For example, if querying for the current monitor on a laser diode driver, this value would contain the measured laser diode current in units of amps, represented as a floating point number converted to a string.

The OpType field can have one of the four following values:

Mnemonic Value Description
TypeRead 1 Indicates that the quantity specified in OpCode is to be read back by the host.
TypeWrite 2 Indicates the value of the quantity specified in OpCode is to be written to by the host.
TypeMin 3 Indicates that the minimum range value for the quantity specified in OpCode is to be returned to the host.
TypeMax 4 Indicates that the maximum range value for the quantity specified in OpCode is to be returned to the host.

The TypeMin and TypeMax OpType values are used for detecting the capabilities of a device that is not necessarily known to software. These OpTypes instruct the device to return back to the host application the acceptable values for a quantity specified in OpCode, allowing an existing application to work with similar products as they are released in the future.

Response Packet

The response packet represents information read from a device to the host by the driver. Its internal structure is nearly identical to that of the command packet, with the exception of the addition of a 2-byte EndCode field. The following table outlines this internal structure:

Field: DevType Channel OpType OpCode EndCode Data
Offset: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

The following table describes each field in more detail:

Field Byte Offset Length Description
DevType 0 2 Indicates the type of device being addressed. This field is primarily used in combination units, such as one that may have a temperature controller and a laser driver integrated into the same package. Using the DevType field allows the application to target a specific command to a particular element of a product.
Channel 2 2 For multichannel devices, this indicates the channel number being operated on. For example, a command to change the setpoint on a specific channel could be issued.
OpType 4 2 Indicates the type of operation the device should perform. Some commands, such as the setpoint or limit command, can be either written to or read back by the host application. The OpCode value is the same, indicating that the application is operating on a specific quantity known to the device, and the OpType will indicate what action is being requested in regard to the OpCode specified. See more below for a listing of possible values.
OpCode 6 2 Indicates the quantity or function of interest. Each quantity within the product, such as setpoint, limit, monitors, etc, are assigned a numeric OpCode value. There are a minimal set of OpCodes that must be supported by all devices that utilize Wavelength's protocol, and there is a set of values reserved for use with calibration of the unit. Other values are free to be used as command codes corresponding to a particular device or device class.
EndCode 8 2 The end code represents the device's response as to it's status in carrying out the operation requested in the previous command packet. This code will indicate whether the request was completed successfully, or will indicate the nature of the failure to do so. See the end code listing table below for a more detailed list of the generic end code values.
Data 8 16 Contains data applicable to the context of the OpCode issued. Numeric and string data types are represented as strings in this field. For example, if querying for the current monitor on a laser diode driver, this value would contain the measured laser diode current in units of amps, represented as a floating point number converted to a string.

The following table outlines the generic end codes that can possibly be returned from any device supporting the Wavelength USB Device Protocol:

Mnemonic Value Description
ERR_OK 0 No error code. The requested operation was completed successfully.
ERR_DEVTYPE 1 The device type specified in the DevType field of the command packet does not correspond with the device type for the device.
ERR_CHANNEL 2 The channel number specified is out of range for the device.
ERR_OPTYPE 3 The OpType field of the command packet contains an invalid value or a value not supported by the specified OpCode.
ERR_NOTIMPL 4 The specified OpCode is not implemented in this device.
ERR_PENDING 5 This code acts as an acknowledgement that for the host that the command packet was received, however the device has not yet completed the operation. The contents of the data field should be ignored.
ERR_BUSY 6 The device is currently busy servicing a previous request and has not performed the requested operation.
ERR_DATA 7 The contents of the data field are invalid for the specified OpCode.
ERR_SAFETY 8 The requested operation would exceed safety specifications for the current configuration or the device. The requested operation was not performed.
ERR_CALMODE 9 The requested operation is only available when in calibration mode, and the device is currently in user mode. A PASSWD command must be specified with the correct password in the data field to gain access to the requested function.

When a response packet is returned to the host, most of the fields will contain the values specified in the respective response packet. This allows the host application to determine exactly which operation was completed. This is useful in applications where there is a delay between sending the command packet and retrieving the response packet. For command packets where OpType is set to TypeWrite, the data field of the response packet will contain the current value of the specified quantity after applying the value specified by the command. For OpType of TypeRead, the value of the data field is the current value known to the device for the specified quantity.

OpCode Values

As mentioned previously, there is a basic set of OpCodes that must be supported by all devices utilizing this protocol. These OpCodes are used to determine the product ID of the device, serial number, model number, and other information identifying the device. The following table outlines these OpCodes:

Mnemonic Value OpTypes Description
MODEL 0x00 TypeRead Queries the devices for its model number string. This value is hard coded into the firmware of the device.
SERIAL 0x01 TypeRead
TypeWrite1
Queries the device for or sets the devices serial number string.
FWVER 0x02 TypeRead Queries the device for its firmware version. This value is hard coded into the firmware of the device.
DEVTYPE 0x03 TypeRead Queries the device for its device type code. This is the same value as its USB product ID. This value is hard coded into the firmware of the device.
CHANCT 0x04 TypeRead Queries the device for the number of channels the device supports.
IDENTIFY 0x05 TypeRead
TypeWrite
This OpCode provides a means of physical identification of a device. The intention behind this OpCode is that an application can send a command packet with this OpCode, and the OpType of TypeWrite, and if the data field numerically evaluates to a nonzero value, the device will perform some visual or audible action that allows a specific device to be physically identified by the user. Issuing the same command with a data field that evaluates to zero causes it to stop identifying itself. Reading this value in will indicate whether the device is currently identifying itself or not.
SAVE2 0x0C TypeWrite Causes the current configuration to be saved to nonvolatile memory on board the target device. This includes setpoint configurations, limit configurations, gain configurations (as applicable), output enabled states, startup behavior, etc. When the device is powered up, this information will automatically be reloaded from nonvolatile memory and, depending on the startup behavior, can be configured to automatically resume operation even if not attached to a host computer. See the data sheet for specific products to see more details on the startup behavior for each product, and how to implement such behavior.
RECALL 0x0D TypeWrite Causes the device to reload its default configuration from nonvolatile memory. For devices that do not have nonvolatile memory, this causes the device to reload factory defaults.
PASSWD 0x0E TypeRead
TypeWrite
Allows an application to change from operating mode to calibration mode. The data field for this OpCode must contain the password provided by the user to enter calibration mode. The device will verify that the password is correct, indicating the result of this comparison in the end code of the response packet. If the end code is ERR_OK, then the password was valid and the device is now in calibration mode. If the end code is ERR_CALMODE, the password is not valid and the device remains in user mode. Use the TypeWrite OpType value for sending the password. Use the TypeRead to retrieve the current mode the device is operating in. If the end code field contains ERR_OK then the device is in user mode. If the end code contains ERR_CALMODE then the device is in calibration mode.
REVERT 0x0F TypeWrite Causes the device to revert to user mode from calibration mode. To re-enter calibration mode, the PASSWD OpCode must be issued to the device again.

Notes:

-TypeWrite OpType value is only valid when the device is in calibration mode. -Devices that do not contain nonvolatile memory must still acknowledge the SAVE request successfully, as the SAVE command falls within the range of codes (0x00-0x0F) that must be supported by all devices.

Data Field Formatting

The data field for any given command or response packet is a 16-byte buffer that can be applied as needed by any function provided by a particular device. The data field should be used to transfer data by means that are platform independent to avoid the need to manage byte-ordering within the data field. There are four primary types of data that can be transferred in the data field: string, numeric, boolean and bitmapped.

String data allows for the transfer of data that contains characters that cannot be interpreted or represented as numeric data. This includes the characters A-Z, a-z, punctuation marks and whitespace. String data is used to represent the model number, serial number and possibly the firmware version. All data in a string data field are left-aligned, and unused bytes in the data field must be padded with NULL characters (ASCII 0).

Numeric data is any data that can be evaluated as or converted to numeric form. This includes all real numbers. Any measured quantities, such as current monitors, temperature monitors and power monitors all will return unitless values in the data field, however this value will be scaled to units of the quantity measured. For example, if a laser driver's current monitor is set to 100mA, the data field when requesting the current monitor value will be represented in units of amperes. Similarly, photodiode current will be represented in amps for laser drivers. Temperature controllers will have the option of representing temperatures in either volts or degrees Celsius, since converting the measured feedback in volts to degrees Celsius cannot be done without additional information about the temperature sensor that the user may not possess or may not be readily available.

Boolean data represents a single boolean term. The data field will use left-aligned data within the data field, and only the left-most character will contain data. The remaining characters may contain additional information, however it will be ignored. See the data sheet for specific USB based products to see which commands utilize boolean data. With a boolean term, a value of zero indicates a logical false, and a nonzero value indicates true.

The final data format is the bitmapped format. The bitmapped type is similar to boolean, except that it utilizes all 16 of the data field characters instead of just the first (position 0). Just as with the boolean type, each character within the bitmap field is represented either as a '0' (ASCII 48) or any other numerical character, including '1' (ASCII 49) through '9' (ASCII 57). This is useful for commands such as the ALARM command, where multiple boolean values such as output state, enabled state, interlock state and limit flags are transferred at one time. A value of '0' in any given character indicates a logical false, and any other numeric value from '1' to '9' (inclusive) are considered to be a logical true. Any other character is considered illegal, and command packets containing any other characters will return a response packet with an end code of ERR_DATA. This allows up to 16 boolean quantities to be transferred in a bitmapped data transfer.


In [ ]: