usbHostEnumerate (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

NX-200, NX-400

Firmware version:

1.00.00


The function is used to retrieve information about devices connected to the USB host port.

Only devices connected to an enabled port can be discovered. See usbHostEnable for details.

 

 

Input:

port : SINT (0..1, default 0)

The USB host port to enumerate. (0=All ports, 1=usb1, etc.)

 

index : INT (1..32767)

The index of the USB device to query.

 

 

Output:

device : STRING

This is the system device name, which can be used to identify the connected device.

 

type : INT

The type of device:

7

Camera.

4

Ethernet module

3

Mass storage device

2

Serial port.

1

USB hub.

-1

Unknown device.

 

Returns: INT

1

- Success.

0

- The function is not supported.

-1

- The device is not found or the USB host port is not present.(See usbHostEnable)

 

Declaration:

FUNCTION usbHostEnumerate : INT;
VAR_INPUT
  port : SINT;
  index : INT;
  device : ACCESS STRING;
  type   : ACCESS INT;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR_INPUT
  doScan   : BOOL R_EDGE; | Scan for connected USB devices
END_VAR;
 
PROGRAM example;
VAR
  device   : STRING;
  type     : INT;
  index    : INT;
  rc       : INT;
END_VAR;
// Enable USB host port
usbHostEnable(port:=1,enable:=TRUE);
 
BEGIN
  IF doScan THEN
    DebugMsg(message := "-- USB devices --");
    FOR index := 1 TO 32 DO
        // Get information about USB device
        rc := usbHostEnumerate(index := index, device := device, type := type);
        IF rc = 1 THEN
          DebugFmt(message := "\1 : Type = \2, Device = '" + device + "'", v1 := index, v2 := type);
        ELSE
          EXIT;
        END_IF;
    END_FOR;
  END_IF;
END;
END_PROGRAM;