OpenCores
URL https://opencores.org/ocsvn/usb_fpga_1_15/usb_fpga_1_15/trunk

Subversion Repositories usb_fpga_1_15

[/] [usb_fpga_1_15/] [trunk/] [java/] [ztex/] [Ztex1.java] - Diff between revs 3 and 4

Only display areas with differences | Details | Blame | View Log

Rev 3 Rev 4
/*!
/*!
   Java host software API of ZTEX EZ-USB FX2 SDK
   Java host software API of ZTEX SDK
   Copyright (C) 2009-2011 ZTEX GmbH.
   Copyright (C) 2009-2014 ZTEX GmbH.
   http://www.ztex.de
   http://www.ztex.de
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3 as
   it under the terms of the GNU General Public License version 3 as
   published by the Free Software Foundation.
   published by the Free Software Foundation.
 
 
   This program is distributed in the hope that it will be useful, but
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   General Public License for more details.
   General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, see http://www.gnu.org/licenses/.
   along with this program; if not, see http://www.gnu.org/licenses/.
!*/
!*/
 
 
/*
/*
    Functions for USB devices with ZTEX descriptor 1
    Functions for USB devices with ZTEX descriptor 1
*/
*/
package ztex;
package ztex;
 
 
import java.io.*;
import java.io.*;
import java.util.*;
import java.util.*;
 
 
import ch.ntb.usb.*;
import ch.ntb.usb.*;
 
 
/**
/**
  * This class implements the interface-independent part of the communication protocol for the interaction with the ZTEX firmware.<p>
  * This class implements the interface-independent part of the communication protocol for the interaction with the ZTEX firmware.<p>
  * All firmware implementations that provide the ZTEX descriptor 1 are supported.
  * All firmware implementations that provide the ZTEX descriptor 1 are supported.
  * A description of this descriptor can be found in {@link ZtexDevice1}.
  * A description of this descriptor can be found in {@link ZtexDevice1}.
  * <p>
  * <p>
  * The most important features of this class are the functions for uploading the firmware
  * The most important features of this class are the functions for uploading the firmware
  * and the renumeration management.
  * and the renumeration management.
  * <p>
  * <p>
  * The interface dependent part of the communication protocol (currently only one is supported)
  * The interface dependent part of the communication protocol (currently only one is supported)
  * can be found in {@link Ztex1v1}.
  * can be found in {@link Ztex1v1}.
  * @see ZtexDevice1
  * @see ZtexDevice1
  * @see Ztex1v1
  * @see Ztex1v1
  */
  */
