jPicUsb
Class iface

java.lang.Object
  extended by jPicUsb.iface

public class iface
extends java.lang.Object

Interface with Microchip Usb API
Requires jpicusb.dll on the same folder of running program
Author: Geronimo OƱativia
Version: 1.0
Date: 30 de Enero de 2009


Field Summary
static int FUNCTION_CALL_FAIL
          Called function failed.
static int MAX_NUM_MPUSB_DEV
          Max number of attached devices.
static int MP_READ
          Direction of the endpoint.
static int MP_WRITE
          Direction of the endpoint.
static int MPUSB_FAIL
          Called function failed.
static int MPUSB_SUCCESS
          Called function succeeded.
 
Constructor Summary
iface()
          Dummy constructor.
 
Method Summary
static boolean Close(long handle)
          Opens an endpoint pipe with matching handle.
static java.lang.String GetAPIVersion()
          Get mpusbapi revision level
static int GetDeviceCount(java.lang.String pVID_PID)
          Returns the number of devices with matching VID & PID.
static void load()
          Loads the interface jpicusb.dll Call this function only once.
static long Open(int instance, java.lang.String pVID_PID, java.lang.String pEP, int dwDir, int dwReserved)
          Opens an endpoint pipe with matching VID & PID.
static byte[] QRead(int dwLen, long dwMilliseconds)
          Quick Read
Open a connection with DEFAULT VID & PID, reads data, and closes the opened endpoint pipe.
static long QWrite(byte[] pData, int dwLen, long dwMilliseconds)
          Quick Write
Open a connection with DEFAULT VID & PID, writes data, and closes the opened endpoint pipe.
static byte[] QWriteRead(byte[] pData, int dwLenWrite, int dwLenRead, long dwMilliseconds)
          Quick Write and Read
Open two connections with DEFAULT VID & PID, wtite data, then reads data, and closes the opened endpoint pipes.
static byte[] Read(long handle, int dwLen, long dwMilliseconds)
          Reads data from an opened endpoint pipe.
static byte[] Read(java.lang.String pVID_PID, int instance, int dwLen, long dwMilliseconds)
          Open a connection with matching VID & PID, reads data, and closes the opened endpoint pipe.
static void set_instance(int i)
          Sets DEFAULT instance used by functions wich don't receive a handle or VID & PID.
static void set_vidpid(java.lang.String s)
          Sets DEFAULT VID & PID used by functions wich don't receive a handle or VID & PID.
static long Write(long handle, byte[] pData, int dwLen, long dwMilliseconds)
          Writes data to an opened endpoint pipe.
static long Write(java.lang.String pVID_PID, int instance, byte[] pData, int dwLen, long dwMilliseconds)
          Open a connection with matching VID & PID, writes data, and closes the opened endpoint pipe.
static byte[] WriteRead(java.lang.String pVID_PID, int instance, byte[] pData, int dwLenWrite, int dwLenRead, long dwMilliseconds)
          Open two connections with matching VID & PID, wtite data, then reads data, and closes the opened endpoint pipes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FUNCTION_CALL_FAIL

public static int FUNCTION_CALL_FAIL
Called function failed. Useful on functions that can return zero.


MPUSB_FAIL

public static int MPUSB_FAIL
Called function failed. If function can return zero, use FUNCTION_CALL_FAIL instead.


MPUSB_SUCCESS

public static int MPUSB_SUCCESS
Called function succeeded.


MP_WRITE

public static int MP_WRITE
Direction of the endpoint. Use this to Write.


MP_READ

public static int MP_READ
Direction of the endpoint. Use this to Read.


MAX_NUM_MPUSB_DEV

public static int MAX_NUM_MPUSB_DEV
Max number of attached devices.

Constructor Detail

iface

public iface()
Dummy constructor. All methods of this class are static. Its not necessary to create an instance of this class to use its methods.

Method Detail

GetAPIVersion

public static java.lang.String GetAPIVersion()
Get mpusbapi revision level

Returns:
String representing the version

GetDeviceCount

public static int GetDeviceCount(java.lang.String pVID_PID)
Returns the number of devices with matching VID & PID.

Parameters:
pVID_PID - A string containing the VID & PID value of the target device. The format is "vid_xxxx&pid_yyyy".
Returns:
Number of USB device with matching VID & PID.

Open

public static long Open(int instance,
                        java.lang.String pVID_PID,
                        java.lang.String pEP,
                        int dwDir,
                        int dwReserved)
Opens an endpoint pipe with matching VID & PID.

Parameters:
instance - An instance number of the device to open.
pVID_PID - A string containing the VID & PID value of the target device. The format is "vid_xxxx&pid_yyyy".
pEP - A string of the endpoint number on the target endpoint to open. The format is "\\MCHP_EPz". Where z is the endpoint number in decimal.
dwDir - Specifies the direction of the endpoint. Use MP_READ for Read. Use MP_WRITE for Write.
dwReserved - Future Use.
Returns:
Returns a long value representing the handle to the endpoint pipe with matching VID & PID.

