Skip to main content

usb.openendpoint(speed, deviceAddress, interface, endpointType, maxPacketSize, endpointAddress, interval)

Opens the endpoint for reading or writing via USB

Availability

Device
imp005 and impC001 only

Parameters

Name Type Description
speed Float The speed in Mb/s. Must be either 1.5 or 12
deviceAddress Integer The address of the device
interface Integer The endpoint’s interface number
endpointType Integer The type of the endpoint
maxPacketSize Integer The maximum size of packet that can be written or read on this endpoint
endpointAddress Integer The address of the endpoint
interval Integer Interval for polling endpoint for data transfers. Valid range: 1—255

Returns

Nothing

Description

This method opens the specified endpoint for reading or writing via USB. It will throw an exception if it can’t open the specified endpoint (otherwise it simply returns null).

If the device goes away or usb.disable() is called, all endpoints are closed and must be re-opened when the device returns.

The value of the endpointType parameter is provided in the endpoint descriptor generated when the device connects, an event which triggers a call to the callback function registered with usb.configure(). It will one of the following values:

Value Type
0x00 Control endpoint
0x01 Isochronous endpoint not supported
0x02 Bulk endpoint
0x03 Interrupt In endpoint

The maximum size of packet that can be written or read on this endpoint is also provided in the endpoint descriptor returned to the callback function registered with usb.configure() when the peripheral device first connects.

The endpoint value is an 8-bit integer formed from the following bit fields:

Bits Description
D0-3 The endpoint number
D4-6 Reserved
D7 The direction of transfer: 0 is out, 1 is in
  • For more information on determining the source of USB errors and implementing recovery methods, please see Understanding USB Errors.

To make use of an Interrupt In endpoint, the method requires an extra, seventh parameter: interval. This takes an integer value representing the polling period:

Interval Actual Polling Period (ms)
1 1
2-3 2
4-7 4
8-15 8
16-31 16
32-255 32

If a value outside of the range 1-255 is passed into interval, or is not an integer, Squirrel will throw the following error: "invalid interval in usb.openendpoint()".

One and only one Interrupt In endpoint may be opened. If you attempt to open another Interrupt In endpoint, Squirrel will throw the following error: "endpoint already open in usb.openendpoint()".