public class Ztex1 {
public class Ztex1 {
    private final int maxDevNum = 1023;
    private final int maxDevNum = 1023;
    private long handle;
    private long handle;
    private ZtexDevice1 dev = null;
    private ZtexDevice1 dev = null;
    private boolean oldDevices[] = new boolean[maxDevNum+1];
    private boolean oldDevices[] = new boolean[maxDevNum+1];
    private int oldDevNum = -1;
    private int oldDevNum = -1;
    private String usbBusName = null;
    private String usbBusName = null;
    private boolean[] interfaceClaimed = new boolean[256];
    private boolean[] interfaceClaimed = new boolean[256];
    private boolean configurationSet = false;
    private boolean configurationSet = false;
/** * Setting to true enables certain workarounds, e.g. to deal with bad driver/OS implementations. */
/** * Setting to true enables certain workarounds, e.g. to deal with bad driver/OS implementations. */
    public boolean certainWorkarounds = false;
    public boolean certainWorkarounds = false;
/** * The timeout for  control messages in ms. */
/** * The timeout for  control messages in ms. */
    public int controlMsgTimeout = 1000;        // in ms
    public int controlMsgTimeout = 1000;        // in ms
    private long lastVendorCommandT = 0;
    private long lastVendorCommandT = 0;
 
 
 
 
// ******* Ztex1 ***************************************************************
// ******* Ztex1 ***************************************************************
/**
/**
  * Constructs an instance from a given device.
  * Constructs an instance from a given device.
  * @param pDev The given device.
  * @param pDev The given device.
  * @throws UsbException if an communication error occurred.
  * @throws UsbException if an communication error occurred.
  */
  */
    public Ztex1 ( ZtexDevice1 pDev ) throws UsbException {
    public Ztex1 ( ZtexDevice1 pDev ) throws UsbException {
        dev = pDev;
        dev = pDev;
        init();
        init();
    }
    }
 
 
// ******* init ****************************************************************
// ******* init ****************************************************************
/**
/**
  * Initializates the class.
  * Initializates the class.
  * @throws UsbException if an communication error occurred.
  * @throws UsbException if an communication error occurred.
  */
  */
    protected void init () throws UsbException {
    protected void init () throws UsbException {
        for (int i=0; i<256; i++)
        for (int i=0; i<256; i++)
            interfaceClaimed[i] = false;
            interfaceClaimed[i] = false;
 
 
        handle = LibusbJava.usb_open(dev.dev());
        handle = LibusbJava.usb_open(dev.dev());
//      if ( handle<=0 ) 
//      if ( handle<=0 ) 
//          throw new UsbException(dev.dev(), "Error opening device");
//          throw new UsbException(dev.dev(), "Error opening device");
    }
    }
 
 
// ******* finalize ************************************************************
// ******* finalize ************************************************************
/** * The destructor closes the USB file handle. */
/** * The destructor closes the USB file handle. */
    protected void finalize () {
    protected void finalize () {
        for (int i=0; i<256; i++)
        for (int i=0; i<256; i++)
            if ( interfaceClaimed[i] )
            if ( interfaceClaimed[i] )
                LibusbJava.usb_release_interface(handle, i);
                LibusbJava.usb_release_interface(handle, i);
 
 
        LibusbJava.usb_close(handle);
        LibusbJava.usb_close(handle);
    }
    }
 
 
// ******* handle **************************************************************
// ******* handle **************************************************************
/** * Returns the USB file handle. */
/** * Returns the USB file handle. */
    public final long handle()
    public final long handle()
    {
    {
        return handle;
        return handle;
    }
    }
 
 
// ******* dev *****************************************************************
// ******* dev *****************************************************************
/**
/**
  * Returns the corresponding {@link ZtexDevice1}.
  * Returns the corresponding {@link ZtexDevice1}.
  * @return the corresponding {@link ZtexDevice1}.
  * @return the corresponding {@link ZtexDevice1}.
  */
  */
    public final ZtexDevice1 dev()
    public final ZtexDevice1 dev()
    {
    {
        return dev;
        return dev;
    }
    }
 
 
// ******* valid ***************************************************************
// ******* valid ***************************************************************
/**
/**
  * Returns true if ZTEX descriptor 1 is available.
  * Returns true if ZTEX descriptor 1 is available.
  * @return true if ZTEX descriptor 1 is available.
  * @return true if ZTEX descriptor 1 is available.
  */
  */
    public boolean valid ( ) {
    public boolean valid ( ) {
        return dev.valid();
        return dev.valid();
    }
    }
 
 
// ******* checkValid **********************************************************
// ******* checkValid **********************************************************
/**
/**
  * Checks whether ZTEX descriptor 1 is available.
  * Checks whether ZTEX descriptor 1 is available.
  * @throws InvalidFirmwareException if ZTEX descriptor 1 is not available.
  * @throws InvalidFirmwareException if ZTEX descriptor 1 is not available.
  */
  */
    public void checkValid () throws InvalidFirmwareException {
    public void checkValid () throws InvalidFirmwareException {
        if ( ! dev.valid() )
        if ( ! dev.valid() )
            throw new InvalidFirmwareException(this, "Can't read ZTEX descriptor 1");
            throw new InvalidFirmwareException(this, "Can't read ZTEX descriptor 1");
    }
    }
 
 
// ******* vendorCommand *******************************************************
// ******* vendorCommand *******************************************************
/**
/**
  * Sends a vendor command to Endpoint 0 of the EZ-USB device.
  * Sends a vendor command to Endpoint 0 of the EZ-USB device.
  * The command may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * The command may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * @param cmd The command number (0..255).
  * @param cmd The command number (0..255).
  * @param func The name of the command. This string is used for the generation of error messages.
  * @param func The name of the command. This string is used for the generation of error messages.
  * @param value The value (0..65535), i.e bytes 2 and 3 of the setup data.
  * @param value The value (0..65535), i.e bytes 2 and 3 of the setup data.
  * @param index The index (0..65535), i.e. bytes 4 and 5 of the setup data.
  * @param index The index (0..65535), i.e. bytes 4 and 5 of the setup data.
  * @param length The size of the payload data (0..65535), i.e. bytes 6 and 7 of the setup data.
  * @param length The size of the payload data (0..65535), i.e. bytes 6 and 7 of the setup data.
  * @param buf The payload data buffer.
  * @param buf The payload data buffer.
  * @return the number of bytes sent.
  * @return the number of bytes sent.
  * @throws UsbException if a communication error occurs.
  * @throws UsbException if a communication error occurs.
  */
  */
    public synchronized int vendorCommand (int cmd, String func, int value, int index, byte[] buf, int length) throws UsbException {
    public synchronized int vendorCommand (int cmd, String func, int value, int index, byte[] buf, int length) throws UsbException {
        long t0 = new Date().getTime()-100;
        long t0 = new Date().getTime()-100;
        int trynum = 0;
        int trynum = 0;
        int i = -1;
        int i = -1;
        if ( controlMsgTimeout < 200 )
        if ( controlMsgTimeout < 200 )
            controlMsgTimeout = 200;
            controlMsgTimeout = 200;
//      while ( i<=0 && new Date().getTime()-t0<controlMsgTimeout ) {           // we repeat the message until the timeout has reached
//      while ( i<=0 && new Date().getTime()-t0<controlMsgTimeout ) {           // we repeat the message until the timeout has reached
            i = LibusbJava.usb_control_msg(handle, 0x40, cmd, value, index, buf, length, controlMsgTimeout);
            i = LibusbJava.usb_control_msg(handle, 0x40, cmd, value, index, buf, length, controlMsgTimeout);
            if ( certainWorkarounds ) {
            if ( certainWorkarounds ) {
                try {
                try {
                    Thread.sleep(2);
                    Thread.sleep(2);
                }
                }
                    catch ( InterruptedException e ) {
                    catch ( InterruptedException e ) {
                }
                }
            }
            }
            lastVendorCommandT = new Date().getTime();
            lastVendorCommandT = new Date().getTime();
            if ( i < 0 ) {
            if ( i < 0 ) {
                System.err.println("Warning (try " + (trynum+1) + "): " + LibusbJava.usb_strerror() );
                System.err.println("Warning (try " + (trynum+1) + "): " + LibusbJava.usb_strerror() );
                try {
                try {
                    Thread.sleep( 1 << trynum );                                // we don't want to bother the USB device to often
                    Thread.sleep( 1 << trynum );                                // we don't want to bother the USB device to often
                }
                }
                    catch ( InterruptedException e ) {
                    catch ( InterruptedException e ) {
                }
                }
                trynum++;
                trynum++;
            }
            }
//      } 
//      } 
        if ( i < 0 )
        if ( i < 0 )
            throw new UsbException( dev.dev(), (func != null ? func + ": " : "" )+ LibusbJava.usb_strerror());
            throw new UsbException( dev.dev(), (func != null ? func + ": " : "" )+ LibusbJava.usb_strerror());
        return i;
        return i;
    }
    }
 
 
/**
/**
  * Sends a vendor command with no payload data to Endpoint 0 of the EZ-USB device.
  * Sends a vendor command with no payload data to Endpoint 0 of the EZ-USB device.
  * The command may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * The command may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * @param cmd The command number (0..255).
  * @param cmd The command number (0..255).
  * @param func The name of the command. This string is used for the generation of error messages.
  * @param func The name of the command. This string is used for the generation of error messages.
  * @param value The value (0..65535), i.e bytes 2 and 3 of the setup data.
  * @param value The value (0..65535), i.e bytes 2 and 3 of the setup data.
  * @param index The index (0..65535), i.e. bytes 4 and 5 of the setup data.
  * @param index The index (0..65535), i.e. bytes 4 and 5 of the setup data.
  * @return the number of bytes sent.
  * @return the number of bytes sent.
  * @throws UsbException if a communication error occurs.
  * @throws UsbException if a communication error occurs.
  */
  */
    public int vendorCommand (int cmd, String func, int value, int index) throws UsbException {
    public int vendorCommand (int cmd, String func, int value, int index) throws UsbException {
        byte[] buf = { 0 };
        byte[] buf = { 0 };
        return vendorCommand (cmd, func, value, index, buf, 0);
        return vendorCommand (cmd, func, value, index, buf, 0);
    }
    }
 
 
/**
/**
  * Sends a vendor command with no payload data and no setup data to Endpoint 0 of the EZ-USB device.
  * Sends a vendor command with no payload data and no setup data to Endpoint 0 of the EZ-USB device.
  * The command may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * The command may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * @param cmd The command number (0..255).
  * @param cmd The command number (0..255).
  * @param func The name of the command. This string is used for the generation of error messages.
  * @param func The name of the command. This string is used for the generation of error messages.
  * @return the number of bytes sent.
  * @return the number of bytes sent.
  * @throws UsbException if a communication error occurs.
  * @throws UsbException if a communication error occurs.
  */
  */
    public int vendorCommand (int cmd, String func) throws UsbException {
    public int vendorCommand (int cmd, String func) throws UsbException {
        byte[] buf = { 0 };
        byte[] buf = { 0 };
        return vendorCommand (cmd, func, 0, 0, buf, 0);
        return vendorCommand (cmd, func, 0, 0, buf, 0);
    }
    }
 
 
// ******* vendorRequest *******************************************************
// ******* vendorRequest *******************************************************
/**
/**
  * Sends a vendor request to Endpoint 0 of the EZ-USB device.
  * Sends a vendor request to Endpoint 0 of the EZ-USB device.
  * The request may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * The request may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * @param cmd The request number (0..255).
  * @param cmd The request number (0..255).
  * @param func The name of the request. This string is used for the generation of error messages.
  * @param func The name of the request. This string is used for the generation of error messages.
  * @param value The value (0..65535), i.e bytes 2 and 3 of the setup data.
  * @param value The value (0..65535), i.e bytes 2 and 3 of the setup data.
  * @param index The index (0..65535), i.e. bytes 4 and 5 of the setup data.
  * @param index The index (0..65535), i.e. bytes 4 and 5 of the setup data.
  * @param maxlen The size of the requested payload data (0..65535), i.e. bytes 6 and 7 of the setup data.
  * @param maxlen The size of the requested payload data (0..65535), i.e. bytes 6 and 7 of the setup data.
  * @param buf The payload data buffer.
  * @param buf The payload data buffer.
  * @return the number of bytes received.
  * @return the number of bytes received.
  * @throws UsbException if a communication error occurs.
  * @throws UsbException if a communication error occurs.
  */
  */
    public synchronized int vendorRequest (int cmd, String func, int value, int index, byte[] buf, int maxlen) throws UsbException {
    public synchronized int vendorRequest (int cmd, String func, int value, int index, byte[] buf, int maxlen) throws UsbException {
        long t0 = new Date().getTime()-100;
        long t0 = new Date().getTime()-100;
        int trynum = 0;
        int trynum = 0;
        int i = -1;
        int i = -1;
        if ( controlMsgTimeout < 200 )
        if ( controlMsgTimeout < 200 )
            controlMsgTimeout = 200;
            controlMsgTimeout = 200;
        while ( i<=0 && new Date().getTime()-t0<controlMsgTimeout ) {            // we repeat the message until the timeout has reached
        while ( i<=0 && new Date().getTime()-t0<controlMsgTimeout ) {            // we repeat the message until the timeout has reached
            /*
            /*
                The HSNAK mechanism of EP0 usually avoids that a request is sent before a command has been completed.
                The HSNAK mechanism of EP0 usually avoids that a request is sent before a command has been completed.
                Unfortunately this mechanism is only 99.99% reliable. Therefore we wait at least 1ms after the last
                Unfortunately this mechanism is only 99.99% reliable. Therefore we wait at least 1ms after the last
                command has been send before we transmit a new request.
                command has been send before we transmit a new request.
            */
            */
            long ms = new Date().getTime() - lastVendorCommandT;
            long ms = new Date().getTime() - lastVendorCommandT;
            if ( ms < 2 ) {     //
            if ( ms < 2 ) {     //
                try {
                try {
                    Thread.sleep(1);
                    Thread.sleep(1);
                }
                }
                    catch ( InterruptedException e ) {
                    catch ( InterruptedException e ) {
                }
                }
            }
            }
 
 
            i = LibusbJava.usb_control_msg(handle, 0xc0, cmd, value, index, buf, maxlen, controlMsgTimeout);
            i = LibusbJava.usb_control_msg(handle, 0xc0, cmd, value, index, buf, maxlen, controlMsgTimeout);
            if ( certainWorkarounds ) {
            if ( certainWorkarounds ) {
                try {
                try {
                    Thread.sleep(2);
                    Thread.sleep(2);
                }
                }
                    catch ( InterruptedException e ) {
                    catch ( InterruptedException e ) {
                }
                }
            }
            }
            if ( i < 0 ) {
            if ( i < 0 ) {
                System.err.println("Warning (try " + (trynum+1) + "): " + LibusbJava.usb_strerror() );
                System.err.println("Warning (try " + (trynum+1) + "): " + LibusbJava.usb_strerror() );
                try {
                try {
                    Thread.sleep( 1 << trynum );                                // we don't want to bother the USB device to often
                    Thread.sleep( 1 << trynum );                                // we don't want to bother the USB device to often
                }
                }
                    catch ( InterruptedException e ) {
                    catch ( InterruptedException e ) {
                }
                }
                trynum++;
                trynum++;
            }
            }
        }
        }
        if ( i < 0 )
        if ( i < 0 )
            throw new UsbException( dev.dev(), (func != null ? func + ": " : "" ) + LibusbJava.usb_strerror());
            throw new UsbException( dev.dev(), (func != null ? func + ": " : "" ) + LibusbJava.usb_strerror());
        return i;
        return i;
    }
    }
 
 
/**
/**
  * Sends a vendor request to Endpoint 0 of the EZ-USB device.
  * Sends a vendor request to Endpoint 0 of the EZ-USB device.
  * The request may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * The request may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * @param cmd The request number (0..255).
  * @param cmd The request number (0..255).
  * @param func The name of the request. This string is used for the generation of error messages.
  * @param func The name of the request. This string is used for the generation of error messages.
  * @param maxlen The size of the requested payload data (0..65535), i.e. bytes 6 and 7 of the setup data.
  * @param maxlen The size of the requested payload data (0..65535), i.e. bytes 6 and 7 of the setup data.
  * @param buf The payload data buffer.
  * @param buf The payload data buffer.
  * @return the number of bytes sent.
  * @return the number of bytes sent.
  * @throws UsbException if a communication error occurs.
  * @throws UsbException if a communication error occurs.
  */
  */
    public int vendorRequest (int cmd, String func, byte[] buf, int maxlen) throws UsbException {
    public int vendorRequest (int cmd, String func, byte[] buf, int maxlen) throws UsbException {
        return vendorRequest (cmd, func, 0, 0, buf, maxlen);
        return vendorRequest (cmd, func, 0, 0, buf, maxlen);
    }
    }
 
 
// ******* vendorCommand2 ******************************************************
// ******* vendorCommand2 ******************************************************
/**
/**
  * Sends a vendor command to Endpoint 0 of the EZ-USB device and throws an {@link UsbException} if not all of the payload has been sent.
  * Sends a vendor command to Endpoint 0 of the EZ-USB device and throws an {@link UsbException} if not all of the payload has been sent.
  * The command may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * The command may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * @param cmd The command number (0..255).
  * @param cmd The command number (0..255).
  * @param func The name of the command. This string is used for the generation of error messages.
  * @param func The name of the command. This string is used for the generation of error messages.
  * @param value The value (0..65535), i.e bytes 2 and 3 of the setup data.
  * @param value The value (0..65535), i.e bytes 2 and 3 of the setup data.
  * @param index The index (0..65535), i.e. bytes 4 and 5 of the setup data.
  * @param index The index (0..65535), i.e. bytes 4 and 5 of the setup data.
  * @param length The size of the payload data (0..65535), i.e. bytes 6 and 7 of the setup data.
  * @param length The size of the payload data (0..65535), i.e. bytes 6 and 7 of the setup data.
  * @param buf The payload data buffer.
  * @param buf The payload data buffer.
  * @throws UsbException if a communication error occurs or if not all of the payload has been sent.
  * @throws UsbException if a communication error occurs or if not all of the payload has been sent.
  */
  */
    public synchronized void vendorCommand2 (int cmd, String func, int value, int index, byte[] buf, int length) throws UsbException {
    public synchronized void vendorCommand2 (int cmd, String func, int value, int index, byte[] buf, int length) throws UsbException {
        int i = vendorCommand (cmd, func, value, index, buf, length);
        int i = vendorCommand (cmd, func, value, index, buf, length);
        if ( i != length )
        if ( i != length )
            throw new UsbException( dev.dev(), (func != null ? func + ": " : "" ) + "Send " + i + " byte of data instead of " + length + " bytes");
            throw new UsbException( dev.dev(), (func != null ? func + ": " : "" ) + "Send " + i + " byte of data instead of " + length + " bytes");
    }
    }
 
 
// ******* vendorRequest2 ******************************************************
// ******* vendorRequest2 ******************************************************
/**
/**
  * Sends a vendor request to Endpoint 0 of the EZ-USB device and throws an {@link UsbException} if not all of the payload has been received.
  * Sends a vendor request to Endpoint 0 of the EZ-USB device and throws an {@link UsbException} if not all of the payload has been received.
  * The request may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * The request may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * @param cmd The request number (0..255).
  * @param cmd The request number (0..255).
  * @param func The name of the request. This string is used for the generation of error messages.
  * @param func The name of the request. This string is used for the generation of error messages.
  * @param value The value (0..65535), i.e bytes 2 and 3 of the setup data.
  * @param value The value (0..65535), i.e bytes 2 and 3 of the setup data.
  * @param index The index (0..65535), i.e. bytes 4 and 5 of the setup data.
  * @param index The index (0..65535), i.e. bytes 4 and 5 of the setup data.
  * @param maxlen The size of the requested payload data (0..65535), i.e. bytes 6 and 7 of the setup data.
  * @param maxlen The size of the requested payload data (0..65535), i.e. bytes 6 and 7 of the setup data.
  * @param buf The payload data buffer.
  * @param buf The payload data buffer.
  * @throws UsbException if a communication error occurs or not all of the payload has been received.
  * @throws UsbException if a communication error occurs or not all of the payload has been received.
  */
  */
    public void vendorRequest2 (int cmd, String func, int value, int index, byte[] buf, int maxlen) throws UsbException {
    public void vendorRequest2 (int cmd, String func, int value, int index, byte[] buf, int maxlen) throws UsbException {
        int i = vendorRequest(cmd, func, value, index, buf, maxlen);
        int i = vendorRequest(cmd, func, value, index, buf, maxlen);
        if ( i != maxlen )
        if ( i != maxlen )
            throw new UsbException( dev.dev(), (func != null ? func + ": " : "" ) + "Received " + i + " byte of data, expected "+maxlen+" bytes");
            throw new UsbException( dev.dev(), (func != null ? func + ": " : "" ) + "Received " + i + " byte of data, expected "+maxlen+" bytes");
    }
    }
 
 
/**
/**
  * Sends a vendor request to Endpoint 0 of the EZ-USB device and throws an {@link UsbException} if not all of the payload has been received.
  * Sends a vendor request to Endpoint 0 of the EZ-USB device and throws an {@link UsbException} if not all of the payload has been received.
  * The request may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * The request may be send multiple times until the {@link #controlMsgTimeout} is reached.
  * @param cmd The request number (0..255).
  * @param cmd The request number (0..255).
  * @param func The name of the request. This string is used for the generation of error messages.
  * @param func The name of the request. This string is used for the generation of error messages.
  * @param maxlen The size of the requested payload data (0..65535), i.e. bytes 6 and 7 of the setup data.
  * @param maxlen The size of the requested payload data (0..65535), i.e. bytes 6 and 7 of the setup data.
  * @param buf The payload data buffer.
  * @param buf The payload data buffer.
  * @throws UsbException if a communication error occurs or not all of the payload has been received.
  * @throws UsbException if a communication error occurs or not all of the payload has been received.
  */
  */
    public void vendorRequest2 (int cmd, String func, byte[] buf, int maxlen) throws UsbException {
    public void vendorRequest2 (int cmd, String func, byte[] buf, int maxlen) throws UsbException {
        vendorRequest2(cmd, func, 0, 0, buf, maxlen);
        vendorRequest2(cmd, func, 0, 0, buf, maxlen);
    }
    }
 
 
 
 
 
 
// ******* setConfiguration ****************************************************
// ******* setConfiguration ****************************************************
/**
/**
  * Sets the configuration.
  * Sets the configuration.
  * @param config The configuration number (usually 1)
  * @param config The configuration number (usually 1)
  * @throws UsbException if an error occurs while attempting to set the configuration.
  * @throws UsbException if an error occurs while attempting to set the configuration.
  */
  */
    public void setConfiguration ( int config) throws UsbException{
    public void setConfiguration ( int config) throws UsbException{
        if ( LibusbJava.usb_set_configuration(handle(), config) < 0 )
        if ( LibusbJava.usb_set_configuration(handle(), config) < 0 )
            throw new UsbException("Setting configuration to " + config + " failed: " + LibusbJava.usb_strerror());
            throw new UsbException("Setting configuration to " + config + " failed: " + LibusbJava.usb_strerror());
        configurationSet = true;
        configurationSet = true;
    }
    }
 
 
 
 
// ******* trySetConfiguration ****************************************************
// ******* trySetConfiguration ****************************************************
/**
/**
  * Tries to set the configuration.
  * Tries to set the configuration.
  * If an error occurs while attempting to set the configuration, a warning messaage is printed to stderr.
  * If an error occurs while attempting to set the configuration, a warning messaage is printed to stderr.
  * @param config The configuration number (usually 1)
  * @param config The configuration number (usually 1)
  */
  */
    public void trySetConfiguration ( int config) {
    public void trySetConfiguration ( int config) {
        if ( LibusbJava.usb_set_configuration(handle(), config) < 0 )
        if ( LibusbJava.usb_set_configuration(handle(), config) < 0 )
            System.err.println("Setting configuration to " + config + " failed: " + LibusbJava.usb_strerror());
            System.err.println("Setting configuration to " + config + " failed: " + LibusbJava.usb_strerror());
        configurationSet = true;
        configurationSet = true;
    }
    }
 
 
 
 
// ******* getInterfaceClaimed *************************************************
// ******* getInterfaceClaimed *************************************************
/**
/**
  * Returns true if interface is claimed.
  * Returns true if interface is claimed.
  * @return true if interface is claimed
  * @return true if interface is claimed
  * @param iface The interface number
  * @param iface The interface number
  */
  */
    public boolean getInterfaceClaimed ( int iface ) {
    public boolean getInterfaceClaimed ( int iface ) {
        return iface>=0 && iface<256 && interfaceClaimed[iface];
        return iface>=0 && iface<256 && interfaceClaimed[iface];
    }
    }
 
 
 
 
// ******* claimInterface ******************************************************
// ******* claimInterface ******************************************************
/**
/**
  * Claims an interface.
  * Claims an interface.
  * @param iface The interface number (usually 0)
  * @param iface The interface number (usually 0)
  * @throws UsbException if an error occurs while attempting to claim the interface.
  * @throws UsbException if an error occurs while attempting to claim the interface.
  */
  */
    public void claimInterface ( int iface) throws UsbException{
    public void claimInterface ( int iface) throws UsbException{
        if ( ! configurationSet )
        if ( ! configurationSet )
            trySetConfiguration(1);
            trySetConfiguration(1);
        if ( ( iface<0 || iface>=256 || (! interfaceClaimed[iface]) ) && ( LibusbJava.usb_claim_interface(handle(), iface) < 0 ) )
        if ( ( iface<0 || iface>=256 || (! interfaceClaimed[iface]) ) && ( LibusbJava.usb_claim_interface(handle(), iface) < 0 ) )
            throw new UsbException("Claiming interface " + iface + " failed: " + LibusbJava.usb_strerror());
            throw new UsbException("Claiming interface " + iface + " failed: " + LibusbJava.usb_strerror());
        if ( iface>=0 && iface < 256 )
        if ( iface>=0 && iface < 256 )
            interfaceClaimed[iface]=true;
            interfaceClaimed[iface]=true;
    }
    }
 
 
 
 
// ******* releaseInterface ****************************************************
// ******* releaseInterface ****************************************************
/**
/**
  * Releases an interface.
  * Releases an interface.
  * @param iface The interface number (usually 0)
  * @param iface The interface number (usually 0)
  */
  */
    public void releaseInterface ( int iface ) {
    public void releaseInterface ( int iface ) {
        if ( iface<0 || iface>=256 || interfaceClaimed[iface] )
        if ( iface<0 || iface>=256 || interfaceClaimed[iface] )
            LibusbJava.usb_release_interface(handle(), iface);
            LibusbJava.usb_release_interface(handle(), iface);
        if ( iface>=0 && iface < 256 )
        if ( iface>=0 && iface < 256 )
            interfaceClaimed[iface]=false;
            interfaceClaimed[iface]=false;
 
 
    }
    }
 
 
 
 
// ******* findOldDevices ******************************************************
// ******* findOldDevices ******************************************************
    private synchronized void findOldDevices () throws DeviceLostException {
    private synchronized void findOldDevices () throws DeviceLostException {
        usbBusName = dev.dev().getBus().getDirname();
        usbBusName = dev.dev().getBus().getDirname();
 
 
        Usb_Bus bus = LibusbJava.usb_get_busses();
        Usb_Bus bus = LibusbJava.usb_get_busses();
        while ( bus != null && ! bus.getDirname().equals(usbBusName) )
        while ( bus != null && ! bus.getDirname().equals(usbBusName) )
            bus = bus.getNext();
            bus = bus.getNext();
        if ( bus == null )
        if ( bus == null )
                throw new DeviceLostException( "findOldDevice: Bus dissapeared" );
                throw new DeviceLostException( "findOldDevice: Bus dissapeared" );
 
 
        for ( int i=0; i<=maxDevNum; i++ )
        for ( int i=0; i<=maxDevNum; i++ )
            oldDevices[i] = false;
            oldDevices[i] = false;
 
 
        Usb_Device d = bus.getDevices();
        Usb_Device d = bus.getDevices();
        while ( d != null ) {
        while ( d != null ) {
            byte b = d.getDevnum();
            byte b = d.getDevnum();
            if ( b > maxDevNum )
            if ( b > maxDevNum )
                throw new DeviceLostException( "Device number too large: " + b + " > " + maxDevNum );
                throw new DeviceLostException( "Device number too large: " + b + " > " + maxDevNum );
            if ( b > 0 )
            if ( b > 0 )
                oldDevices[b] = true;
                oldDevices[b] = true;
            d = d.getNext();
            d = d.getNext();
        }
        }
        oldDevNum = dev.dev().getDevnum();
        oldDevNum = dev.dev().getDevnum();
    }
    }
 
 
// ******* findNewDevice *******************************************************
// ******* findNewDevice *******************************************************
    private synchronized Usb_Device findNewDevice ( String errMsg ) throws DeviceLostException {
    private synchronized Usb_Device findNewDevice ( String errMsg ) throws DeviceLostException {
        Usb_Device newDev = null;
        Usb_Device newDev = null;
        LibusbJava.usb_find_busses();
        LibusbJava.usb_find_busses();
        LibusbJava.usb_find_devices();
        LibusbJava.usb_find_devices();
 
 
        Usb_Bus bus = LibusbJava.usb_get_busses();
        Usb_Bus bus = LibusbJava.usb_get_busses();
        while ( bus != null && ! bus.getDirname().equals(usbBusName) )
        while ( bus != null && ! bus.getDirname().equals(usbBusName) )
            bus = bus.getNext();
            bus = bus.getNext();
        if ( bus == null )
        if ( bus == null )
                throw new DeviceLostException( "findNewDevice: Bus dissapeared" );
                throw new DeviceLostException( "findNewDevice: Bus dissapeared" );
 
 
        Usb_Device d = bus != null ? bus.getDevices() : null;
        Usb_Device d = bus != null ? bus.getDevices() : null;
        while ( d != null ) {
        while ( d != null ) {
            byte b = d.getDevnum();
            byte b = d.getDevnum();
            if ( b > maxDevNum )
            if ( b > maxDevNum )
                throw new DeviceLostException( "Device number too large: " + b + " > " + maxDevNum );
                throw new DeviceLostException( "Device number too large: " + b + " > " + maxDevNum );
            if ( b > 0 && ! oldDevices[b] ) {
            if ( b > 0 && ! oldDevices[b] ) {
                if ( newDev != null )
                if ( newDev != null )
                    throw new DeviceLostException( errMsg + "More than 2 new devices found: " + newDev.getDevnum() + "(`" + newDev.getFilename() + "') and " + b + "(`" + d.getFilename() + "')");
                    throw new DeviceLostException( errMsg + "More than 2 new devices found: " + newDev.getDevnum() + "(`" + newDev.getFilename() + "') and " + b + "(`" + d.getFilename() + "')");
                newDev = d;
                newDev = d;
            }
            }
            d = d.getNext();
            d = d.getNext();
        }
        }
 
 
        return newDev;
        return newDev;
    }
    }
 
 
// ******* initNewDevice *******************************************************
// ******* initNewDevice *******************************************************
    private void initNewDevice ( String errBase, boolean scanUnconfigured ) throws DeviceLostException, UsbException, InvalidFirmwareException {
    private void initNewDevice ( String errBase, boolean scanUnconfigured ) throws DeviceLostException, UsbException, InvalidFirmwareException {
// scan the bus for up to 60 s for a new device. Boot sequence may take a while.
// scan the bus for up to 60 s for a new device. Boot sequence may take a while.
        Usb_Device newDev = null;
        Usb_Device newDev = null;
        int i;
        int i;
        for ( i=0; i<300 && newDev==null; i++ ) {
        for ( i=0; i<300 && newDev==null; i++ ) {
            try {
            try {
                Thread.sleep( 200 );
                Thread.sleep( 200 );
            }
            }
                catch ( InterruptedException e ) {
                catch ( InterruptedException e ) {
            }
            }
            if ( i > 10 && oldDevNum >= 0 && oldDevNum < maxDevNum )
            if ( i > 10 && oldDevNum >= 0 && oldDevNum < maxDevNum )
                oldDevices[oldDevNum ] = false;
                oldDevices[oldDevNum ] = false;
            newDev = findNewDevice( errBase + ": " );
            newDev = findNewDevice( errBase + ": " );
        }
        }
        oldDevNum = -1;
        oldDevNum = -1;
        if ( newDev == null )
        if ( newDev == null )
            throw new DeviceLostException( errBase + ": No new device found" );
            throw new DeviceLostException( errBase + ": No new device found" );
 
 
// init new device
// init new device
        Usb_Device_Descriptor dd = newDev.getDescriptor();
        Usb_Device_Descriptor dd = newDev.getDescriptor();
        int vid = dd.getIdVendor() & 65535;
        int vid = dd.getIdVendor() & 65535;
        int pid = dd.getIdProduct() & 65535;
        int pid = dd.getIdProduct() & 65535;
        try {
        try {
            dev = new ZtexDevice1( newDev, vid, pid, scanUnconfigured );
            dev = new ZtexDevice1( newDev, vid, pid, scanUnconfigured );
        }
        }
        catch ( DeviceNotSupportedException e ) {
        catch ( DeviceNotSupportedException e ) {
            throw new InvalidFirmwareException( e.getLocalizedMessage() );
            throw new InvalidFirmwareException( e.getLocalizedMessage() );
        }
        }
 
 
        init();
        init();
    }
    }
 
 
// ******* uploadFirmware ******************************************************
// ******* uploadFirmware ******************************************************
/**
/**
  * Uploads the firmware to the EZ-USB and manages the renumeration process.
  * Uploads the firmware to the EZ-USB and manages the renumeration process.
  * <p>
  * <p>
  * Before the firmware is uploaded the device is set into a reset state.
  * Before the firmware is uploaded the device is set into a reset state.
  * After the upload the firmware is booted and the renumeration starts.
  * After the upload the firmware is booted and the renumeration starts.
  * During this process the device disappears from the bus and a new one
  * During this process the device disappears from the bus and a new one
  * occurs which will be assigned to this class automatically (instead of the disappeared one).
  * occurs which will be assigned to this class automatically (instead of the disappeared one).
  * @param ihxFile The firmware image.
  * @param ihxFile The firmware image.
  * @param force The compatibility check is skipped if true.
  * @param force The compatibility check is skipped if true.
  * @throws IncompatibleFirmwareException if the given firmware is not compatible to the installed one, see {@link ZtexDevice1#compatible(int,int,int,int)} (Upload can be enforced using the <tt>force</tt> parameter)
  * @throws IncompatibleFirmwareException if the given firmware is not compatible to the installed one, see {@link ZtexDevice1#compatible(int,int,int,int)} (Upload can be enforced using the <tt>force</tt> parameter)
  * @throws FirmwareUploadException If an error occurred while attempting to upload the firmware.
  * @throws FirmwareUploadException If an error occurred while attempting to upload the firmware.
  * @throws UsbException if a communication error occurs.
  * @throws UsbException if a communication error occurs.
  * @throws InvalidFirmwareException if ZTEX descriptor 1 is not available.
  * @throws InvalidFirmwareException if ZTEX descriptor 1 is not available.
  * @throws DeviceLostException if a device went lost after renumeration.
  * @throws DeviceLostException if a device went lost after renumeration.
  * @return the upload time in ms.
  * @return the upload time in ms.
  */
  */
//  returns upload time in ms
//  returns upload time in ms
    public long uploadFirmware ( ZtexIhxFile1 ihxFile, boolean force ) throws IncompatibleFirmwareException, FirmwareUploadException, UsbException, InvalidFirmwareException, DeviceLostException {
    public long uploadFirmware ( ZtexIhxFile1 ihxFile, boolean force ) throws IncompatibleFirmwareException, FirmwareUploadException, UsbException, InvalidFirmwareException, DeviceLostException {
// load the ihx file
// load the ihx file
//      ihxFile.dataInfo(System.out);
//      ihxFile.dataInfo(System.out);
//      System.out.println(ihxFile);
//      System.out.println(ihxFile);
 
 
// check for compatibility
// check for compatibility
        if ( ! force && dev.valid() ) {
        if ( ! force && dev.valid() ) {
            if ( ihxFile.interfaceVersion() != 1 )
            if ( ihxFile.interfaceVersion() != 1 )
                throw new IncompatibleFirmwareException("Wrong interface version: Expected 1, got " + ihxFile.interfaceVersion() );
                throw new IncompatibleFirmwareException("Wrong interface version: Expected 1, got " + ihxFile.interfaceVersion() );
 
 
            if ( ! dev.compatible ( ihxFile.productId(0), ihxFile.productId(1), ihxFile.productId(2), ihxFile.productId(3) ) )
            if ( ! dev.compatible ( ihxFile.productId(0), ihxFile.productId(1), ihxFile.productId(2), ihxFile.productId(3) ) )
                throw new IncompatibleFirmwareException("Incompatible productId's: Current firmware: " + ZtexDevice1.byteArrayString(dev.productId())
                throw new IncompatibleFirmwareException("Incompatible productId's: Current firmware: " + ZtexDevice1.byteArrayString(dev.productId())
                    + "  Ihx File: " + ZtexDevice1.byteArrayString(ihxFile.productId()) );
                    + "  Ihx File: " + ZtexDevice1.byteArrayString(ihxFile.productId()) );
        }
        }
 
 
// scan the bus for comparison
// scan the bus for comparison
        findOldDevices();
        findOldDevices();
 
 
// upload the firmware
// upload the firmware
        long time = EzUsb.uploadFirmware( handle, ihxFile );
        long time = EzUsb.uploadFirmware( handle, ihxFile );
 
 
// find and init new device
// find and init new device
        initNewDevice("Device lost after uploading Firmware", false);
        initNewDevice("Device lost after uploading Firmware", false);
 
 
        return time;
        return time;
    }
    }
 
 
/**
/**
  * Uploads the firmware to the EZ-USB and manages the renumeration process.
  * Uploads the firmware to the EZ-USB and manages the renumeration process.
  * <p>
  * <p>
  * Before the firmware is uploaded the device is set into a reset state.
  * Before the firmware is uploaded the device is set into a reset state.
  * After the upload the firmware is booted and the renumeration starts.
  * After the upload the firmware is booted and the renumeration starts.
  * During this process the device disappears from the bus and a new one
  * During this process the device disappears from the bus and a new one
  * occurs which will be assigned to this class automatically (instead of the disappeared one).
  * occurs which will be assigned to this class automatically (instead of the disappeared one).
  * @param ihxFileName The file name of the firmware image in ihx format. The file can be a regular file or a system resource (e.g. a file from the current jar archive).
  * @param ihxFileName The file name of the firmware image in ihx format. The file can be a regular file or a system resource (e.g. a file from the current jar archive).
  * @param force The compatibility check is skipped if true.
  * @param force The compatibility check is skipped if true.
  * @throws IncompatibleFirmwareException if the given firmware is not compatible to the installed one, see {@link ZtexDevice1#compatible(int,int,int,int)} (Upload can be enforced using the <tt>force</tt> parameter)
  * @throws IncompatibleFirmwareException if the given firmware is not compatible to the installed one, see {@link ZtexDevice1#compatible(int,int,int,int)} (Upload can be enforced using the <tt>force</tt> parameter)
  * @throws FirmwareUploadException If an error occurred while attempting to upload the firmware.
  * @throws FirmwareUploadException If an error occurred while attempting to upload the firmware.
  * @throws UsbException if a communication error occurs.
  * @throws UsbException if a communication error occurs.
  * @throws InvalidFirmwareException if ZTEX descriptor 1 is not available.
  * @throws InvalidFirmwareException if ZTEX descriptor 1 is not available.
  * @throws DeviceLostException if a device went lost after renumeration.
  * @throws DeviceLostException if a device went lost after renumeration.
  * @return the upload time in ms.
  * @return the upload time in ms.
  */
  */
//  returns upload time in ms
//  returns upload time in ms
    public long uploadFirmware ( String ihxFileName, boolean force ) throws IncompatibleFirmwareException, FirmwareUploadException, UsbException, InvalidFirmwareException, DeviceLostException {
    public long uploadFirmware ( String ihxFileName, boolean force ) throws IncompatibleFirmwareException, FirmwareUploadException, UsbException, InvalidFirmwareException, DeviceLostException {
// load the ihx file
// load the ihx file
        ZtexIhxFile1 ihxFile;
        ZtexIhxFile1 ihxFile;
        try {
        try {
            ihxFile = new ZtexIhxFile1( ihxFileName );
            ihxFile = new ZtexIhxFile1( ihxFileName );
        }
        }
        catch ( IOException e ) {
        catch ( IOException e ) {
            throw new FirmwareUploadException( e.getLocalizedMessage() );
            throw new FirmwareUploadException( e.getLocalizedMessage() );
        }
        }
        catch ( IhxFileDamagedException e ) {
        catch ( IhxFileDamagedException e ) {
            throw new FirmwareUploadException( e.getLocalizedMessage() );
            throw new FirmwareUploadException( e.getLocalizedMessage() );
        }
        }
        return uploadFirmware( ihxFile, force );
        return uploadFirmware( ihxFile, force );
    }
    }
 
 
/**
/**
  * Uploads the firmware to the EZ-USB and manages the renumeration process.
  * Uploads the firmware to the EZ-USB and manages the renumeration process.
  * <p>
  * <p>
  * Before the firmware is uploaded the device is set into a reset state.
  * Before the firmware is uploaded the device is set into a reset state.
  * After the upload the firmware is booted and the renumeration starts.
  * After the upload the firmware is booted and the renumeration starts.
  * During this process the device disappears from the bus and a new one
  * During this process the device disappears from the bus and a new one
  * occurs which will be assigned to this class automatically (instead of the disappeared one).
  * occurs which will be assigned to this class automatically (instead of the disappeared one).
  * @param ihxIn Input stream from which the ihx file is read.
  * @param ihxIn Input stream from which the ihx file is read.
  * @param name Name of the input.
  * @param name Name of the input.
  * @param force The compatibility check is skipped if true.
  * @param force The compatibility check is skipped if true.
  * @throws IncompatibleFirmwareException if the given firmware is not compatible to the installed one, see {@link ZtexDevice1#compatible(int,int,int,int)} (Upload can be enforced using the <tt>force</tt> parameter)
  * @throws IncompatibleFirmwareException if the given firmware is not compatible to the installed one, see {@link ZtexDevice1#compatible(int,int,int,int)} (Upload can be enforced using the <tt>force</tt> parameter)
  * @throws FirmwareUploadException If an error occurred while attempting to upload the firmware.
  * @throws FirmwareUploadException If an error occurred while attempting to upload the firmware.
  * @throws UsbException if a communication error occurs.
  * @throws UsbException if a communication error occurs.
  * @throws InvalidFirmwareException if ZTEX descriptor 1 is not available.
  * @throws InvalidFirmwareException if ZTEX descriptor 1 is not available.
  * @throws DeviceLostException if a device went lost after renumeration.
  * @throws DeviceLostException if a device went lost after renumeration.
  * @return the upload time in ms.
  * @return the upload time in ms.
  */
  */
//  returns upload time in ms
//  returns upload time in ms
    public long uploadFirmware ( InputStream ihxIn, String name, boolean force ) throws IncompatibleFirmwareException, FirmwareUploadException, UsbException, InvalidFirmwareException, DeviceLostException {
    public long uploadFirmware ( InputStream ihxIn, String name, boolean force ) throws IncompatibleFirmwareException, FirmwareUploadException, UsbException, InvalidFirmwareException, DeviceLostException {
// load the ihx file
// load the ihx file
        ZtexIhxFile1 ihxFile;
        ZtexIhxFile1 ihxFile;
        try {
        try {
            ihxFile = new ZtexIhxFile1( ihxIn, name );
            ihxFile = new ZtexIhxFile1( ihxIn, name );
        }
        }
        catch ( IOException e ) {
        catch ( IOException e ) {
            throw new FirmwareUploadException( e.getLocalizedMessage() );
            throw new FirmwareUploadException( e.getLocalizedMessage() );
        }
        }
        catch ( IhxFileDamagedException e ) {
        catch ( IhxFileDamagedException e ) {
            throw new FirmwareUploadException( e.getLocalizedMessage() );
            throw new FirmwareUploadException( e.getLocalizedMessage() );
        }
        }
        return uploadFirmware( ihxFile, force );
        return uploadFirmware( ihxFile, force );
    }
    }
 
 
// ******* resetEzUsb **********************************************************
// ******* resetEzUsb **********************************************************
/**
/**
  * Resets the EZ-USB and manages the renumeration process.
  * Resets the EZ-USB and manages the renumeration process.
  * <p>
  * <p>
  * After the reset the renumeration starts.
  * After the reset the renumeration starts.
  * During this process the device disappears from the bus and a new one
  * During this process the device disappears from the bus and a new one
  * occurs which will be assigned to this class automatically (instead of the disappeared one).
  * occurs which will be assigned to this class automatically (instead of the disappeared one).
  * @throws FirmwareUploadException If an error occurred while attempting to upload the firmware.
  * @throws FirmwareUploadException If an error occurred while attempting to upload the firmware.
  * @throws UsbException if a communication error occurs.
  * @throws UsbException if a communication error occurs.
  * @throws InvalidFirmwareException if ZTEX descriptor 1 is not available.
  * @throws InvalidFirmwareException if ZTEX descriptor 1 is not available.
  * @throws DeviceLostException if a device went lost after renumeration.
  * @throws DeviceLostException if a device went lost after renumeration.
  */
  */
    public void resetEzUsb () throws FirmwareUploadException, UsbException, InvalidFirmwareException, DeviceLostException {
    public void resetEzUsb () throws FirmwareUploadException, UsbException, InvalidFirmwareException, DeviceLostException {
// scan the bus for comparison
// scan the bus for comparison
        findOldDevices();
        findOldDevices();
 
 
// reset the EZ-USB
// reset the EZ-USB
        EzUsb.reset(handle,true);
        EzUsb.reset(handle,true);
        try {
        try {
            EzUsb.reset(handle,false);          // error (may caused by re-numeration) can be ignored
            EzUsb.reset(handle,false);          // error (may caused by re-numeration) can be ignored
        }
        }
        catch ( FirmwareUploadException e ) {
        catch ( FirmwareUploadException e ) {
        }
        }
 
 
// find and init new device
// find and init new device
        initNewDevice( "Device lost after resetting the EZ-USB", true );
        initNewDevice( "Device lost after resetting the EZ-USB", true );
    }
    }
 
 
// ******* toString ************************************************************
// ******* toString ************************************************************
/**
/**
  * Returns a lot of useful information about the corresponding device.
  * Returns a lot of useful information about the corresponding device.
  * @return a lot of useful information about the corresponding device.
  * @return a lot of useful information about the corresponding device.
  */
  */
    public String toString () {
    public String toString () {
        return dev.toString();
        return dev.toString();
    }
    }
 
 
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.