Close

public static boolean Close(long handle)
Opens an endpoint pipe with matching handle.

Parameters:
handle - long value representing the handle to an endpoint pipe opened with Open.
Returns:
True on sucess, False on fail.

Write

public static long Write(long handle,
                         byte[] pData,
                         int dwLen,
                         long dwMilliseconds)
Writes data to an opened endpoint pipe.

Parameters:
handle - Long value representing the handle to an endpoint pipe opened with Open.
pData - Byte array containing the data to be sent.
dwLen - Amount of bytes to be sent.
dwMilliseconds - Timeout in milliseconds.
Returns:
Return the number of bytes written by this function call.

Write

public static long Write(java.lang.String pVID_PID,
                         int instance,
                         byte[] pData,
                         int dwLen,
                         long dwMilliseconds)
Open a connection with matching VID & PID, writes data, and closes the opened endpoint pipe.

Parameters:
pVID_PID - A string containing the VID & PID value of the target device. The format is "vid_xxxx&pid_yyyy".
instance - An instance number of the device to open.
pData - Byte array containing the data to be sent.
dwLen - Amount of bytes to be sent.
dwMilliseconds - Timeout in milliseconds.
Returns:
Return the number of bytes written by this function call.

Read

public static byte[] Read(long handle,
                          int dwLen,
                          long dwMilliseconds)
Reads data from an opened endpoint pipe.

Parameters:
handle - Long value representing the handle to an endpoint pipe opened with Open.
dwLen - Amount of bytes to be read.
dwMilliseconds - Timeout in milliseconds.
Returns:
Byte array containing the read data.

Read

public static byte[] Read(java.lang.String pVID_PID,
                          int instance,
                          int dwLen,
                          long dwMilliseconds)
Open a connection with matching VID & PID, reads data, and closes the opened endpoint pipe.

Parameters:
pVID_PID - A string containing the VID & PID value of the target device. The format is "vid_xxxx&pid_yyyy".
instance - An instance number of the device to open.
dwLen - Amount of bytes to be read.
dwMilliseconds - Timeout in milliseconds.
Returns:
Byte array containing the read data.

WriteRead

public static byte[] WriteRead(java.lang.String pVID_PID,
                               int instance,
                               byte[] pData,
                               int dwLenWrite,
                               int dwLenRead,
                               long dwMilliseconds)
Open two connections with matching VID & PID, wtite data, then reads data, and closes the opened endpoint pipes.

Parameters:
pVID_PID - A string containing the VID & PID value of the target device. The format is "vid_xxxx&pid_yyyy".
instance - An instance number of the device to open.
pData - Byte array containing the data to be sent.
dwLenWrite - Amount of bytes to be sent.
dwLenRead - Amount of bytes to be read.
dwMilliseconds - Timeout in milliseconds.
Returns:
Byte array containing the read data.

QWrite

public static long QWrite(byte[] pData,
                          int dwLen,
                          long dwMilliseconds)
Quick Write
Open a connection with DEFAULT VID & PID, writes data, and closes the opened endpoint pipe.

Parameters:
pData - Byte array containing the data to be sent.
dwLen - Amount of bytes to be sent.
dwMilliseconds - Timeout in milliseconds.
Returns:
Return the number of bytes written by this function call.

QRead

public static byte[] QRead(int dwLen,
                           long dwMilliseconds)
Quick Read
Open a connection with DEFAULT VID & PID, reads data, and closes the opened endpoint pipe.

Parameters:
dwLen - Amount of bytes to be read.
dwMilliseconds - Timeout in milliseconds.
Returns:
Byte array containing the read data.

QWriteRead

public static byte[] QWriteRead(byte[] pData,
                                int dwLenWrite,
                                int dwLenRead,
                                long dwMilliseconds)
Quick Write and Read
Open two connections with DEFAULT VID & PID, wtite data, then reads data, and closes the opened endpoint pipes.

Parameters:
pData - Byte array containing the data to be sent.
dwLenWrite - Amount of bytes to be sent.
dwLenRead - Amount of bytes to be read.
dwMilliseconds - Timeout in milliseconds.
Returns:
Byte array containing the read data.

set_vidpid

public static void set_vidpid(java.lang.String s)
Sets DEFAULT VID & PID used by functions wich don't receive a handle or VID & PID.

Parameters:
s - A string containing the VID & PID value of the target device. The format is "vid_xxxx&pid_yyyy".

set_instance

public static void set_instance(int i)
Sets DEFAULT instance used by functions wich don't receive a handle or VID & PID.

Parameters:
i - An instance number of the device.

load

public static void load()
Loads the interface jpicusb.dll Call this function only once.