usbHostGetInfo (Functionblock)

Top  Previous  Next

Architecture:

NX32L

Device support:

NX-200, NX-400

Firmware version:

2.00.00


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

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

Composite devices will report the same information for all the contained interfaces.

 

 

Input:

device : STRING

The system device name of the device, retrieved using the usbHostEnumerate function.

 

Output:

status : INT

The type of device:

1

Success

0

Not supported

-1

Device not found

 

VID: UINT

Vendor ID of the device.

 

PID: UINT

Product ID of the device.

 

manufacturer: STRING

The manufacturer name. An empty string if it is not set in the device

 

product: STRING

The product name. An empty string if it is not set in the device

 

version: STRING

The version number of the device. An empty string if it is not set in the device

 

serial: STRING

The serial number of the device. An empty string if it is not set in the device

 

 

Declaration:

FUNCTION_BLOCK usbHostGetInfo;
VAR_INPUT
  device : STRING;
END_VAR;
VAR_OUTPUT
  status  : INT;
  VID     : UINT;
  PID     : UINT;
  manufacturer : STRING;
  product : STRING;
  version : STRING;
  serial  : STRING;
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;
  usbInfo  : usbHostGetInfo;
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);
          usbInfo(device:=device);
          IF usbInfo.status > 0 THEN
              DebugFmt(message := "   ID : " + intToHex(v:=usbInfo.VID) + ":" + intToHex(v:=usbInfo.PID));
              DebugMsg(message := "   Man: " + usbInfo.manufacturer);
              DebugMsg(message := "   Prd: " + usbInfo.product);
              DebugMsg(message := "   Ver: " + usbInfo.version);
              DebugMsg(message := "   Ser: " + usbInfo.serial);
          END_IF;
        ELSE
          EXIT;
        END_IF;
    END_FOR;
  END_IF;
END;
END_PROGRAM;