Line 1... |
Line 1... |
/*!
|
/*!
|
ucecho -- example for ZTEX USB FPGA Module 1.2
|
ucecho -- uppercase conversion example for all EZ-USB devices
|
Copyright (C) 2008-2009 ZTEX e.K.
|
Copyright (C) 2009-2010 ZTEX e.K.
|
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.
|
Line 50... |
Line 50... |
// constructor
|
// constructor
|
public UCEcho ( ZtexDevice1 pDev ) throws UsbException {
|
public UCEcho ( ZtexDevice1 pDev ) throws UsbException {
|
super ( pDev );
|
super ( pDev );
|
}
|
}
|
|
|
// ******* claimInterface ******************************************************
|
|
// claims interface 0
|
|
public void claimInterface ( ) throws UsbException{
|
|
if ( LibusbJava.usb_set_configuration(handle(), 1) < 0 )
|
|
throw new UsbException("Setting configuration to 1 failed: " + LibusbJava.usb_strerror());
|
|
if ( LibusbJava.usb_claim_interface(handle(), 0) < 0 )
|
|
throw new UsbException("Claiming interface 0 failed: " + LibusbJava.usb_strerror());
|
|
}
|
|
|
|
// ******* releaseInterface ****************************************************
|
|
// releases interface 0
|
|
public void releaseInterface ( ) {
|
|
LibusbJava.usb_release_interface(handle(), 0);
|
|
}
|
|
|
|
// ******* echo ****************************************************************
|
// ******* echo ****************************************************************
|
// writes a string to Endpoint 4, reads it back from Endpoint 2 and writes the output to System.out
|
// writes a string to Endpoint 4, reads it back from Endpoint 2 and writes the output to System.out
|
public void echo ( String input ) throws UsbException {
|
public void echo ( String input ) throws UsbException {
|
byte buf[] = input.getBytes();
|
byte buf[] = input.getBytes();
|
int i = LibusbJava.usb_bulk_write(handle(), 0x04, buf, buf.length, 1000);
|
int i = LibusbJava.usb_bulk_write(handle(), 0x04, buf, buf.length, 1000);
|
Line 99... |
Line 84... |
try {
|
try {
|
// init USB stuff
|
// init USB stuff
|
LibusbJava.usb_init();
|
LibusbJava.usb_init();
|
|
|
// scan the USB bus
|
// scan the USB bus
|
ZtexScanBus1 bus = new ZtexScanBus1( ZtexDevice1.cypressVendorId, ZtexDevice1.cypressProductId, true, false, 1);
|
ZtexScanBus1 bus = new ZtexScanBus1( ZtexDevice1.ztexVendorId, ZtexDevice1.ztexProductId, true, false, 1);
|
if ( bus.numberOfDevices() <= 0) {
|
if ( bus.numberOfDevices() <= 0) {
|
System.err.println("No devices found");
|
System.err.println("No devices found");
|
System.exit(0);
|
System.exit(0);
|
}
|
}
|
|
|
Line 149... |
Line 134... |
if ( force || ! ztex.valid() || ! ztex.dev().productString().equals("ucecho for EZ-USB devices") ) {
|
if ( force || ! ztex.valid() || ! ztex.dev().productString().equals("ucecho for EZ-USB devices") ) {
|
System.out.println("Firmware upload time: " + ztex.uploadFirmware( "ucecho.ihx", force ) + " ms");
|
System.out.println("Firmware upload time: " + ztex.uploadFirmware( "ucecho.ihx", force ) + " ms");
|
}
|
}
|
|
|
// claim interface 0
|
// claim interface 0
|
ztex.claimInterface();
|
ztex.trySetConfiguration ( 1 );
|
|
ztex.claimInterface ( 0 );
|
|
|
// read string from stdin and write it to USB device
|
// read string from stdin and write it to USB device
|
String str = "";
|
String str = "";
|
BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
|
BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
|
while ( ! str.equals("quit") ) {
|
while ( ! str.equals("quit") ) {
|
Line 163... |
Line 149... |
ztex.echo(str);
|
ztex.echo(str);
|
System.out.println("");
|
System.out.println("");
|
}
|
}
|
|
|
// release interface 0
|
// release interface 0
|
ztex.releaseInterface();
|
ztex.releaseInterface(0);
|
|
|
}
|
}
|
catch (Exception e) {
|
catch (Exception e) {
|
System.out.println("Error: "+e.getLocalizedMessage() );
|
System.out.println("Error: "+e.getLocalizedMessage() );
|
}
|
}
|