com.moxa.mxuportapi
Class MxUPortService

java.lang.Object
  extended by com.moxa.mxuportapi.MxUPortService

public class MxUPortService
extends java.lang.Object

The MxUPortService class offers service routines for MxUPorts in your system. These routines should be used before accessing MxUPort. For example, the program should use getPortInfoList to get the list of MxUPort in your system before using any MxUPort object.


Nested Class Summary
static class MxUPortService.DeviceID
          This class represents the supported UPort for MxUPort API.
 
Constructor Summary
MxUPortService()
           
 
Method Summary
static int getDeviceInfoListCount(android.hardware.usb.UsbManager usbManager)
          Returns the number of available UPort devices in the system.
static java.util.List<MxUPort> getPortInfoList(android.hardware.usb.UsbManager usbManager)
          Builds and returns a new List<MxUPort> from the attached UPort , or returns null if a UPort is not available in system.
static int requestPermission(android.content.Context context, android.hardware.usb.UsbManager usbManager, java.lang.String actionName, int vid, int pid, android.content.BroadcastReceiver usbReceiver)
          Requests USB permission to access; should get user's permission to access the USB device.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MxUPortService

public MxUPortService()
Method Detail

getDeviceInfoListCount

public static int getDeviceInfoListCount(android.hardware.usb.UsbManager usbManager)
Returns the number of available UPort devices in the system.

Parameters:
usbManager - The UsbManager object returned from getSystemService().
Returns:
The number of devices, or 0 if none are found.

getPortInfoList

public static java.util.List<MxUPort> getPortInfoList(android.hardware.usb.UsbManager usbManager)
Builds and returns a new List<MxUPort> from the attached UPort , or returns null if a UPort is not available in system. The ports are sorted in the sequence they are discovered.

Example:

 // Get a MxUPort list from current system
   
   UsbManager mUsbManager = (UsbManager)getSystemService(Context.USB_SERVICE);
   
   List<MxUPort> mPortList = MxUPortService.getPortInfoList(mUsbManager);
   
   if( mPortList!=null ){
       // Process more tasks 			
   }
 
 

Parameters:
usbManager - The UsbManager object returned from getSystemService().
Returns:
A new List<MxUPort>, or null if no UPort is found.

requestPermission

public static int requestPermission(android.content.Context context,
                                    android.hardware.usb.UsbManager usbManager,
                                    java.lang.String actionName,
                                    int vid,
                                    int pid,
                                    android.content.BroadcastReceiver usbReceiver)
Requests USB permission to access; should get user's permission to access the USB device. This method offers a quick (although not the only way) to request permission. (Read more)

Call this method to request the 1st parent USB device of MxUPort and return the remaining USB devices that need to get permission.

Parameters:
context - The Context from the application. It is usually 'this'.
usbManager - The UsbManager object returned from getSystemService().
actionName - The unique name for specifying the permission request. It is usually $(APP_NAME).USB_PERMISSION.
vid - Vendor ID. Give both vid and pid to narrow the MxUPorts inquiry. Give both vid and pid with zero for all Moxa devices.
pid - Product ID. Give both vid and pid to narrow the MxUPorts inquiry. Give both vid and pid with zero for all Moxa devices.
usbReceiver - A BroadcastReceiver object to receive the permission result.
Returns:
The number of devices that need to be granted permission, or -1 if failed.