diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..26e7af5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+/build/
+/dist/
+/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
+/nbproject/
\ No newline at end of file
diff --git a/build.xml b/build.xml
index f7926c9..ff2ea81 100644
--- a/build.xml
+++ b/build.xml
@@ -74,7 +74,7 @@
-
+
diff --git a/lib/jna-3.2.7-arm-hf.jar b/lib/jna-3.2.7-arm-hf.jar
new file mode 100644
index 0000000..bebb150
Binary files /dev/null and b/lib/jna-3.2.7-arm-hf.jar differ
diff --git a/lib/jna.jar b/lib/jna.jar
deleted file mode 100644
index 57f31c3..0000000
Binary files a/lib/jna.jar and /dev/null differ
diff --git a/lib/nblibraries.properties b/lib/nblibraries.properties
index 03b52d6..1c91935 100644
--- a/lib/nblibraries.properties
+++ b/lib/nblibraries.properties
@@ -1,2 +1,4 @@
-libs.CopyLibs.classpath=\
- ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
+libs.CopyLibs.classpath=\
+ ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar
+libs.CopyLibs.displayName=CopyLibs Task
+libs.CopyLibs.prop-version=2.0
diff --git a/native/natives/arm926/libftd2xx.a b/native/natives/arm926/libftd2xx.a
new file mode 100644
index 0000000..c851cdd
Binary files /dev/null and b/native/natives/arm926/libftd2xx.a differ
diff --git a/native/natives/arm926/libftd2xx.so b/native/natives/arm926/libftd2xx.so
new file mode 100644
index 0000000..6dbdc11
Binary files /dev/null and b/native/natives/arm926/libftd2xx.so differ
diff --git a/native/natives/arm926hf/libftd2xx.a b/native/natives/arm926hf/libftd2xx.a
new file mode 100644
index 0000000..1dcc8ea
Binary files /dev/null and b/native/natives/arm926hf/libftd2xx.a differ
diff --git a/native/natives/arm926hf/libftd2xx.so b/native/natives/arm926hf/libftd2xx.so
new file mode 100644
index 0000000..a4f2d1a
Binary files /dev/null and b/native/natives/arm926hf/libftd2xx.so differ
diff --git a/native/natives/i386/ftd2xx.dll b/native/natives/i386/ftd2xx.dll
index 3b8c0ab..349b589 100644
Binary files a/native/natives/i386/ftd2xx.dll and b/native/natives/i386/ftd2xx.dll differ
diff --git a/native/natives/i386/ftd2xx.lib b/native/natives/i386/ftd2xx.lib
index bccb53b..6449dd2 100644
Binary files a/native/natives/i386/ftd2xx.lib and b/native/natives/i386/ftd2xx.lib differ
diff --git a/native/natives/x86_64/ftd2xx.dll b/native/natives/x86_64/ftd2xx.dll
index 2c2602c..af270c1 100644
Binary files a/native/natives/x86_64/ftd2xx.dll and b/native/natives/x86_64/ftd2xx.dll differ
diff --git a/native/natives/x86_64/ftd2xx.lib b/native/natives/x86_64/ftd2xx.lib
index 96b4284..6896e3c 100644
Binary files a/native/natives/x86_64/ftd2xx.lib and b/native/natives/x86_64/ftd2xx.lib differ
diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml
index 3346366..8d0a0ac 100644
--- a/nbproject/build-impl.xml
+++ b/nbproject/build-impl.xml
@@ -1,1067 +1,1438 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must set src.dir
- Must set test.src.dir
- Must set build.dir
- Must set dist.dir
- Must set build.classes.dir
- Must set dist.javadoc.dir
- Must set build.test.classes.dir
- Must set build.test.results.dir
- Must set build.classes.excludes
- Must set dist.jar
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must set javac.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must set JVM to use for profiling in profiler.info.jvm
- Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select some files in the IDE or set javac.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- To run this application from the command line without Ant, try:
-
-
-
-
-
-
- java -cp "${run.classpath.with.dist.jar}" ${main.class}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- To run this application from the command line without Ant, try:
-
- java -jar "${dist.jar.resolved}"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set run.class
-
-
-
- Must select one file in the IDE or set run.class
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set debug.class
-
-
-
-
- Must select one file in the IDE or set debug.class
-
-
-
-
- Must set fix.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set profile.class
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select some files in the IDE or set javac.includes
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Some tests failed; see details above.
-
-
-
-
-
-
-
-
- Must select some files in the IDE or set test.includes
-
-
-
- Some tests failed; see details above.
-
-
-
-
- Must select one file in the IDE or set test.class
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set applet.url
-
-
-
-
-
-
-
-
- Must select one file in the IDE or set applet.url
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set src.dir
+ Must set test.src.dir
+ Must set build.dir
+ Must set dist.dir
+ Must set build.classes.dir
+ Must set dist.javadoc.dir
+ Must set build.test.classes.dir
+ Must set build.test.results.dir
+ Must set build.classes.excludes
+ Must set dist.jar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ No tests executed.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set JVM to use for profiling in profiler.info.jvm
+ Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ To run this application from the command line without Ant, try:
+
+ java -jar "${dist.jar.resolved}"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set debug.class
+
+
+
+
+ Must select one file in the IDE or set debug.class
+
+
+
+
+ Must set fix.includes
+
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set profile.class
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+
+ Must select some files in the IDE or set test.includes
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Some tests failed; see details above.
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set test.includes
+
+
+
+ Some tests failed; see details above.
+
+
+
+ Must select some files in the IDE or set test.class
+ Must select some method in the IDE or set test.method
+
+
+
+ Some tests failed; see details above.
+
+
+
+
+ Must select one file in the IDE or set test.class
+
+
+
+ Must select one file in the IDE or set test.class
+ Must select some method in the IDE or set test.method
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties
index 05316e3..4d8f955 100644
--- a/nbproject/genfiles.properties
+++ b/nbproject/genfiles.properties
@@ -1,8 +1,8 @@
-build.xml.data.CRC32=06edd407
-build.xml.script.CRC32=c738cfbe
-build.xml.stylesheet.CRC32=28e38971@1.43.1.45
-# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
-# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=6aaf98a2
-nbproject/build-impl.xml.script.CRC32=7815eb66
-nbproject/build-impl.xml.stylesheet.CRC32=0ae3a408@1.44.1.45
+build.xml.data.CRC32=06edd407
+build.xml.script.CRC32=c738cfbe
+build.xml.stylesheet.CRC32=28e38971@1.43.1.45
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+nbproject/build-impl.xml.data.CRC32=6aaf98a2
+nbproject/build-impl.xml.script.CRC32=de5d123f
+nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.1.48
diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties
index c9d65c7..e4a7ad6 100644
--- a/nbproject/private/private.properties
+++ b/nbproject/private/private.properties
@@ -1,6 +1,6 @@
-compile.on.save=true
-do.depend=false
-do.jar=true
-javac.debug=true
-javadoc.preview=true
-user.properties.file=/home/kocsis/.netbeans/7.0/build.properties
+compile.on.save=true
+do.depend=false
+do.jar=true
+javac.debug=true
+javadoc.preview=true
+user.properties.file=C:\\Users\\Ed\\SkyDrive\\PortableApps\\PortableApps\\NetBeans_JavaSE_8.0_Portable\\Data\\NetBeans\\Config\\8.0\\build.properties
diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml
index c1f155a..02ced2d 100644
--- a/nbproject/private/private.xml
+++ b/nbproject/private/private.xml
@@ -1,4 +1,14 @@
-
-
-
-
+
+
+
+
+
+
+ file:/C:/Users/Ed/moba/workspace/JavaFTD2XX/nbproject/project.properties
+ file:/C:/Users/Ed/moba/workspace/JavaFTD2XX/src/com/ftdi/FTD2XX.java
+ file:/C:/Users/Ed/moba/workspace/JavaFTD2XX/build.xml
+ file:/C:/Users/Ed/moba/workspace/JavaFTD2XX/src/com/ftdi/FTDevice.java
+ file:/C:/Users/Ed/moba/workspace/JavaFTD2XX/src/com/ftdi/EEPROMData.java
+
+
+
diff --git a/nbproject/project.properties b/nbproject/project.properties
index 2e0fc99..0b8c67a 100644
--- a/nbproject/project.properties
+++ b/nbproject/project.properties
@@ -1,85 +1,86 @@
-annotation.processing.enabled=true
-annotation.processing.enabled.in.editor=false
-annotation.processing.run.all.processors=true
-annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
-application.title=JavaFTD2XX
-application.vendor=Peter Kocsis
-build.classes.dir=${build.dir}/classes
-build.classes.excludes=**/*.java,**/*.form
-# This directory is removed when the project is cleaned:
-build.dir=build
-build.generated.dir=${build.dir}/generated
-build.generated.sources.dir=${build.dir}/generated-sources
-# Only compile against the classpath explicitly listed here:
-build.sysclasspath=ignore
-build.test.classes.dir=${build.dir}/test/classes
-build.test.results.dir=${build.dir}/test/results
-# Uncomment to specify the preferred debugger connection transport:
-#debug.transport=dt_socket
-debug.classpath=\
- ${run.classpath}
-debug.test.classpath=\
- ${run.test.classpath}
-# This directory is removed when the project is cleaned:
-dist.dir=dist
-dist.jar=${dist.dir}/JavaFTD2XX.jar
-dist.javadoc.dir=${dist.dir}/javadoc
-endorsed.classpath=
-excludes=
-file.reference.jna.jar=lib/jna.jar
-includes=**
-jar.archive.disabled=${jnlp.enabled}
-jar.compress=false
-jar.index=${jnlp.enabled}
-javac.classpath=\
- ${file.reference.jna.jar}
-# Space-separated list of extra javac options
-javac.compilerargs=
-javac.deprecation=false
-javac.processorpath=\
- ${javac.classpath}
-javac.source=1.6
-javac.target=1.6
-javac.test.classpath=\
- ${javac.classpath}:\
- ${build.classes.dir}
-javac.test.processorpath=\
- ${javac.test.classpath}
-javadoc.additionalparam=
-javadoc.author=false
-javadoc.encoding=${source.encoding}
-javadoc.noindex=false
-javadoc.nonavbar=false
-javadoc.notree=false
-javadoc.private=false
-javadoc.splitindex=true
-javadoc.use=true
-javadoc.version=false
-javadoc.windowtitle=
-jnlp.codebase.type=no.codebase
-jnlp.descriptor=application
-jnlp.enabled=false
-jnlp.mixed.code=default
-jnlp.offline-allowed=false
-jnlp.signed=false
-jnlp.signing=
-jnlp.signing.alias=
-jnlp.signing.keystore=
-meta.inf.dir=${src.dir}/META-INF
-mkdist.disabled=true
-platform.active=default_platform
-run.classpath=\
- ${javac.classpath}:\
- ${build.classes.dir}
-# Space-separated list of JVM arguments used when running the project
-# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
-# or test-sys-prop.name=value to set system properties for unit tests):
-run.jvmargs=
-run.test.classpath=\
- ${javac.test.classpath}:\
- ${build.test.classes.dir}
-source.encoding=UTF-8
-src.dir=src
-test.src.dir=test
-project.license=mit
-project.version=0.2.5
\ No newline at end of file
+annotation.processing.enabled=true
+annotation.processing.enabled.in.editor=false
+annotation.processing.processors.list=
+annotation.processing.run.all.processors=true
+annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+application.title=JavaFTD2XX
+application.vendor=Peter Kocsis
+build.classes.dir=${build.dir}/classes
+build.classes.excludes=**/*.java,**/*.form
+# This directory is removed when the project is cleaned:
+build.dir=build
+build.generated.dir=${build.dir}/generated
+build.generated.sources.dir=${build.dir}/generated-sources
+# Only compile against the classpath explicitly listed here:
+build.sysclasspath=ignore
+build.test.classes.dir=${build.dir}/test/classes
+build.test.results.dir=${build.dir}/test/results
+# Uncomment to specify the preferred debugger connection transport:
+#debug.transport=dt_socket
+debug.classpath=\
+ ${run.classpath}
+debug.test.classpath=\
+ ${run.test.classpath}
+# This directory is removed when the project is cleaned:
+dist.dir=dist
+dist.jar=${dist.dir}/JavaFTD2XX.jar
+dist.javadoc.dir=${dist.dir}/javadoc
+endorsed.classpath=
+excludes=
+file.reference.jna-3.2.7-arm-hf.jar=lib\\jna-3.2.7-arm-hf.jar
+includes=**
+jar.archive.disabled=${jnlp.enabled}
+jar.compress=false
+jar.index=${jnlp.enabled}
+javac.classpath=\
+ ${file.reference.jna-3.2.7-arm-hf.jar}
+# Space-separated list of extra javac options
+javac.compilerargs=
+javac.deprecation=false
+javac.processorpath=\
+ ${javac.classpath}
+javac.source=1.6
+javac.target=1.6
+javac.test.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
+javac.test.processorpath=\
+ ${javac.test.classpath}
+javadoc.additionalparam=
+javadoc.author=false
+javadoc.encoding=${source.encoding}
+javadoc.noindex=false
+javadoc.nonavbar=false
+javadoc.notree=false
+javadoc.private=false
+javadoc.splitindex=true
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+jnlp.codebase.type=no.codebase
+jnlp.descriptor=application
+jnlp.enabled=false
+jnlp.mixed.code=default
+jnlp.offline-allowed=false
+jnlp.signed=false
+jnlp.signing=
+jnlp.signing.alias=
+jnlp.signing.keystore=
+meta.inf.dir=${src.dir}/META-INF
+mkdist.disabled=true
+platform.active=default_platform
+run.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
+# Space-separated list of JVM arguments used when running the project
+# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
+# or test-sys-prop.name=value to set system properties for unit tests):
+run.jvmargs=
+run.test.classpath=\
+ ${javac.test.classpath}:\
+ ${build.test.classes.dir}
+source.encoding=UTF-8
+src.dir=src
+test.src.dir=test
+project.license=mit
+project.version=0.2.10
diff --git a/src/com/ftdi/DeviceStatus.java b/src/com/ftdi/DeviceStatus.java
index 5483a0d..d046d7f 100644
--- a/src/com/ftdi/DeviceStatus.java
+++ b/src/com/ftdi/DeviceStatus.java
@@ -35,39 +35,42 @@ public enum DeviceStatus {
/**
* Clear To Send
*/
- CTS(0x10),
+ CTS(0x10, "Clear To Send"),
/**
* Data Set Ready
*/
- DSR(0x20),
+ DSR(0x20, "Data Set Ready"),
/**
* Ring Indicator
*/
- RI(0x40),
+ RI(0x40, "Ring Indicator"),
/**
* Data Carrier Detect
*/
- DCD(0x80),
+ DCD(0x80, "Data Carrier Detect"),
/**
* Overrun Error
*/
- OE(0x02),
+ OE(0x02, "Overrun Error"),
/**
* Parity Error
*/
- PE(0x04),
+ PE(0x04, "Parity Error"),
/**
* Framing Error
*/
- FE(0x08),
+ FE(0x08, "Framing Error"),
/**
* Break Interrupt
*/
- BI(0x10);
+ BI(0x10, "Break Interrupt");
+
private final int constant;
+ private final String description;
- private DeviceStatus(int constant) {
+ private DeviceStatus(int constant, String description) {
this.constant = constant;
+ this.description = description;
}
int constant() {
@@ -83,4 +86,10 @@ static EnumSet parseToEnumset(int val){
}
return EnumSet.copyOf(enu);
}
+
+ @Override
+ public String toString() {
+ return super.toString() + " (" + description + ")";
+ }
+
}
diff --git a/src/com/ftdi/FTD2XX.java b/src/com/ftdi/FTD2XX.java
index f65aaa3..235f381 100644
--- a/src/com/ftdi/FTD2XX.java
+++ b/src/com/ftdi/FTD2XX.java
@@ -1,1338 +1,1409 @@
-/*
- * The MIT License
- *
- * Copyright 2011 Peter Kocsis .
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.ftdi;
-
-import com.sun.jna.Library;
-import com.sun.jna.Memory;
-import com.sun.jna.Native;
-import com.sun.jna.Platform;
-import com.sun.jna.Pointer;
-import com.sun.jna.Structure;
-import com.sun.jna.ptr.ByteByReference;
-import com.sun.jna.ptr.IntByReference;
-import com.sun.jna.ptr.ShortByReference;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.StringTokenizer;
-
-/**
- *
- * @author Peter Kocsis
- */
-interface FTD2XX extends Library {
-
- static class Loader {
-
- private Loader() {
- }
-
- static String getNative() {
- InputStream in = null;
- FileOutputStream fos = null;
- File fileOut = null;
- System.setProperty("jna.library.path",
- System.getProperty("java.io.tmpdir"));
-
- if (Platform.isMac()) {
- in = Loader.class.getResourceAsStream(
- "/natives/libftd2xx.dylib");
- } else if (Platform.is64Bit()) {
- if (Platform.isLinux()) {
- in = Loader.class.getResourceAsStream(
- "/natives/x86_64/libftd2xx.so");
- } else if (Platform.isWindows()) {
- in = Loader.class.getResourceAsStream(
- "/natives/x86_64/ftd2xx.dll");
- }
- } else {
- if (Platform.isLinux()) {
- in = Loader.class.getResourceAsStream(
- "/natives/i386/libftd2xx.so");
- } else if (Platform.isWindows()) {
- in = Loader.class.getResourceAsStream(
- "/natives/i386/ftd2xx.dll");
- }
- }
-
- if (in != null) {
- try {
- fileOut = File.createTempFile(Platform.isMac() ? "lib" : ""
- + "ftd2xx", Platform.isWindows() ? ".dll"
- : Platform.isLinux() ? ".so" : ".dylib");
- fileOut.deleteOnExit();
-
- fos = new FileOutputStream(fileOut);
-
- int count;
- byte[] buf = new byte[1024];
-
- while ((count = in.read(buf, 0, buf.length)) > 0) {
- fos.write(buf, 0, count);
- }
-
- } catch (IOException ex) {
- throw new Error("Failed to create temporary file "
- + "for d2xx library: " + ex);
- } finally {
- try {
- in.close();
- } catch (IOException ex) {
- }
-
- if (fos != null) {
- try {
- fos.close();
- } catch (IOException ex) {
- }
- }
-
- String res;
- if (Platform.isMac()) {
- StringTokenizer st = new StringTokenizer(
- fileOut.getName(), ".");
- res = st.nextToken().substring(3);
- } else {
- res = fileOut.getName();
- }
- return res;
- }
- } else {
- throw new Error("Not supported OS");
- }
- }
- }
- final FTD2XX INSTANCE = (FTD2XX) Native.loadLibrary(
- Loader.getNative(), FTD2XX.class);
- public final static int FT_FLAGS_OPENED = 0x00000001;
- public final static int FT_LIST_NUMBER_ONLY = 0x80000,
- FT_LIST_BY_INDEX = 0x40000000,
- FT_LIST_ALL = 0x20000000;
- public final static int FT_OPEN_BY_SERIAL_NUMBER = 1,
- FT_OPEN_BY_DESCRIPTION = 2,
- FT_OPEN_BY_LOCATION = 4;
-
- public static class NotificationEvents {
-
- public final static int FT_EVENT_RXCHAR = 1,
- FT_EVENT_MODEM_STATUS = 2,
- FT_EVENT_LINE_STATUS = 4;
- }
-
- public static class FT_DEVICE_LIST_INFO_NODE extends Structure {
-
- public int Flags;
- public int Type;
- public int ID;
- public int LocId;
- public Memory SerialNumber = new Memory(16);
- public Memory Description = new Memory(64);
- public int ftHandle;
- }
-
- public static class FT_PROGRAM_DATA extends Structure {
-
- public static class ByReference extends FT_PROGRAM_DATA
- implements Structure.ByReference {
- }
- /**
- * Header - must be 0x0000000
- */
- public int Signature1 = 0x0000000;
- /**
- * Header - must be 0xffffffff
- */
- public int Signature2 = 0xffffffff;
- /**
- * // Header - FT_PROGRAM_DATA version
- * 0 = original (FT232B)
- * 1 = FT2232 extensions
- * 2 = FT232R extensions
- * 3 = FT2232H extensions
- * 4 = FT4232H extensions
- * 5 = FT232H extensions
- */
- public int Version = 0x00000000;
- /**
- * 0x0403
- */
- public short VendorId;
- /**
- * 0x6001
- */
- public short ProductId;
- /**
- * "FTDI"
- */
- public Pointer Manufacturer = new Memory(32);
- /**
- * "FT"
- */
- public Pointer ManufacturerId = new Memory(16);
- /**
- * "USB HS Serial Converter"
- */
- public Pointer Description = new Memory(64);
- /**
- * "FT000001" if fixed, or NULL
- */
- public Pointer SerialNumber = new Memory(16);
- /**
- * 0 < MaxPower <= 500
- */
- public short MaxPower;
- /**
- * 0 = disabled, 1 = enabled
- */
- public short PnP;
- /**
- * 0 = bus powered, 1 = self powered
- */
- public short SelfPowered;
- /**
- * 0 = not capable, 1 = capable
- */
- public short RemoteWakeup;
-//
-// Rev4 (FT232B) extensions
-//
- /**
- * non-zero if Rev4 chip, zero otherwise
- */
- public byte Rev4;
- /**
- * non-zero if in endpoint is isochronous
- */
- public byte IsoIn;
- /**
- * non-zero if out endpoint is isochronous
- */
- public byte IsoOut;
- /**
- * non-zero if pull down enabled
- */
- public byte PullDownEnable;
- /**
- * non-zero if serial number to be used
- */
- public byte SerNumEnable;
- /**
- * non-zero if chip uses USBVersion
- */
- public byte USBVersionEnable;
- /**
- * BCD (0x0200 => USB2)
- */
- public short USBVersion;
-//
-// Rev 5 (FT2232) extensions
-//
- /**
- * non-zero if Rev5 chip, zero otherwise
- */
- public byte Rev5;
- /**
- * non-zero if in endpoint is isochronous
- */
- public byte IsoInA;
- /**
- * non-zero if in endpoint is isochronous
- */
- public byte IsoInB;
- /**
- * non-zero if out endpoint is isochronous
- */
- public byte IsoOutA;
- /**
- * non-zero if out endpoint is isochronous
- */
- public byte IsoOutB;
- /**
- * non-zero if pull down enabled
- */
- public byte PullDownEnable5;
- /**
- * non-zero if serial number to be used
- */
- public byte SerNumEnable5;
- /**
- * non-zero if chip uses USBVersion
- */
- public byte USBVersionEnable5;
- /**
- * BCD (0x0200 => USB2)
- */
- public short USBVersion5;
- /**
- * non-zero if interface is high current
- */
- public byte AIsHighCurrent;
- /**
- * non-zero if interface is high current
- */
- public byte BIsHighCurrent;
- /**
- * non-zero if interface is 245 FIFO
- */
- public byte IFAIsFifo;
- /**
- * non-zero if interface is 245 FIFO CPU target
- */
- public byte IFAIsFifoTar;
- /**
- * non-zero if interface is Fast serial
- */
- public byte IFAIsFastSer;
- /**
- * non-zero if interface is to use VCP drivers
- */
- public byte AIsVCP;
- /**
- * non-zero if interface is 245 FIFO
- */
- public byte IFBIsFifo;
- /**
- * non-zero if interface is 245 FIFO CPU target
- */
- public byte IFBIsFifoTar;
- /**
- * non-zero if interface is Fast serial
- */
- public byte IFBIsFastSer;
- /**
- * non-zero if interface is to use VCP drivers
- */
- public byte BIsVCP;
-//
-// Rev 6 (FT232R) extensions
-//
- /**
- * Use External Oscillator
- */
- public byte UseExtOsc;
- /**
- * High Drive I/Os
- */
- public byte HighDriveIOs;
- /**
- * Endpoint size
- */
- public byte EndpointSize;
- /**
- * non-zero if pull down enabled
- */
- public byte PullDownEnableR;
- /**
- * non-zero if serial number to be used
- */
- public byte SerNumEnableR;
- /**
- * non-zero if invert TXD
- */
- public byte InvertTXD;
- /**
- * non-zero if invert RXD
- */
- public byte InvertRXD;
- /**
- * non-zero if invert RTS
- */
- public byte InvertRTS;
- /**
- * non-zero if invert CTS
- */
- public byte InvertCTS;
- /**
- * non-zero if invert DTR
- */
- public byte InvertDTR;
- /**
- * non-zero if invert DSR
- */
- public byte InvertDSR;
- /**
- * non-zero if invert DCD
- */
- public byte InvertDCD;
- /**
- * non-zero if invert RI
- */
- public byte InvertRI;
- /**
- * Cbus Mux control
- */
- public byte Cbus0;
- /**
- * Cbus Mux control
- */
- public byte Cbus1;
- /**
- * Cbus Mux control
- */
- public byte Cbus2;
- /**
- * Cbus Mux control
- */
- public byte Cbus3;
- /**
- * Cbus Mux control
- */
- public byte Cbus4;
- /**
- * non-zero if using D2XX driver
- */
- public byte RIsD2XX;
- //
-// Rev 7 (FT2232H) Extensions
-//
- /**
- * non-zero if pull down enabled
- */
- public byte PullDownEnable7;
- /**
- * non-zero if serial number to be used
- */
- public byte SerNumEnable7;
- /**
- * non-zero if AL pins have slow slew
- */
- public byte ALSlowSlew;
- /**
- * non-zero if AL pins are Schmitt input
- */
- public byte ALSchmittInput;
- /**
- * valid values are 4mA, 8mA, 12mA, 16mA
- */
- public byte ALDriveCurrent;
- /**
- * non-zero if AH pins have slow slew
- */
- public byte AHSlowSlew;
- /**
- * non-zero if AH pins are Schmitt input
- */
- public byte AHSchmittInput;
- /**
- * valid values are 4mA, 8mA, 12mA, 16mA
- */
- public byte AHDriveCurrent;
- /**
- * non-zero if BL pins have slow slew
- */
- public byte BLSlowSlew;
- /**
- * non-zero if BL pins are Schmitt input
- */
- public byte BLSchmittInput;
- /**
- * valid values are 4mA, 8mA, 12mA, 16mA
- */
- public byte BLDriveCurrent;
- /**
- * non-zero if BH pins have slow slew
- */
- public byte BHSlowSlew;
- /**
- * non-zero if BH pins are Schmitt input
- */
- public byte BHSchmittInput;
- /**
- * valid values are 4mA, 8mA, 12mA, 16mA
- */
- public byte BHDriveCurrent;
- /**
- * non-zero if interface is 245 FIFO
- */
- public byte IFAIsFifo7;
- /**
- * non-zero if interface is 245 FIFO CPU target
- */
- public byte IFAIsFifoTar7;
- /**
- * non-zero if interface is Fast serial
- */
- public byte IFAIsFastSer7;
- /**
- * non-zero if interface is to use VCP drivers
- */
- public byte AIsVCP7;
- /**
- * non-zero if interface is 245 FIFO
- */
- public byte IFBIsFifo7;
- /**
- * non-zero if interface is 245 FIFO CPU target
- */
- public byte IFBIsFifoTar7;
- /**
- * non-zero if interface is Fast serial
- */
- public byte IFBIsFastSer7;
- /**
- * non-zero if interface is to use VCP drivers
- */
- public byte BIsVCP7;
- /**
- * non-zero if using BCBUS7 to save power for self-powered designs
- */
- public byte PowerSaveEnable;
-//
-// Rev 8 (FT4232H) Extensions
-//
- /**
- * non-zero if pull down enabled
- */
- public byte PullDownEnable8;
- /**
- * non-zero if serial number to be used
- */
- public byte SerNumEnable8;
- /**
- * non-zero if AL pins have slow slew
- */
- public byte ASlowSlew;
- /**
- * non-zero if AL pins are Schmitt input
- */
- public byte ASchmittInput;
- /**
- * valid values are 4mA, 8mA, 12mA, 16mA
- */
- public byte ADriveCurrent;
- /**
- * non-zero if AH pins have slow slew
- */
- public byte BSlowSlew;
- /**
- * non-zero if AH pins are Schmitt input
- */
- public byte BSchmittInput;
- /**
- * valid values are 4mA, 8mA, 12mA, 16mA
- */
- public byte BDriveCurrent;
- /**
- * non-zero if BL pins have slow slew
- */
- public byte CSlowSlew;
- /**
- * non-zero if BL pins are Schmitt input
- */
- public byte CSchmittInput;
- /**
- * valid values are 4mA, 8mA, 12mA, 16mA
- */
- public byte CDriveCurrent;
- /**
- * non-zero if BH pins have slow slew
- */
- public byte DSlowSlew;
- /**
- * non-zero if BH pins are Schmitt input
- */
- public byte DSchmittInput;
- /**
- * valid values are 4mA, 8mA, 12mA, 16mA
- */
- public byte DDriveCurrent;
- /**
- * non-zero if port A uses RI as RS485 TXDEN
- */
- public byte ARIIsTXDEN;
- /**
- * non-zero if port B uses RI as RS485 TXDEN
- */
- public byte BRIIsTXDEN;
- /**
- * non-zero if port C uses RI as RS485 TXDEN
- */
- public byte CRIIsTXDEN;
- /**
- * non-zero if port D uses RI as RS485 TXDEN
- */
- public byte DRIIsTXDEN;
- /**
- * non-zero if interface is to use VCP drivers
- */
- public byte AIsVCP8;
- /**
- * non-zero if interface is to use VCP drivers
- */
- public byte BIsVCP8;
- /**
- * non-zero if interface is to use VCP drivers
- */
- public byte CIsVCP8;
- /**
- * non-zero if interface is to use VCP drivers
- */
- public byte DIsVCP8;
-//
-// Rev 9 (FT232H) Extensions
-//
- /**
- * non-zero if pull down enabled
- */
- public byte PullDownEnableH;
- /**
- * non-zero if serial number to be used
- */
- public byte SerNumEnableH;
- /**
- * non-zero if AC pins have slow slew
- */
- public byte ACSlowSlewH;
- /**
- * non-zero if AC pins are Schmitt input
- */
- public byte ACSchmittInputH;
- /**
- * valid values are 4mA, 8mA, 12mA, 16mA
- */
- public byte ACDriveCurrentH;
- /**
- * non-zero if AD pins have slow slew
- */
- public byte ADSlowSlewH;
- /**
- * non-zero if AD pins are Schmitt input
- */
- public byte ADSchmittInputH;
- /**
- * valid values are 4mA, 8mA, 12mA, 16mA
- */
- public byte ADDriveCurrentH;
- /**
- * Cbus Mux control
- */
- public byte Cbus0H;
- /**
- * Cbus Mux control
- */
- public byte Cbus1H;
- /**
- * Cbus Mux control
- */
- public byte Cbus2H;
- /**
- * Cbus Mux control
- */
- public byte Cbus3H;
- /**
- * Cbus Mux control
- */
- public byte Cbus4H;
- /**
- * Cbus Mux control
- */
- public byte Cbus5H;
- /**
- * Cbus Mux control
- */
- public byte Cbus6H;
- /**
- * Cbus Mux control
- */
- public byte Cbus7H;
- /**
- * Cbus Mux control
- */
- public byte Cbus8H;
- /**
- * Cbus Mux control
- */
- public byte Cbus9H;
- /**
- * non-zero if interface is 245 FIFO
- */
- public byte IsFifoH;
- /**
- * non-zero if interface is 245 FIFO CPU target
- */
- public byte IsFifoTarH;
- /**
- * non-zero if interface is Fast serial
- */
- public byte IsFastSerH;
- /**
- * non-zero if interface is FT1248
- */
- public byte IsFT1248H;
- /**
- * FT1248 clock polarity - clock idle high (1) or clock idle low (0)
- */
- public byte FT1248CpolH;
- /**
- * FT1248 data is LSB (1) or MSB (0)
- */
- public byte FT1248LsbH;
- /**
- * FT1248 flow control enable
- */
- public byte FT1248FlowControlH;
- /**
- * non-zero if interface is to use VCP drivers
- */
- public byte IsVCPH;
- /**
- * non-zero if using ACBUS7 to save power for self-powered designs
- */
- public byte PowerSaveEnableH;
- }
-
- /**
- * A command to include a custom VID and PID combination within the internal
- * device list table. This will allow the driver to load for the specified
- * VID and PID combination.
- * @param dwVID Device Vendor ID (VID)
- * @param dwPID Device Product ID (PID)
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetVIDPID(int dwVID, int dwPID);
-
- /**
- * A command to retrieve the current VID and PID combination from within the
- * internal device list table.
- * @param pdwVID Pointer to DWORD(int) that will contain the internal VID
- * @param pdwPID Pointer to DWORD(int) that will contain the internal PID
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_GetVIDPID(IntByReference pdwVID, IntByReference pdwPID);
-
- /**
- * This function builds a device information list and returns the number of
- * D2XX devices connected to the system. The list contains information
- * about both unopen and open devices.
- * @param lpdwNumDevs Pointer to unsigned long(long) to store the number of
- * devices connected.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_CreateDeviceInfoList(IntByReference lpdwNumDevs);
-
- /**
- * This function returns an entry from the device information list.
- * @param pDest Pointer to an array of FT_DEVICE_LIST_INFO_NODE structures.
- * @param lpdwNumDevs Pointer to the number of elements in the array
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_GetDeviceInfoList(FT_DEVICE_LIST_INFO_NODE[] pDest,
- IntByReference lpdwNumDevs);
-
- /**
- * This function returns an entry from the device information list.
- * @param dwIndex Index of the entry in the device info list.
- * @param lpdwFlags Pointer to unsigned long to store the flag value.
- * @param lpdwType Pointer to unsigned long to store device type.
- * @param lpdwID Pointer to unsigned long to store device ID.
- * @param lpdwLocId Pointer to unsigned long to store the device location ID.
- * @param pcSerialNumber Pointer to buffer to store device serial number as
- * a nullterminated string.
- * @param pcDescription Pointer to buffer to store device description as a
- * null-terminated string.
- * @param ftHandle Pointer to a variable of type FT_HANDLE where the handle
- * will be stored.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_GetDeviceInfoDetail(int dwIndex, IntByReference lpdwFlags,
- IntByReference lpdwType, IntByReference lpdwID,
- IntByReference lpdwLocId, Pointer pcSerialNumber,
- Pointer pcDescription, IntByReference ftHandle);
-
- /**
- * Gets information concerning the devices currently connected. This
- * function can return information such as the number of devices connected,
- * the device serial number and device description strings, and the
- * location IDs of connected devices.
- * @param pvArg1 Meaning depends on dwFlags
- * @param pvArg2 Meaning depends on dwFlags
- * @param dwFlags Determines format of returned information.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_ListDevices(Pointer pvArg1, Pointer pvArg2, int dwFlags);
-
- /**
- * Open the device and return a handle which will be used for subsequent
- * accesses.
- * @param iDevice Index of the device to open. Indices are 0 based.
- * @param ftHandle Pointer to a variable of type FT_HANDLE where the handle
- * will be stored. This handle must be used to access the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_Open(int iDevice, IntByReference ftHandle);
-
- /**
- * Open the specified device and return a handle that will be used for
- * subsequent accesses. The device can be specified by its serial number,
- * device description or location. This function can also be used to open
- * multiple devices simultaneously. Multiple devices can be specified by
- * serial number, device description or location ID (location information
- * derived from the physical location of a device on USB). Location IDs for
- * specific USB ports can be obtained using the utility USBView and are
- * given in hexadecimal format. Location IDs for devices connected to a
- * system can be obtained by calling FT_GetDeviceInfoList or FT_ListDevices
- * with the appropriate flags.
- * @param pvArg1 Pointer to an argument whose type depends on the value of
- * dwFlags. It is normally be interpreted as a pointer to a null
- * terminated string.
- * @param dwFlags FT_OPEN_BY_SERIAL_NUMBER, FT_OPEN_BY_DESCRIPTION or
- * FT_OPEN_BY_LOCATION.
- * @param ftHandle Pointer to a variable of type FT_HANDLE where the handle
- * will be stored. This handle must be used to access the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_OpenEx(Pointer pvArg1, int dwFlags, IntByReference ftHandle);
-
- /**
- * Close an open device.
- * @param ftHandle Handle of the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_Close(int ftHandle);
-
- /**
- * Read data from the device.
- * @param ftHandle Handle of the device.
- * @param lpBuffer Pointer to the buffer that receives the data from the
- * device.
- * @param dwBytesToRead Number of bytes to be read from the device.
- * @param lpdwBytesReturned Pointer to a variable of type DWORD which
- * receives the number of bytes read from the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_Read(int ftHandle, Pointer lpBuffer, int dwBytesToRead,
- IntByReference lpdwBytesReturned);
-
- /**
- * Write data to the device.
- * @param ftHandle Handle of the device.
- * @param lpBuffer Pointer to the buffer that contains the data to be
- * written to the device.
- * @param dwBytesToWrite Number of bytes to write to the device.
- * @param lpdwBytesWritten Pointer to a variable of type DWORD which
- * receives the number of bytes written to the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_Write(int ftHandle, Pointer lpBuffer, int dwBytesToWrite,
- IntByReference lpdwBytesWritten);
-
- /**
- * This function sets the baud rate for the device.
- * @param ftHandle Handle of the device.
- * @param dwBaudRate Baud rate.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetBaudRate(int ftHandle, int dwBaudRate);
-
- /**
- * This function sets the baud rate for the device. It is used to set
- * non-standard baud rates.
- * This function is no longer required as FT_SetBaudRate will now
- * automatically calculate the required divisor for a requested baud rate.
- * @param ftHandle Handle of the device.
- * @param usDivisor Divisor.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetDivisor(int ftHandle, short usDivisor);
-
- /**
- * This function sets the data characteristics for the device.
- * @param ftHandle Handle of the device.
- * @param uWordLength Number of bits per word - must be FT_BITS_8 or
- * FT_BITS_7.
- * @param uStopBits Number of stop bits - must be FT_STOP_BITS_1 or
- * FT_STOP_BITS_2.
- * @param uParity Parity - must be FT_PARITY_NONE, FT_PARITY_ODD,
- * FT_PARITY_EVEN, FT_PARITY_MARK or FT_PARITY SPACE.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetDataCharacteristics(int ftHandle, byte uWordLength,
- byte uStopBits, byte uParity);
-
- /**
- * This function sets the read and write timeouts for the device.
- * @param ftHandle Handle of the device.
- * @param dwReadTimeout Read timeout in milliseconds.
- * @param dwWriteTimeout Write timeout in milliseconds.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetTimeouts(int ftHandle, int dwReadTimeout, int dwWriteTimeout);
-
- /**
- * This function sets the flow control for the device.
- * @param ftHandle Handle of the device.
- * @param usFlowControl Must be one of FT_FLOW_NONE, FT_FLOW_RTS_CTS,
- * FT_FLOW_DTR_DSR or FT_FLOW_XON_XOFF.
- * @param uXon Character used to signal Xon. Only used if flow control is
- * FT_FLOW_XON_XOFF.
- * @param uXoff Character used to signal Xoff. Only used if flow control is
- * FT_FLOW_XON_XOFF.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetFlowControl(int ftHandle, short usFlowControl, byte uXon,
- byte uXoff);
-
- /**
- * This function sets the Data Terminal Ready (DTR) control signal.
- * @param ftHandle Handle of the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetDtr(int ftHandle);
-
- /**
- * This function clears the Data Terminal Ready (DTR) control signal.
- * @param ftHandle Handle of the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_ClrDtr(int ftHandle);
-
- /**
- * This function sets the Request To Send (RTS) control signal.
- * @param ftHandle Handle of the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetRts(int ftHandle);
-
- /**
- * This function clears the Request To Send (RTS) control signal.
- * @param ftHandle Handle of the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_ClrRts(int ftHandle);
-
- /**
- * Gets the modem status and line status from the device.
- * @param ftHandle Handle of the device.
- * @param lpdwModemStatus Pointer to a variable of type DWORD which receives
- * the modem status and line status from the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_GetModemStatus(int ftHandle, IntByReference lpdwModemStatus);
-
- /**
- * Gets the number of bytes in the receive queue.
- * @param ftHandle Handle of the device.
- * @param lpdwAmountInRxQueue Pointer to a variable of type DWORD which
- * receives the number of bytes in the receive queue.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_GetQueueStatus(int ftHandle, IntByReference lpdwAmountInRxQueue);
-
- /**
- * Get device information for an open device.
- * @param ftHandle Handle of the device.
- * @param pftType Pointer to unsigned long to store device type.
- * @param lpdwID Pointer to unsigned long to store device ID.
- * @param pcSerialNumber Pointer to buffer to store device serial number as
- * a null-terminated string.
- * @param pcDescription Pointer to buffer to store device description as a
- * null-terminated string.
- * @param pvDummy Reserved for future use - should be set to NULL.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_GetDeviceInfo(int ftHandle, IntByReference pftType,
- IntByReference lpdwID, Pointer pcSerialNumber, Pointer pcDescription,
- Pointer pvDummy);
-
- /**
- * This function returns the D2XX driver version number.
- * @param ftHandle Handle of the device.
- * @param lpdwDriverVersion Pointer to the driver version number.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_GetDriverVersion(int ftHandle, IntByReference lpdwDriverVersion);
-
- /**
- * This function returns D2XX DLL version number.
- * @param lpdwDLLVersion Pointer to the DLL version number.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_GetLibraryVersion(IntByReference lpdwDLLVersion);
-
- /**
- * Retrieves the COM port associated with a device.
- * @param ftHandle Handle of the device.
- * @param lplComPortNumber Pointer to a variable of type LONG which receives
- * the COM port number associated with the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_GetComPortNumber(int ftHandle, IntByReference lplComPortNumber);
-
- /**
- * Gets the device status including number of characters in the receive
- * queue, number of characters in the transmit queue, and the current event
- * status.
- * @param ftHandle Handle of the device.
- * @param lpdwAmountInRxQueue Pointer to a variable of type DWORD which
- * receives the number of characters in the receive queue.
- * @param lpdwAmountInTxQueue Pointer to a variable of type DWORD which
- * receives the number of characters in the transmit queue.
- * @param lpdwEventStatus Pointer to a variable of type DWORD which receives
- * the current state of the event status.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_GetStatus(int ftHandle, IntByReference lpdwAmountInRxQueue,
- IntByReference lpdwAmountInTxQueue, IntByReference lpdwEventStatus);
-
- /**
- * Sets conditions for event notification.
- * @param ftHandle Handle of the device.
- * @param dwEventMask Conditions that cause the event to be set.
- * @param pvArg Interpreted as the handle of an event.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetEventNotification(int ftHandle, int dwEventMask, Pointer pvArg);
-
- /**
- * This function sets the special characters for the device.
- * @param ftHandle Handle of the device.
- * @param uEventCh Event character.
- * @param uEventChEn 0 if event character disabled, non-zero otherwise.
- * @param uErrorCh Error character.
- * @param uErrorChEn 0 if error character disabled, non-zero otherwise.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetChars(int ftHandle, byte uEventCh, byte uEventChEn,
- byte uErrorCh, byte uErrorChEn);
-
- /**
- * Sets the BREAK condition for the device.
- * @param ftHandle Handle of the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetBreakOn(int ftHandle);
-
- /**
- * Resets the BREAK condition for the device.
- * @param ftHandle Handle of the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetBreakOff(int ftHandle);
-
- /**
- * This function purges receive and transmit buffers in the device.
- * @param ftHandle Handle of the device.
- * @param dwMask Combination of FT_PURGE_RX and FT_PURGE_TX.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_Purge(int ftHandle, int dwMask);
-
- /**
- * This function sends a reset command to the device.
- * @param ftHandle Handle of the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_ResetDevice(int ftHandle);
-
- /**
- * Send a reset command to the port.
- * @param ftHandle Handle of the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_ResetPort(int ftHandle);
-
- /**
- * Send a cycle command to the USB port.
- * @param ftHandle Handle of the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_CyclePort(int ftHandle);
-
- /**
- * This function can be of use when trying to recover devices
- * programatically.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_Rescan();
-
- /**
- * This function forces a reload of the driver for devices with a specific
- * VID and PID combination.
- * @param wVID Vendor ID of the devices to reload the driver for.
- * @param wPID Product ID of the devices to reload the driver for.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_Reload(short wVID, short wPID);
-
- /**
- * Set the ResetPipeRetryCount value.
- * @param ftHandle Handle of the device.
- * @param dwCount Unsigned long containing required ResetPipeRetryCount.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetResetPipeRetryCount(int ftHandle, int dwCount);
-
- /**
- * Stops the driver's IN task.
- * @param ftHandle Handle of the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_StopInTask(int ftHandle);
-
- /**
- * Restart the driver's IN task.
- * @param ftHandle Handle of the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_RestartInTask(int ftHandle);
-
- /**
- * This function allows the maximum time in milliseconds that a USB request
- * can remain outstanding to be set.
- * @param ftHandle Handle of the device.
- * @param dwDeadmanTimeout Deadman timeout value in milliseconds.
- * Default value is 5000.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetDeadmanTimeout(int ftHandle, int dwDeadmanTimeout);
-
- /**
- * Read a value from an EEPROM location.
- * @param ftHandle Handle of the device.
- * @param dwWordOffset EEPROM location to read from.
- * @param lpwValue Pointer to the WORD value read from the EEPROM.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_ReadEE(int ftHandle, int dwWordOffset, ShortByReference lpwValue);
-
- /**
- * Write a value to an EEPROM location.
- * @param ftHandle Handle of the device.
- * @param dwWordOffset EEPROM location to read from.
- * @param wValue The WORD value write to the EEPROM.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_WriteEE(int ftHandle, int dwWordOffset, short wValue);
-
- /**
- * Erases the device EEPROM.
- * @param ftHandle Handle of the device.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_EraseEE(int ftHandle);
-
- /**
- * Read the contents of the EEPROM.
- * @param ftHandle Handle of the device.
- * @param pData Pointer to structure of type FT_PROGRAM_DATA.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_EE_Read(int ftHandle, FT_PROGRAM_DATA.ByReference pData);
-
- /**
- * Read the contents of the EEPROM and pass strings separately.
- * @param ftHandle Handle of the device.
- * @param pData Pointer to structure of type FT_PROGRAM_DATA.
- * @param Manufacturer Pointer to a null-terminated string containing the
- * manufacturer name.
- * @param ManufacturerId Pointer to a null-terminated string containing the
- * manufacturer ID.
- * @param Description Pointer to a null-terminated string containing the
- * device description.
- * @param SerialNumber Pointer to a null-terminated string containing the
- * device serial number.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_EE_ReadEx(int ftHandle, FT_PROGRAM_DATA.ByReference pData,
- String Manufacturer, String ManufacturerId, String Description,
- String SerialNumber);
-
- /**
- * Program the EEPROM.
- * @param ftHandle Handle of the device.
- * @param pData Pointer to structure of type FT_PROGRAM_DATA.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_EE_Program(int ftHandle, FT_PROGRAM_DATA.ByReference pData);
-
- /**
- * Program the EEPROM and pass strings separately.
- * @param ftHandle Handle of the device.
- * @param pData Pointer to structure of type FT_PROGRAM_DATA.
- * @param Manufacturer Pointer to a null-terminated string containing the
- * manufacturer name.
- * @param ManufacturerId Pointer to a null-terminated string containing the
- * manufacturer ID.
- * @param Description Pointer to a null-terminated string containing the
- * device description.
- * @param SerialNumber Pointer to a null-terminated string containing the
- * device serial number.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_EE_ProgramEx(int ftHandle, FT_PROGRAM_DATA.ByReference pData,
- String Manufacturer, String ManufacturerId,
- String Description, String SerialNumber);
-
- /**
- * Get the available size of the EEPROM user area.
- * @param ftHandle Handle of the device.
- * @param lpdwSize Pointer to a DWORD that receives the available size, in
- * bytes, of the EEPROM user area.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_EE_UASize(int ftHandle, IntByReference lpdwSize);
-
- /**
- * Read the contents of the EEPROM user area.
- * @param ftHandle Handle of the device.
- * @param pucData Pointer to a buffer that contains storage for data to be
- * read.
- * @param dwDataLen Size, in bytes, of buffer that contains storage for the
- * data to be read.
- * @param lpdwBytesRead Pointer to a DWORD that receives the number of bytes
- * read.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_EE_UARead(int ftHandle, Pointer pucData, int dwDataLen,
- IntByReference lpdwBytesRead);
-
- /**
- * Write data into the EEPROM user area.
- * @param ftHandle Handle of the device.
- * @param pucData Pointer to a buffer that contains the data to be written.
- * @param dwDataLen Size, in bytes, of buffer that contains storage for the
- * data to be read.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_EE_UAWrite(int ftHandle, Pointer pucData, int dwDataLen);
-
- /**
- * Set the latency timer value.
- * @param ftHandle Handle of the device.
- * @param ucTimer Required value, in milliseconds, of latency timer. Valid
- * range is 2 – 255.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetLatencyTimer(int ftHandle, byte ucTimer);
-
- /**
- * Get the current value of the latency timer.
- * @param ftHandle Handle of the device.
- * @param pucTimer Pointer to unsigned char to store latency timer value.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_GetLatencyTimer(int ftHandle, ByteByReference pucTimer);
-
- /**
- * Enables different chip modes.
- * @param ftHandle Handle of the device.
- * @param ucMask Required value for bit mode mask. This sets up which bits
- * are inputs and outputs. A bit value of 0 sets the corresponding pin to
- * an input, a bit value of 1 sets the corresponding pin to an output.
- * In the case of CBUS Bit Bang, the upper nibble of this value controls
- * which pins are inputs and outputs, while the lower nibble controls which
- * of the outputs are high and low.
- * @param ucMode Mode value. Can be one of the following:
- * 0x0 = Reset
- * 0x1 = Asynchronous Bit Bang
- * 0x2 = MPSSE (FT2232, FT2232H, FT4232H and FT232H devices only)
- * 0x4 = Synchronous Bit Bang (FT232R, FT245R, FT2232, FT2232H, FT4232H and
- * FT232H devices only)
- * 0x8 = MCU Host Bus Emulation Mode (FT2232, FT2232H, FT4232H and FT232H
- * devices only)
- * 0x10 = Fast Opto-Isolated Serial Mode (FT2232, FT2232H, FT4232H and
- * FT232H devices only)
- * 0x20 = CBUS Bit Bang Mode (FT232R and FT232H devices only)
- * 0x40 = Single Channel Synchronous 245 FIFO Mode (FT2232H and FT232H
- * devices only)
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetBitMode(int ftHandle, byte ucMask, byte ucMode);
-
- /**
- * Gets the instantaneous value of the data bus.
- * @param ftHandle Handle of the device.
- * @param pucMode Pointer to unsigned char to store the instantaneous data
- * bus value.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_GetBitmode(int ftHandle, ByteByReference pucMode);
-
- /**
- * Set the USB request transfer size.
- * @param ftHandle Handle of the device.
- * @param dwInTransferSize Transfer size for USB IN request.
- * @param dwOutTransferSize Transfer size for USB OUT request.
- * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
- * FT error code.
- */
- int FT_SetUSBParameters(int ftHandle, int dwInTransferSize,
- int dwOutTransferSize);
-}
+/*
+ * The MIT License
+ *
+ * Copyright 2011 Peter Kocsis .
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.ftdi;
+
+import com.sun.jna.Library;
+import com.sun.jna.Memory;
+import com.sun.jna.Native;
+import com.sun.jna.Platform;
+import com.sun.jna.Pointer;
+import com.sun.jna.Structure;
+import com.sun.jna.ptr.ByteByReference;
+import com.sun.jna.ptr.IntByReference;
+import com.sun.jna.ptr.PointerByReference;
+import com.sun.jna.ptr.ShortByReference;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author Peter Kocsis
+ */
+public interface FTD2XX extends Library {
+
+ static class Loader {
+
+ private Loader() {
+ }
+
+ static String getNative() {
+ InputStream in = null;
+ FileOutputStream fos = null;
+ File fileOut = null;
+ String fromStream = null;
+ System.setProperty("jna.library.path", System.getProperty("java.io.tmpdir"));
+ Logger.getLogger(FTD2XX.class.getName()).log(Level.INFO,
+ "JNA Library Path is: {0}", System.getProperty("jna.library.path"));
+
+ if (Platform.isMac()) {
+ fromStream = "/natives/libftd2xx.dylib";
+ } else if (Platform.is64Bit()) {
+ if (Platform.isLinux()) {
+ fromStream = "/natives/x86_64/libftd2xx.so";
+ } else if (Platform.isWindows()) {
+ fromStream = "/natives/x86_64/ftd2xx.dll";
+ }
+ } else {
+ if (System.getProperty("os.arch").toLowerCase().trim().startsWith("arm")) {
+ if (new File("/lib/arm-linux-gnueabihf").exists()) {
+ fromStream = "/natives/arm926hf/libftd2xx.so";
+ } else {
+ // TODO: Soft Float ARM has not yet been tested. The native
+ // libjnidispatch.so file inside of lib/jna-3.2.7.jar file
+ // may need to be replaced by the /usr/lib/jni/libjnidispatch.so
+ // file created by running "apt-get install libjna-java".
+ fromStream = "/natives/arm926/libftd2xx.so";
+ }
+ } else if (Platform.isLinux()) {
+ fromStream = "/natives/i386/libftd2xx.so";
+ } else if (Platform.isWindows()) {
+ fromStream = "/natives/i386/ftd2xx.dll";
+ }
+ }
+
+ if (fromStream == null) {
+ throw new Error("Not supported OS.");
+ } else {
+ try {
+ fileOut = new File(System.getProperty("java.io.tmpdir") +
+ (!Platform.isWindows() ? "/lib" : "\\")
+ + "ftd2xx" + (Platform.isWindows() ? ".dll"
+ : Platform.isLinux() ? ".so" : ".dylib"));
+ fileOut.deleteOnExit();
+
+ Logger.getLogger(FTD2XX.class.getName()).log(Level.INFO,
+ "Copying native library from lib/JavaFTD2XX-0.2.10.jar:{0} to {1}",
+ new Object[]{fromStream, fileOut});
+
+ in = Loader.class.getResourceAsStream(fromStream);
+ fos = new FileOutputStream(fileOut);
+
+ int count;
+ byte[] buf = new byte[1024];
+
+ while ((count = in.read(buf, 0, buf.length)) > 0) {
+ fos.write(buf, 0, count);
+ }
+
+ } catch (IOException ex) {
+ throw new Error("Failed to create temporary file "
+ + "for d2xx library: " + ex);
+ } finally {
+ try {
+ in.close();
+ } catch (IOException ex) {
+ }
+
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException ex) {
+ }
+ }
+
+ String res;
+ if (Platform.isMac()) {
+ StringTokenizer st = new StringTokenizer(
+ fileOut.getName(), ".");
+ res = st.nextToken().substring(3);
+ } else {
+ res = fileOut.getName();
+ }
+ return res;
+ }
+ }
+ }
+ }
+ final FTD2XX INSTANCE = (FTD2XX) Native.loadLibrary(
+ Loader.getNative(), FTD2XX.class);
+
+ public final static int FT_FLAGS_OPENED = 0x00000001;
+ public final static int FT_FLAGS_HISPEED = 0x00000002;
+ public final static int FT_LIST_NUMBER_ONLY = 0x80000,
+ FT_LIST_BY_INDEX = 0x40000000,
+ FT_LIST_ALL = 0x20000000;
+
+ public final static int FT_OPEN_BY_SERIAL_NUMBER = 1,
+ FT_OPEN_BY_DESCRIPTION = 2,
+ FT_OPEN_BY_LOCATION = 4;
+
+ public static class NotificationEvents {
+
+ public final static int FT_EVENT_RXCHAR = 1,
+ FT_EVENT_MODEM_STATUS = 2,
+ FT_EVENT_LINE_STATUS = 4;
+ }
+
+ public static class FT_DEVICE_LIST_INFO_NODE extends Structure {
+
+ public int Flags;
+ public int Type;
+ public int ID;
+ public int LocId;
+ public Memory SerialNumber = new Memory(16);
+ public Memory Description = new Memory(64);
+ public Pointer ftHandle;
+
+ @Override
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "Flags", "Type", "ID", "LocId", "SerialNumber", "Description", "ftHandle" });
+ }
+ }
+
+ public static class FT_PROGRAM_DATA extends Structure {
+
+ public static class ByReference extends FT_PROGRAM_DATA
+ implements Structure.ByReference {
+ }
+ /**
+ * Header - must be 0x0000000
+ */
+ public int Signature1 = 0x0000000;
+ /**
+ * Header - must be 0xffffffff
+ */
+ public int Signature2 = 0xffffffff;
+ /**
+ * // Header - FT_PROGRAM_DATA version
+ * 0 = original (FT232B)
+ * 1 = FT2232 extensions
+ * 2 = FT232R extensions
+ * 3 = FT2232H extensions
+ * 4 = FT4232H extensions
+ * 5 = FT232H extensions
+ */
+ public int Version = 0x00000000;
+ /**
+ * 0x0403
+ */
+ public short VendorId;
+ /**
+ * 0x6001
+ */
+ public short ProductId;
+ /**
+ * "FTDI"
+ */
+ public Pointer Manufacturer = new Memory(32);
+ /**
+ * "FT"
+ */
+ public Pointer ManufacturerId = new Memory(16);
+ /**
+ * "USB HS Serial Converter"
+ */
+ public Pointer Description = new Memory(64);
+ /**
+ * "FT000001" if fixed, or NULL
+ */
+ public Pointer SerialNumber = new Memory(16);
+ /**
+ * 0 < MaxPower <= 500
+ */
+ public short MaxPower;
+ /**
+ * 0 = disabled, 1 = enabled
+ */
+ public short PnP;
+ /**
+ * 0 = bus powered, 1 = self powered
+ */
+ public short SelfPowered;
+ /**
+ * 0 = not capable, 1 = capable
+ */
+ public short RemoteWakeup;
+//
+// Rev4 (FT232B) extensions
+//
+ /**
+ * non-zero if Rev4 chip, zero otherwise
+ */
+ public byte Rev4;
+ /**
+ * non-zero if in endpoint is isochronous
+ */
+ public byte IsoIn;
+ /**
+ * non-zero if out endpoint is isochronous
+ */
+ public byte IsoOut;
+ /**
+ * non-zero if pull down enabled
+ */
+ public byte PullDownEnable;
+ /**
+ * non-zero if serial number to be used
+ */
+ public byte SerNumEnable;
+ /**
+ * non-zero if chip uses USBVersion
+ */
+ public byte USBVersionEnable;
+ /**
+ * BCD (0x0200 => USB2)
+ */
+ public short USBVersion;
+//
+// Rev 5 (FT2232) extensions
+//
+ /**
+ * non-zero if Rev5 chip, zero otherwise
+ */
+ public byte Rev5;
+ /**
+ * non-zero if in endpoint is isochronous
+ */
+ public byte IsoInA;
+ /**
+ * non-zero if in endpoint is isochronous
+ */
+ public byte IsoInB;
+ /**
+ * non-zero if out endpoint is isochronous
+ */
+ public byte IsoOutA;
+ /**
+ * non-zero if out endpoint is isochronous
+ */
+ public byte IsoOutB;
+ /**
+ * non-zero if pull down enabled
+ */
+ public byte PullDownEnable5;
+ /**
+ * non-zero if serial number to be used
+ */
+ public byte SerNumEnable5;
+ /**
+ * non-zero if chip uses USBVersion
+ */
+ public byte USBVersionEnable5;
+ /**
+ * BCD (0x0200 => USB2)
+ */
+ public short USBVersion5;
+ /**
+ * non-zero if interface is high current
+ */
+ public byte AIsHighCurrent;
+ /**
+ * non-zero if interface is high current
+ */
+ public byte BIsHighCurrent;
+ /**
+ * non-zero if interface is 245 FIFO
+ */
+ public byte IFAIsFifo;
+ /**
+ * non-zero if interface is 245 FIFO CPU target
+ */
+ public byte IFAIsFifoTar;
+ /**
+ * non-zero if interface is Fast serial
+ */
+ public byte IFAIsFastSer;
+ /**
+ * non-zero if interface is to use VCP drivers
+ */
+ public byte AIsVCP;
+ /**
+ * non-zero if interface is 245 FIFO
+ */
+ public byte IFBIsFifo;
+ /**
+ * non-zero if interface is 245 FIFO CPU target
+ */
+ public byte IFBIsFifoTar;
+ /**
+ * non-zero if interface is Fast serial
+ */
+ public byte IFBIsFastSer;
+ /**
+ * non-zero if interface is to use VCP drivers
+ */
+ public byte BIsVCP;
+//
+// Rev 6 (FT232R) extensions
+//
+ /**
+ * Use External Oscillator
+ */
+ public byte UseExtOsc;
+ /**
+ * High Drive I/Os
+ */
+ public byte HighDriveIOs;
+ /**
+ * Endpoint size
+ */
+ public byte EndpointSize;
+ /**
+ * non-zero if pull down enabled
+ */
+ public byte PullDownEnableR;
+ /**
+ * non-zero if serial number to be used
+ */
+ public byte SerNumEnableR;
+ /**
+ * non-zero if invert TXD
+ */
+ public byte InvertTXD;
+ /**
+ * non-zero if invert RXD
+ */
+ public byte InvertRXD;
+ /**
+ * non-zero if invert RTS
+ */
+ public byte InvertRTS;
+ /**
+ * non-zero if invert CTS
+ */
+ public byte InvertCTS;
+ /**
+ * non-zero if invert DTR
+ */
+ public byte InvertDTR;
+ /**
+ * non-zero if invert DSR
+ */
+ public byte InvertDSR;
+ /**
+ * non-zero if invert DCD
+ */
+ public byte InvertDCD;
+ /**
+ * non-zero if invert RI
+ */
+ public byte InvertRI;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus0;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus1;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus2;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus3;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus4;
+ /**
+ * non-zero if using D2XX driver
+ */
+ public byte RIsD2XX;
+ //
+// Rev 7 (FT2232H) Extensions
+//
+ /**
+ * non-zero if pull down enabled
+ */
+ public byte PullDownEnable7;
+ /**
+ * non-zero if serial number to be used
+ */
+ public byte SerNumEnable7;
+ /**
+ * non-zero if AL pins have slow slew
+ */
+ public byte ALSlowSlew;
+ /**
+ * non-zero if AL pins are Schmitt input
+ */
+ public byte ALSchmittInput;
+ /**
+ * valid values are 4mA, 8mA, 12mA, 16mA
+ */
+ public byte ALDriveCurrent;
+ /**
+ * non-zero if AH pins have slow slew
+ */
+ public byte AHSlowSlew;
+ /**
+ * non-zero if AH pins are Schmitt input
+ */
+ public byte AHSchmittInput;
+ /**
+ * valid values are 4mA, 8mA, 12mA, 16mA
+ */
+ public byte AHDriveCurrent;
+ /**
+ * non-zero if BL pins have slow slew
+ */
+ public byte BLSlowSlew;
+ /**
+ * non-zero if BL pins are Schmitt input
+ */
+ public byte BLSchmittInput;
+ /**
+ * valid values are 4mA, 8mA, 12mA, 16mA
+ */
+ public byte BLDriveCurrent;
+ /**
+ * non-zero if BH pins have slow slew
+ */
+ public byte BHSlowSlew;
+ /**
+ * non-zero if BH pins are Schmitt input
+ */
+ public byte BHSchmittInput;
+ /**
+ * valid values are 4mA, 8mA, 12mA, 16mA
+ */
+ public byte BHDriveCurrent;
+ /**
+ * non-zero if interface is 245 FIFO
+ */
+ public byte IFAIsFifo7;
+ /**
+ * non-zero if interface is 245 FIFO CPU target
+ */
+ public byte IFAIsFifoTar7;
+ /**
+ * non-zero if interface is Fast serial
+ */
+ public byte IFAIsFastSer7;
+ /**
+ * non-zero if interface is to use VCP drivers
+ */
+ public byte AIsVCP7;
+ /**
+ * non-zero if interface is 245 FIFO
+ */
+ public byte IFBIsFifo7;
+ /**
+ * non-zero if interface is 245 FIFO CPU target
+ */
+ public byte IFBIsFifoTar7;
+ /**
+ * non-zero if interface is Fast serial
+ */
+ public byte IFBIsFastSer7;
+ /**
+ * non-zero if interface is to use VCP drivers
+ */
+ public byte BIsVCP7;
+ /**
+ * non-zero if using BCBUS7 to save power for self-powered designs
+ */
+ public byte PowerSaveEnable;
+//
+// Rev 8 (FT4232H) Extensions
+//
+ /**
+ * non-zero if pull down enabled
+ */
+ public byte PullDownEnable8;
+ /**
+ * non-zero if serial number to be used
+ */
+ public byte SerNumEnable8;
+ /**
+ * non-zero if AL pins have slow slew
+ */
+ public byte ASlowSlew;
+ /**
+ * non-zero if AL pins are Schmitt input
+ */
+ public byte ASchmittInput;
+ /**
+ * valid values are 4mA, 8mA, 12mA, 16mA
+ */
+ public byte ADriveCurrent;
+ /**
+ * non-zero if AH pins have slow slew
+ */
+ public byte BSlowSlew;
+ /**
+ * non-zero if AH pins are Schmitt input
+ */
+ public byte BSchmittInput;
+ /**
+ * valid values are 4mA, 8mA, 12mA, 16mA
+ */
+ public byte BDriveCurrent;
+ /**
+ * non-zero if BL pins have slow slew
+ */
+ public byte CSlowSlew;
+ /**
+ * non-zero if BL pins are Schmitt input
+ */
+ public byte CSchmittInput;
+ /**
+ * valid values are 4mA, 8mA, 12mA, 16mA
+ */
+ public byte CDriveCurrent;
+ /**
+ * non-zero if BH pins have slow slew
+ */
+ public byte DSlowSlew;
+ /**
+ * non-zero if BH pins are Schmitt input
+ */
+ public byte DSchmittInput;
+ /**
+ * valid values are 4mA, 8mA, 12mA, 16mA
+ */
+ public byte DDriveCurrent;
+ /**
+ * non-zero if port A uses RI as RS485 TXDEN
+ */
+ public byte ARIIsTXDEN;
+ /**
+ * non-zero if port B uses RI as RS485 TXDEN
+ */
+ public byte BRIIsTXDEN;
+ /**
+ * non-zero if port C uses RI as RS485 TXDEN
+ */
+ public byte CRIIsTXDEN;
+ /**
+ * non-zero if port D uses RI as RS485 TXDEN
+ */
+ public byte DRIIsTXDEN;
+ /**
+ * non-zero if interface is to use VCP drivers
+ */
+ public byte AIsVCP8;
+ /**
+ * non-zero if interface is to use VCP drivers
+ */
+ public byte BIsVCP8;
+ /**
+ * non-zero if interface is to use VCP drivers
+ */
+ public byte CIsVCP8;
+ /**
+ * non-zero if interface is to use VCP drivers
+ */
+ public byte DIsVCP8;
+//
+// Rev 9 (FT232H) Extensions
+//
+ /**
+ * non-zero if pull down enabled
+ */
+ public byte PullDownEnableH;
+ /**
+ * non-zero if serial number to be used
+ */
+ public byte SerNumEnableH;
+ /**
+ * non-zero if AC pins have slow slew
+ */
+ public byte ACSlowSlewH;
+ /**
+ * non-zero if AC pins are Schmitt input
+ */
+ public byte ACSchmittInputH;
+ /**
+ * valid values are 4mA, 8mA, 12mA, 16mA
+ */
+ public byte ACDriveCurrentH;
+ /**
+ * non-zero if AD pins have slow slew
+ */
+ public byte ADSlowSlewH;
+ /**
+ * non-zero if AD pins are Schmitt input
+ */
+ public byte ADSchmittInputH;
+ /**
+ * valid values are 4mA, 8mA, 12mA, 16mA
+ */
+ public byte ADDriveCurrentH;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus0H;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus1H;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus2H;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus3H;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus4H;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus5H;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus6H;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus7H;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus8H;
+ /**
+ * Cbus Mux control
+ */
+ public byte Cbus9H;
+ /**
+ * non-zero if interface is 245 FIFO
+ */
+ public byte IsFifoH;
+ /**
+ * non-zero if interface is 245 FIFO CPU target
+ */
+ public byte IsFifoTarH;
+ /**
+ * non-zero if interface is Fast serial
+ */
+ public byte IsFastSerH;
+ /**
+ * non-zero if interface is FT1248
+ */
+ public byte IsFT1248H;
+ /**
+ * FT1248 clock polarity - clock idle high (1) or clock idle low (0)
+ */
+ public byte FT1248CpolH;
+ /**
+ * FT1248 data is LSB (1) or MSB (0)
+ */
+ public byte FT1248LsbH;
+ /**
+ * FT1248 flow control enable
+ */
+ public byte FT1248FlowControlH;
+ /**
+ * non-zero if interface is to use VCP drivers
+ */
+ public byte IsVCPH;
+ /**
+ * non-zero if using ACBUS7 to save power for self-powered designs
+ */
+ public byte PowerSaveEnableH;
+
+ @Override
+ protected List getFieldOrder() {
+ return Arrays.asList(new String[] { "Signature1", "Signature2", "Version", "VendorId", "ProductId", "Manufacturer", "ManufacturerId", "Description", "SerialNumber", "MaxPower", "PnP", "SelfPowered", "RemoteWakeup", "Rev4", "IsoIn", "IsoOut", "PullDownEnable", "SerNumEnable", "USBVersionEnable", "USBVersion", "Rev5", "IsoInA", "IsoInB", "IsoOutA", "IsoOutB", "PullDownEnable5", "SerNumEnable5", "USBVersionEnable5", "USBVersion5", "AIsHighCurrent", "BIsHighCurrent", "IFAIsFifo", "IFAIsFifoTar", "IFAIsFastSer", "AIsVCP", "IFBIsFifo", "IFBIsFifoTar", "IFBIsFastSer", "BIsVCP", "UseExtOsc", "HighDriveIOs", "EndpointSize", "PullDownEnableR", "SerNumEnableR", "InvertTXD", "InvertRXD", "InvertRTS", "InvertCTS", "InvertDTR", "InvertDSR", "InvertDCD", "InvertRI", "Cbus0", "Cbus1", "Cbus2", "Cbus3", "Cbus4", "RIsD2XX", "PullDownEnable7", "SerNumEnable7", "ALSlowSlew", "ALSchmittInput", "ALDriveCurrent", "AHSlowSlew", "AHSchmittInput", "AHDriveCurrent", "BLSlowSlew", "BLSchmittInput", "BLDriveCurrent", "BHSlowSlew", "BHSchmittInput", "BHDriveCurrent", "IFAIsFifo7", "IFAIsFifoTar7", "IFAIsFastSer7", "AIsVCP7", "IFBIsFifo7", "IFBIsFifoTar7", "IFBIsFastSer7", "BIsVCP7", "PowerSaveEnable", "PullDownEnable8", "SerNumEnable8", "ASlowSlew", "ASchmittInput", "ADriveCurrent", "BSlowSlew", "BSchmittInput", "BDriveCurrent", "CSlowSlew", "CSchmittInput", "CDriveCurrent", "DSlowSlew", "DSchmittInput", "DDriveCurrent", "ARIIsTXDEN", "BRIIsTXDEN", "CRIIsTXDEN", "DRIIsTXDEN", "AIsVCP8", "BIsVCP8", "CIsVCP8", "DIsVCP8", "PullDownEnableH", "SerNumEnableH", "ACSlowSlewH", "ACSchmittInputH", "ACDriveCurrentH", "ADSlowSlewH", "ADSchmittInputH", "ADDriveCurrentH", "Cbus0H", "Cbus1H", "Cbus2H", "Cbus3H", "Cbus4H", "Cbus5H", "Cbus6H", "Cbus7H", "Cbus8H", "Cbus9H", "IsFifoH", "IsFifoTarH", "IsFastSerH", "IsFT1248H", "FT1248CpolH", "FT1248LsbH", "FT1248FlowControlH", "IsVCPH", "PowerSaveEnableH" });
+ }
+
+ }
+
+ /**
+ * A command to include a custom VID and PID combination within the internal
+ * device list table. This will allow the driver to load for the specified
+ * VID and PID combination.
+ * @param dwVID Device Vendor ID (VID)
+ * @param dwPID Device Product ID (PID)
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetVIDPID(int dwVID, int dwPID);
+
+ /**
+ * A command to retrieve the current VID and PID combination from within the
+ * internal device list table.
+ * @param pdwVID Pointer to DWORD(int) that will contain the internal VID
+ * @param pdwPID Pointer to DWORD(int) that will contain the internal PID
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_GetVIDPID(IntByReference pdwVID, IntByReference pdwPID);
+
+ /**
+ * This function builds a device information list and returns the number of
+ * D2XX devices connected to the system. The list contains information
+ * about both unopen and open devices.
+ * @param lpdwNumDevs Pointer to unsigned long(long) to store the number of
+ * devices connected.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_CreateDeviceInfoList(IntByReference lpdwNumDevs);
+
+ /**
+ * This function returns an entry from the device information list.
+ * @param pDest Pointer to an array of FT_DEVICE_LIST_INFO_NODE structures.
+ * @param lpdwNumDevs Pointer to the number of elements in the array
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_GetDeviceInfoList(FT_DEVICE_LIST_INFO_NODE[] pDest,
+ IntByReference lpdwNumDevs);
+
+ /**
+ * This function returns an entry from the device information list.
+ * @param dwIndex Index of the entry in the device info list.
+ * @param lpdwFlags Pointer to unsigned long to store the flag value.
+ * @param lpdwType Pointer to unsigned long to store device type.
+ * @param lpdwID Pointer to unsigned long to store device ID.
+ * @param lpdwLocId Pointer to unsigned long to store the device location ID.
+ * @param pcSerialNumber Pointer to buffer to store device serial number as
+ * a nullterminated string.
+ * @param pcDescription Pointer to buffer to store device description as a
+ * null-terminated string.
+ * @param ftHandle Pointer to a variable of type FT_HANDLE where the handle
+ * will be stored.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_GetDeviceInfoDetail(int dwIndex, IntByReference lpdwFlags,
+ IntByReference lpdwType, IntByReference lpdwID,
+ IntByReference lpdwLocId, Pointer pcSerialNumber,
+ Pointer pcDescription, PointerByReference ftHandle);
+
+ /**
+ * Gets information concerning the devices currently connected. This
+ * function can return information such as the number of devices connected,
+ * the device serial number and device description strings, and the
+ * location IDs of connected devices.
+ * @param pvArg1 Meaning depends on dwFlags
+ * @param pvArg2 Meaning depends on dwFlags
+ * @param dwFlags Determines format of returned information.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_ListDevices(Pointer pvArg1, Pointer pvArg2, int dwFlags);
+
+ /**
+ * Open the device and return a handle which will be used for subsequent
+ * accesses.
+ * @param iDevice Index of the device to open. Indices are 0 based.
+ * @param ftHandle Pointer to a variable of type FT_HANDLE where the handle
+ * will be stored. This handle must be used to access the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_Open(int iDevice, PointerByReference ftHandle);
+
+ /**
+ * Open the specified device and return a handle that will be used for
+ * subsequent accesses. The device can be specified by its serial number,
+ * device description or location. This function can also be used to open
+ * multiple devices simultaneously. Multiple devices can be specified by
+ * serial number, device description or location ID (location information
+ * derived from the physical location of a device on USB). Location IDs for
+ * specific USB ports can be obtained using the utility USBView and are
+ * given in hexadecimal format. Location IDs for devices connected to a
+ * system can be obtained by calling FT_GetDeviceInfoList or FT_ListDevices
+ * with the appropriate flags.
+ * @param pvArg1 Pointer to an argument whose type depends on the value of
+ * dwFlags. It is normally be interpreted as a pointer to a null
+ * terminated string.
+ * @param dwFlags FT_OPEN_BY_SERIAL_NUMBER, FT_OPEN_BY_DESCRIPTION or
+ * FT_OPEN_BY_LOCATION.
+ * @param ftHandle Pointer to a variable of type FT_HANDLE where the handle
+ * will be stored. This handle must be used to access the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_OpenEx(Pointer pvArg1, int dwFlags, PointerByReference ftHandle);
+
+ /**
+ * Close an open device.
+ * @param ftHandle Handle of the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_Close(Pointer ftHandle);
+
+ /**
+ * Read data from the device.
+ * @param ftHandle Handle of the device.
+ * @param lpBuffer Pointer to the buffer that receives the data from the
+ * device.
+ * @param dwBytesToRead Number of bytes to be read from the device.
+ * @param lpdwBytesReturned Pointer to a variable of type DWORD which
+ * receives the number of bytes read from the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_Read(Pointer ftHandle, Pointer lpBuffer, int dwBytesToRead,
+ IntByReference lpdwBytesReturned);
+
+ /**
+ * Write data to the device.
+ * @param ftHandle Handle of the device.
+ * @param lpBuffer Pointer to the buffer that contains the data to be
+ * written to the device.
+ * @param dwBytesToWrite Number of bytes to write to the device.
+ * @param lpdwBytesWritten Pointer to a variable of type DWORD which
+ * receives the number of bytes written to the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_Write(Pointer ftHandle, Pointer lpBuffer, int dwBytesToWrite,
+ IntByReference lpdwBytesWritten);
+
+ int FT_IoCtl(Pointer ftHandle, int dwIoControlCode, Pointer lpInBuf, int nInBufSize, Pointer lpOutBuf, int nOutBufSize,
+ IntByReference lpBytesReturned, IntByReference lpOverlapped);
+
+ /**
+ * This function sets the baud rate for the device.
+ * @param ftHandle Handle of the device.
+ * @param dwBaudRate Baud rate.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetBaudRate(Pointer ftHandle, int dwBaudRate);
+
+ /**
+ * This function sets the baud rate for the device. It is used to set
+ * non-standard baud rates.
+ * This function is no longer required as FT_SetBaudRate will now
+ * automatically calculate the required divisor for a requested baud rate.
+ * @param ftHandle Handle of the device.
+ * @param usDivisor Divisor.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetDivisor(Pointer ftHandle, short usDivisor);
+
+ /**
+ * This function sets the data characteristics for the device.
+ * @param ftHandle Handle of the device.
+ * @param uWordLength Number of bits per word - must be FT_BITS_8 or
+ * FT_BITS_7.
+ * @param uStopBits Number of stop bits - must be FT_STOP_BITS_1 or
+ * FT_STOP_BITS_2.
+ * @param uParity Parity - must be FT_PARITY_NONE, FT_PARITY_ODD,
+ * FT_PARITY_EVEN, FT_PARITY_MARK or FT_PARITY SPACE.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetDataCharacteristics(Pointer ftHandle, byte uWordLength,
+ byte uStopBits, byte uParity);
+
+ /**
+ * This function sets the read and write timeouts for the device.
+ * @param ftHandle Handle of the device.
+ * @param dwReadTimeout Read timeout in milliseconds.
+ * @param dwWriteTimeout Write timeout in milliseconds.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetTimeouts(Pointer ftHandle, int dwReadTimeout, int dwWriteTimeout);
+
+ /**
+ * This function sets the flow control for the device.
+ * @param ftHandle Handle of the device.
+ * @param usFlowControl Must be one of FT_FLOW_NONE, FT_FLOW_RTS_CTS,
+ * FT_FLOW_DTR_DSR or FT_FLOW_XON_XOFF.
+ * @param uXon Character used to signal Xon. Only used if flow control is
+ * FT_FLOW_XON_XOFF.
+ * @param uXoff Character used to signal Xoff. Only used if flow control is
+ * FT_FLOW_XON_XOFF.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetFlowControl(Pointer ftHandle, short usFlowControl, byte uXon,
+ byte uXoff);
+
+ /**
+ * This function sets the Data Terminal Ready (DTR) control signal.
+ * @param ftHandle Handle of the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetDtr(Pointer ftHandle);
+
+ /**
+ * This function clears the Data Terminal Ready (DTR) control signal.
+ * @param ftHandle Handle of the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_ClrDtr(Pointer ftHandle);
+
+ /**
+ * This function sets the Request To Send (RTS) control signal.
+ * @param ftHandle Handle of the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetRts(Pointer ftHandle);
+
+ /**
+ * This function clears the Request To Send (RTS) control signal.
+ * @param ftHandle Handle of the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_ClrRts(Pointer ftHandle);
+
+ /**
+ * Gets the modem status and line status from the device.
+ * @param ftHandle Handle of the device.
+ * @param lpdwModemStatus Pointer to a variable of type DWORD which receives
+ * the modem status and line status from the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_GetModemStatus(Pointer ftHandle, IntByReference lpdwModemStatus);
+
+ /**
+ * Gets the number of bytes in the receive queue.
+ * @param ftHandle Handle of the device.
+ * @param lpdwAmountInRxQueue Pointer to a variable of type DWORD which
+ * receives the number of bytes in the receive queue.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_GetQueueStatus(Pointer ftHandle, IntByReference lpdwAmountInRxQueue);
+
+ /**
+ * Get device information for an open device.
+ * @param ftHandle Handle of the device.
+ * @param pftType Pointer to unsigned long to store device type.
+ * @param lpdwID Pointer to unsigned long to store device ID.
+ * @param pcSerialNumber Pointer to buffer to store device serial number as
+ * a null-terminated string.
+ * @param pcDescription Pointer to buffer to store device description as a
+ * null-terminated string.
+ * @param pvDummy Reserved for future use - should be set to NULL.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_GetDeviceInfo(Pointer ftHandle, IntByReference pftType,
+ IntByReference lpdwID, Pointer pcSerialNumber, Pointer pcDescription,
+ Pointer pvDummy);
+
+ int FT_GetDeviceLocId(Pointer ftHandle, IntByReference lpdwLocId);
+
+ /**
+ * This function returns the D2XX driver version number.
+ * @param ftHandle Handle of the device.
+ * @param lpdwDriverVersion Pointer to the driver version number.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_GetDriverVersion(Pointer ftHandle, IntByReference lpdwDriverVersion);
+
+ /**
+ * This function returns D2XX DLL version number.
+ * @param lpdwDLLVersion Pointer to the DLL version number.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_GetLibraryVersion(IntByReference lpdwDLLVersion);
+
+ /**
+ * Retrieves the COM port associated with a device.
+ * @param ftHandle Handle of the device.
+ * @param lplComPortNumber Pointer to a variable of type LONG which receives
+ * the COM port number associated with the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_GetComPortNumber(Pointer ftHandle, IntByReference lplComPortNumber);
+
+ /**
+ * Gets the device status including number of characters in the receive
+ * queue, number of characters in the transmit queue, and the current event
+ * status.
+ * @param ftHandle Handle of the device.
+ * @param lpdwAmountInRxQueue Pointer to a variable of type DWORD which
+ * receives the number of characters in the receive queue.
+ * @param lpdwAmountInTxQueue Pointer to a variable of type DWORD which
+ * receives the number of characters in the transmit queue.
+ * @param lpdwEventStatus Pointer to a variable of type DWORD which receives
+ * the current state of the event status.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_GetStatus(Pointer ftHandle, IntByReference lpdwAmountInRxQueue,
+ IntByReference lpdwAmountInTxQueue, IntByReference lpdwEventStatus);
+
+ /**
+ * Sets conditions for event notification.
+ * @param ftHandle Handle of the device.
+ * @param dwEventMask Conditions that cause the event to be set.
+ * @param pvArg Interpreted as the handle of an event.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetEventNotification(Pointer ftHandle, int dwEventMask, Pointer pvArg);
+
+ /**
+ * This function sets the special characters for the device.
+ * @param ftHandle Handle of the device.
+ * @param uEventCh Event character.
+ * @param uEventChEn 0 if event character disabled, non-zero otherwise.
+ * @param uErrorCh Error character.
+ * @param uErrorChEn 0 if error character disabled, non-zero otherwise.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetChars(Pointer ftHandle, byte uEventCh, byte uEventChEn,
+ byte uErrorCh, byte uErrorChEn);
+
+ /**
+ * Sets the BREAK condition for the device.
+ * @param ftHandle Handle of the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetBreakOn(Pointer ftHandle);
+
+ /**
+ * Resets the BREAK condition for the device.
+ * @param ftHandle Handle of the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetBreakOff(Pointer ftHandle);
+
+ int FT_SetWaitMask(Pointer ftHandle, int Mask);
+
+ int FT_WaitOnMask(Pointer ftHandle, IntByReference Mask);
+
+ int FT_GetEventStatus(Pointer ftHandle, IntByReference Mask);
+
+ /**
+ * This function purges receive and transmit buffers in the device.
+ * @param ftHandle Handle of the device.
+ * @param dwMask Combination of FT_PURGE_RX and FT_PURGE_TX.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_Purge(Pointer ftHandle, int dwMask);
+
+ /**
+ * This function sends a reset command to the device.
+ * @param ftHandle Handle of the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_ResetDevice(Pointer ftHandle);
+
+ /**
+ * Send a reset command to the port.
+ * @param ftHandle Handle of the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_ResetPort(Pointer ftHandle);
+
+ /**
+ * Send a cycle command to the USB port.
+ * @param ftHandle Handle of the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_CyclePort(Pointer ftHandle);
+
+ /**
+ * This function can be of use when trying to recover devices
+ * programatically.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_Rescan();
+
+ /**
+ * This function forces a reload of the driver for devices with a specific
+ * VID and PID combination.
+ * @param wVID Vendor ID of the devices to reload the driver for.
+ * @param wPID Product ID of the devices to reload the driver for.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_Reload(short wVID, short wPID);
+
+ /**
+ * Set the ResetPipeRetryCount value.
+ * @param ftHandle Handle of the device.
+ * @param dwCount Unsigned long containing required ResetPipeRetryCount.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetResetPipeRetryCount(Pointer ftHandle, int dwCount);
+
+ /**
+ * Stops the driver's IN task.
+ * @param ftHandle Handle of the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_StopInTask(Pointer ftHandle);
+
+ /**
+ * Restart the driver's IN task.
+ * @param ftHandle Handle of the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_RestartInTask(Pointer ftHandle);
+
+ /**
+ * This function allows the maximum time in milliseconds that a USB request
+ * can remain outstanding to be set.
+ * @param ftHandle Handle of the device.
+ * @param dwDeadmanTimeout Deadman timeout value in milliseconds.
+ * Default value is 5000.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetDeadmanTimeout(Pointer ftHandle, int dwDeadmanTimeout);
+
+ /**
+ * Read a value from an EEPROM location.
+ * @param ftHandle Handle of the device.
+ * @param dwWordOffset EEPROM location to read from.
+ * @param lpwValue Pointer to the WORD value read from the EEPROM.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_ReadEE(Pointer ftHandle, int dwWordOffset, ShortByReference lpwValue);
+
+ /**
+ * Write a value to an EEPROM location.
+ * @param ftHandle Handle of the device.
+ * @param dwWordOffset EEPROM location to read from.
+ * @param wValue The WORD value write to the EEPROM.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_WriteEE(Pointer ftHandle, int dwWordOffset, short wValue);
+
+ /**
+ * Erases the device EEPROM.
+ * @param ftHandle Handle of the device.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_EraseEE(Pointer ftHandle);
+
+ /**
+ * Read the contents of the EEPROM.
+ * @param ftHandle Handle of the device.
+ * @param pData Pointer to structure of type FT_PROGRAM_DATA.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_EE_Read(Pointer ftHandle, FT_PROGRAM_DATA.ByReference pData);
+
+ int FT_EE_ReadConfig(Pointer ftHandle, byte ucAddress, Pointer pucValue);
+
+ int FT_EE_WriteConfig(Pointer ftHandle, byte ucAddress, byte ucValue);
+
+ int FT_EE_ReadECC(Pointer ftHandle, byte ucOption, ShortByReference lpwValue);
+
+ int FT_GetQueueStatusEx(Pointer ftHandle, byte ucAddress, IntByReference dwRxBytes);
+
+ /**
+ * Read the contents of the EEPROM and pass strings separately.
+ * @param ftHandle Handle of the device.
+ * @param pData Pointer to structure of type FT_PROGRAM_DATA.
+ * @param Manufacturer Pointer to a null-terminated string containing the
+ * manufacturer name.
+ * @param ManufacturerId Pointer to a null-terminated string containing the
+ * manufacturer ID.
+ * @param Description Pointer to a null-terminated string containing the
+ * device description.
+ * @param SerialNumber Pointer to a null-terminated string containing the
+ * device serial number.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_EE_ReadEx(Pointer ftHandle, FT_PROGRAM_DATA.ByReference pData,
+ String Manufacturer, String ManufacturerId, String Description,
+ String SerialNumber);
+
+ /**
+ * Program the EEPROM.
+ * @param ftHandle Handle of the device.
+ * @param pData Pointer to structure of type FT_PROGRAM_DATA.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_EE_Program(Pointer ftHandle, FT_PROGRAM_DATA.ByReference pData);
+
+ /**
+ * Program the EEPROM and pass strings separately.
+ * @param ftHandle Handle of the device.
+ * @param pData Pointer to structure of type FT_PROGRAM_DATA.
+ * @param Manufacturer Pointer to a null-terminated string containing the
+ * manufacturer name.
+ * @param ManufacturerId Pointer to a null-terminated string containing the
+ * manufacturer ID.
+ * @param Description Pointer to a null-terminated string containing the
+ * device description.
+ * @param SerialNumber Pointer to a null-terminated string containing the
+ * device serial number.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_EE_ProgramEx(Pointer ftHandle, FT_PROGRAM_DATA.ByReference pData,
+ String Manufacturer, String ManufacturerId,
+ String Description, String SerialNumber);
+
+ /**
+ * Get the available size of the EEPROM user area.
+ * @param ftHandle Handle of the device.
+ * @param lpdwSize Pointer to a DWORD that receives the available size, in
+ * bytes, of the EEPROM user area.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_EE_UASize(Pointer ftHandle, IntByReference lpdwSize);
+
+ /**
+ * Read the contents of the EEPROM user area.
+ * @param ftHandle Handle of the device.
+ * @param pucData Pointer to a buffer that contains storage for data to be
+ * read.
+ * @param dwDataLen Size, in bytes, of buffer that contains storage for the
+ * data to be read.
+ * @param lpdwBytesRead Pointer to a DWORD that receives the number of bytes
+ * read.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_EE_UARead(Pointer ftHandle, Pointer pucData, int dwDataLen,
+ IntByReference lpdwBytesRead);
+
+ /**
+ * Write data into the EEPROM user area.
+ * @param ftHandle Handle of the device.
+ * @param pucData Pointer to a buffer that contains the data to be written.
+ * @param dwDataLen Size, in bytes, of buffer that contains storage for the
+ * data to be read.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_EE_UAWrite(Pointer ftHandle, Pointer pucData, int dwDataLen);
+
+ /**
+ * Read data from the EEPROM, this command will work for all existing FTDI chipset, and must be used for the FT-X series.
+ * @param ftHandle Handle of the device.
+ * @param eepromData Pointer to a buffer that contains the data to be read.
+ * @param eepromDataSize Size of the eepromData buffer that contains storage for the data to be read.
+ * @param Manufacturer Pointer to a null-terminated string containing the manufacturer name.
+ * @param ManufacturerId Pointer to a null-terminated string containing the manufacturer ID.
+ * @param Description Pointer to a null-terminated string containing the device description.
+ * @param SerialNumber Pointer to a null-terminated string containing the device serial number.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_EEPROM_Read(Pointer ftHandle, Pointer eepromData, int eepromDataSize,
+ String Manufacturer, String ManufacturerId, String Description,
+ String SerialNumber);
+
+ int FT_EEPROM_Program(Pointer ftHandle, Pointer eepromData, int eepromDataSize,
+ String Manufacturer, String ManufacturerId, String Description,
+ String SerialNumber);
+
+ /**
+ * Set the latency timer value.
+ * @param ftHandle Handle of the device.
+ * @param ucTimer Required value, in milliseconds, of latency timer. Valid
+ * range is 2 – 255.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetLatencyTimer(Pointer ftHandle, byte ucTimer);
+
+ /**
+ * Get the current value of the latency timer.
+ * @param ftHandle Handle of the device.
+ * @param pucTimer Pointer to unsigned char to store latency timer value.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_GetLatencyTimer(Pointer ftHandle, ByteByReference pucTimer);
+
+ /**
+ * Enables different chip modes.
+ * @param ftHandle Handle of the device.
+ * @param ucMask Required value for bit mode mask. This sets up which bits
+ * are inputs and outputs. A bit value of 0 sets the corresponding pin to
+ * an input, a bit value of 1 sets the corresponding pin to an output.
+ * In the case of CBUS Bit Bang, the upper nibble of this value controls
+ * which pins are inputs and outputs, while the lower nibble controls which
+ * of the outputs are high and low.
+ * @param ucMode Mode value. Can be one of the following:
+ * 0x0 = Reset
+ * 0x1 = Asynchronous Bit Bang
+ * 0x2 = MPSSE (FT2232, FT2232H, FT4232H and FT232H devices only)
+ * 0x4 = Synchronous Bit Bang (FT232R, FT245R, FT2232, FT2232H, FT4232H and
+ * FT232H devices only)
+ * 0x8 = MCU Host Bus Emulation Mode (FT2232, FT2232H, FT4232H and FT232H
+ * devices only)
+ * 0x10 = Fast Opto-Isolated Serial Mode (FT2232, FT2232H, FT4232H and
+ * FT232H devices only)
+ * 0x20 = CBUS Bit Bang Mode (FT232R and FT232H devices only)
+ * 0x40 = Single Channel Synchronous 245 FIFO Mode (FT2232H and FT232H
+ * devices only)
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetBitMode(Pointer ftHandle, byte ucMask, byte ucMode);
+
+ /**
+ * Gets the instantaneous value of the data bus.
+ * @param ftHandle Handle of the device.
+ * @param pucMode Pointer to unsigned char to store the instantaneous data
+ * bus value.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_GetBitmode(Pointer ftHandle, ByteByReference pucMode);
+
+ /**
+ * Set the USB request transfer size.
+ * @param ftHandle Handle of the device.
+ * @param dwInTransferSize Transfer size for USB IN request.
+ * @param dwOutTransferSize Transfer size for USB OUT request.
+ * @return FT_STATUS: FT_OK if successful, otherwise the return value is an
+ * FT error code.
+ */
+ int FT_SetUSBParameters(Pointer ftHandle, int dwInTransferSize,
+ int dwOutTransferSize);
+}
diff --git a/src/com/ftdi/FTDevice.java b/src/com/ftdi/FTDevice.java
index ad52076..01a1c44 100644
--- a/src/com/ftdi/FTDevice.java
+++ b/src/com/ftdi/FTDevice.java
@@ -1,753 +1,800 @@
-/*
- * The MIT License
- *
- * Copyright 2011 Peter Kocsis .
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.ftdi;
-
-import com.sun.jna.Memory;
-import com.sun.jna.ptr.ByteByReference;
-import com.sun.jna.ptr.IntByReference;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.EnumSet;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Java class to communicate easily to a FTDI device.
- * @author Peter Kocsis
- */
-public class FTDevice {
-
- static private final FTD2XX ftd2xx = FTD2XX.INSTANCE;
- private final int devID, devLocationID, flag;
- private final DeviceType devType;
- private int ftHandle;
- private final String devSerialNumber, devDescription;
- private FTDeviceInputStream fTDeviceInputStream = null;
- private FTDeviceOutputStream fTDeviceOutputStream = null;
-
- private FTDevice(DeviceType devType, int devID, int devLocationID,
- String devSerialNumber, String devDescription, int ftHandle,
- int flag) {
- this.devType = devType;
- this.devID = devID;
- this.devLocationID = devLocationID;
- this.devSerialNumber = devSerialNumber;
- this.devDescription = devDescription;
- this.ftHandle = ftHandle;
- this.flag = flag;
- }
-
- /**
- * Get device description.
- * @return device description
- */
- public String getDevDescription() {
- return devDescription;
- }
-
- /**
- * Get device ID.
- * @return device ID
- */
- public int getDevID() {
- return devID;
- }
-
- /**
- * Get device serial number.
- * @return device serial number
- */
- public String getDevSerialNumber() {
- return devSerialNumber;
- }
-
- /**
- * Get device type.
- * @return device type.
- */
- public DeviceType getDevType() {
- return devType;
- }
-
- /**
- * Get device location.
- * @return device location.
- */
- public int getDevLocationID() {
- return devLocationID;
- }
-
- /**
- * Get device flag.
- * @return flag.
- */
- public int getFlag() {
- return flag;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof FTDevice)) {
- return false;
- }
- FTDevice eq = (FTDevice) obj;
- return eq.ftHandle == this.ftHandle;
- }
-
- @Override
- public int hashCode() {
- int hash = 5;
- hash = 97 * hash + this.ftHandle;
- return hash;
- }
-
- @Override
- public String toString() {
- return "FTDevice{" + "devDescription=" + devDescription
- + ", devSerialNumber=" + devSerialNumber + '}';
- }
-
- private static void ensureFTStatus(int ftstatus) throws FTD2XXException {
- if (!(ftstatus == FT_STATUS.OK.constant())) {
- throw new FTD2XXException(ftstatus);
- }
- }
-
- private static FTDevice getXthDevice(int Xth) throws FTD2XXException {
- IntByReference flag = new IntByReference();
- IntByReference devType = new IntByReference();
- IntByReference devID = new IntByReference();
- IntByReference locID = new IntByReference();
- IntByReference ftHandle = new IntByReference();
- Memory devSerNum = new Memory(16);
- Memory devDesc = new Memory(64);
-
- ensureFTStatus(ftd2xx.FT_GetDeviceInfoDetail(Xth, flag, devType, devID,
- locID, devSerNum, devDesc, ftHandle));
-
- return new FTDevice(DeviceType.values()[devType.getValue()],
- devID.getValue(), locID.getValue(), devSerNum.getString(0),
- devDesc.getString(0), ftHandle.getValue(), flag.getValue());
- }
-
- /**
- * Get the connected FTDI devices. It will not contain opened devices.
- * @return List contain available FTDI devices.
- * @throws FTD2XXException If something goes wrong.
- */
- public static List getDevices() throws FTD2XXException {
- return getDevices(false);
- }
-
- /**
- * Get the connected FTDI devices.
- * @param isIncludeOpenedDevices Would you like to see opened devices?
- * @return List contain available FTDI devices.
- * @throws FTD2XXException If something goes wrong.
- */
- public static List getDevices(boolean isIncludeOpenedDevices)
- throws FTD2XXException {
- IntByReference devNum = new IntByReference();
-
- ensureFTStatus(ftd2xx.FT_CreateDeviceInfoList(devNum));
-
- ArrayList devs = new ArrayList(devNum.getValue());
-
- for (int i = 0; i < devNum.getValue(); i++) {
- FTDevice device = getXthDevice(i);
- //device is occupied?
- if (isIncludeOpenedDevices) {
- devs.add(device);
- } else {
- if ((device.flag & FTD2XX.FT_FLAGS_OPENED) == 0) {
- devs.add(device);
- }
- }
-
- }
-
- Logger.getLogger(FTDevice.class.getName()).log(Level.INFO,
- "Found devs: {0} (All:{1})",
- new Object[]{devs.size(), devNum.getValue()});
-
- return devs;
- }
-
- /**
- * Get the connected FTDI devices. It will not contain opened devices.
- * @param description Filtering option, exact match need.
- * @return List contain available FTDI devices.
- * @throws FTD2XXException If something goes wrong.
- */
- public static List getDevicesByDescription(String description)
- throws FTD2XXException {
- IntByReference devNum = new IntByReference();
-
- ensureFTStatus(ftd2xx.FT_CreateDeviceInfoList(devNum));
-
- ArrayList devs = new ArrayList(devNum.getValue());
-
- for (int i = 0; i < devNum.getValue(); i++) {
- FTDevice device = getXthDevice(i);
-
- if (((device.flag & FTD2XX.FT_FLAGS_OPENED) == 0)
- && description.equals(device.devDescription)) {
- devs.add(device);
- }
-
- }
-
- Logger.getLogger(FTDevice.class.getName()).log(Level.INFO,
- "Found devs: {0} (All:{1})",
- new Object[]{devs.size(), devNum.getValue()});
-
- return devs;
- }
-
- /**
- * Get the connected FTDI devices. It will not contain opened devices.
- * @param serialNumber Filtering option, exact match need.
- * @return List contain available FTDI devices.
- * @throws FTD2XXException If something goes wrong.
- */
- public static List getDevicesBySerialNumber(String serialNumber)
- throws FTD2XXException {
- IntByReference devNum = new IntByReference();
-
- ensureFTStatus(ftd2xx.FT_CreateDeviceInfoList(devNum));
-
- ArrayList devs = new ArrayList(devNum.getValue());
-
- for (int i = 0; i < devNum.getValue(); i++) {
- FTDevice device = getXthDevice(i);
-
- if (((device.getFlag() & FTD2XX.FT_FLAGS_OPENED) == 0)
- && serialNumber.equals(device.devSerialNumber)) {
- devs.add(device);
- }
-
- }
-
- Logger.getLogger(FTDevice.class.getName()).log(Level.INFO,
- "Found devs: {0} (All:{1})",
- new Object[]{devs.size(), devNum.getValue()});
-
- return devs;
- }
-
- /**
- * Get the connected FTDI devices. It will not contain opened devices.
- * @param deviceType Filtering option.
- * @return List contain available FTDI devices.
- * @throws FTD2XXException If something goes wrong.
- */
- public static List getDevicesByDeviceType(DeviceType deviceType)
- throws FTD2XXException {
- IntByReference devNum = new IntByReference();
-
- ensureFTStatus(ftd2xx.FT_CreateDeviceInfoList(devNum));
-
- ArrayList devs = new ArrayList(devNum.getValue());
-
- for (int i = 0; i < devNum.getValue(); i++) {
- FTDevice device = getXthDevice(i);
-
- if (((device.flag & FTD2XX.FT_FLAGS_OPENED) == 0)
- && device.devType.equals(deviceType)) {
- devs.add(device);
- }
-
- }
-
- Logger.getLogger(FTDevice.class.getName()).log(Level.INFO,
- "Found devs: {0} (All:{1})",
- new Object[]{devs.size(), devNum.getValue()});
-
- return devs;
- }
-
- /**
- * Open connection with device.
- * @throws FTD2XXException If something goes wrong.
- */
- public void open() throws FTD2XXException {
- Memory memory = new Memory(16);
- memory.setString(0, devSerialNumber);
- IntByReference handle = new IntByReference();
- ensureFTStatus(ftd2xx.FT_OpenEx(memory, FTD2XX.FT_OPEN_BY_SERIAL_NUMBER,
- handle));
- this.ftHandle = handle.getValue();
- }
-
- /**
- * Close connection with device.
- * @throws FTD2XXException If something goes wrong.
- */
- public void close() throws FTD2XXException {
- ensureFTStatus(ftd2xx.FT_Close(ftHandle));
- }
-
- /**
- * Set desired baud rate.
- * @param baudRate The baud rate.
- * @throws FTD2XXException If something goes wrong.
- */
- public void setBaudRate(long baudRate) throws FTD2XXException {
- ensureFTStatus(ftd2xx.FT_SetBaudRate(ftHandle, (int) baudRate));
- }
-
- /**
- * This function sets the data characteristics for the device
- * @param wordLength Number of bits per word
- * @param stopBits Number of stop bits
- * @param parity Parity
- * @throws FTD2XXException If something goes wrong.
- */
- public void setDataCharacteristics(WordLength wordLength, StopBits stopBits,
- Parity parity) throws FTD2XXException {
- ensureFTStatus(ftd2xx.FT_SetDataCharacteristics(ftHandle,
- (byte) wordLength.constant(), (byte) stopBits.constant(),
- (byte) parity.constant()));
- }
-
- /**
- * Set the read and write timeouts for the device.
- * @param readTimeout Read timeout in milliseconds.
- * @param writeTimeout Write timeout in milliseconds.
- * @throws FTD2XXException If something goes wrong.
- */
- public void setTimeouts(long readTimeout, long writeTimeout)
- throws FTD2XXException {
- ensureFTStatus(ftd2xx.FT_SetTimeouts(ftHandle, (int) readTimeout,
- (int) writeTimeout));
- }
-
- /**
- * Sets the flow control for the device.
- * @param flowControl Flow control type.
- * @throws FTD2XXException If something goes wrong.
- */
- public void setFlowControl(FlowControl flowControl) throws FTD2XXException {
- ensureFTStatus(ftd2xx.FT_SetFlowControl(ftHandle,
- (short) flowControl.constant(), (byte) 0, (byte) 0));
- }
-
- /**
- * Sets the flow control for the device.
- * @param flowControl Flow control type.
- * @param uXon Character used to signal Xon. Only used if flow control is
- * FT_FLOW_XON_XOFF
- * @param uXoff Character used to signal Xoff. Only used if flow control is
- * FT_FLOW_XON_XOFF
- * @throws FTD2XXException If something goes wrong.
- */
- public void setFlowControl(FlowControl flowControl, byte uXon, byte uXoff)
- throws FTD2XXException {
- ensureFTStatus(ftd2xx.FT_SetFlowControl(ftHandle,
- (short) flowControl.constant(), uXon, uXoff));
- }
-
- /**
- * Set the Data Terminal Ready (DTR) control signal.
- * @param status Status of DTR signal.
- * @throws FTD2XXException If something goes wrong.
- */
- public void setDtr(boolean status) throws FTD2XXException {
- if (status) {
- ensureFTStatus(ftd2xx.FT_SetDtr(ftHandle));
- } else {
- ensureFTStatus(ftd2xx.FT_ClrDtr(ftHandle));
- }
- }
-
- /**
- * Set the Request To Send (RTS) control signal
- * @param status Status of RTS signal.
- * @throws FTD2XXException If something goes wrong.
- */
- public void setRts(boolean status) throws FTD2XXException {
- if (status) {
- ensureFTStatus(ftd2xx.FT_SetRts(ftHandle));
- } else {
- ensureFTStatus(ftd2xx.FT_ClrRts(ftHandle));
- }
- }
-
- /**
- * Gets the modem status and line status from the device.
- * @return Modem and line statuses
- * @throws FTD2XXException If something goes wrong.
- */
- public EnumSet getDeviceStatus() throws FTD2XXException {
- IntByReference modstat = new IntByReference();
- ensureFTStatus(ftd2xx.FT_GetModemStatus(ftHandle, modstat));
- return DeviceStatus.parseToEnumset(modstat.getValue());
- }
-
- /**
- * Gets the number of bytes in the receive queue.
- * @return The number of bytes in the receive queue
- * @throws FTD2XXException If something goes wrong.
- */
- public int getQueueStatus() throws FTD2XXException {
- IntByReference reference = new IntByReference();
- ensureFTStatus(ftd2xx.FT_GetQueueStatus(ftHandle, reference));
- return reference.getValue();
- }
-
- /**
- * Purge receive or transmit buffers in the device.
- * @param rxBuffer Will rxBuffer be purged?
- * @param txBuffer Will txBuffer be purged?
- * @throws FTD2XXException If something goes wrong.
- */
- public void purgeBuffer(boolean rxBuffer, boolean txBuffer)
- throws FTD2XXException {
- int mask = 0;
- if (rxBuffer) {
- mask |= Purge.PURGE_RX.constant();
- }
- if (txBuffer) {
- mask |= Purge.PURGE_TX.constant();
- }
- ensureFTStatus(ftd2xx.FT_Purge(ftHandle, mask));
- }
-
- /**
- * Send a reset command to the device.
- * @throws FTD2XXException If something goes wrong.
- */
- public void resetDevice() throws FTD2XXException {
- ensureFTStatus(ftd2xx.FT_ResetDevice(ftHandle));
- }
-
- /**
- * Set the latency timer value.
- * @param timer Latency timer value in milliseconds.
- * Valid range is 2 – 255.
- * @throws FTD2XXException If something goes wrong.
- * @throws IllegalArgumentException If timer was not in range 2 - 255.
- */
- public void setLatencyTimer(short timer) throws FTD2XXException,
- IllegalArgumentException {
- if (!((timer > 2) && (timer < 255))) {
- throw new IllegalArgumentException("Valid range is 2 – 255!");
- }
- ensureFTStatus(ftd2xx.FT_SetLatencyTimer(ftHandle, (byte) timer));
- }
-
- /**
- * Get the current value of the latency timer.
- * @return latency timer value.
- * @throws FTD2XXException If something goes wrong.
- */
- public short getLatencyTimer() throws FTD2XXException {
- ByteByReference byReference = new ByteByReference();
- ensureFTStatus(ftd2xx.FT_GetLatencyTimer(ftHandle, byReference));
- return (short) ((short) byReference.getValue() & 0xFF);
- }
-
- /**
- * Enables different chip modes.
- * @param ucMask Required value for bit mode mask. This sets up which bits
- * are inputs and outputs. A bit value of 0 sets the corresponding pin to
- * an input, a bit value of 1 sets the corresponding pin to an output. In
- * the case of CBUS Bit Bang, the upper nibble of this value controls which
- * pins are inputs and outputs, while the lower nibble controls which of the
- * outputs are high and low.
- * @param bitMode Mode value.
- * @throws FTD2XXException If something goes wrong.
- */
- public void setBitMode(byte ucMask, BitModes bitMode)
- throws FTD2XXException {
- ensureFTStatus(ftd2xx.FT_SetBitMode(ftHandle, ucMask,
- (byte) bitMode.constant()));
- }
-
- /**
- * Gets the instantaneous value of the data bus.
- * @return instantaneous data bus value
- * @throws FTD2XXException If something goes wrong.
- */
- public BitModes getBitMode() throws FTD2XXException {
- ByteByReference byt = new ByteByReference();
- ensureFTStatus(ftd2xx.FT_GetBitmode(ftHandle, byt));
- return BitModes.parse(byt.getValue());
- }
-
- /**
- * Set the USB request transfer size.
- * This function can be used to change the transfer sizes from the default
- * transfer size of 4096 bytes to better suit the application requirements.
- * Transfer sizes must be set to a multiple of 64 bytes between 64 bytes and
- * 64k bytes.
- * When FT_SetUSBParameters is called, the change comes into effect
- * immediately and any data that was held in the driver at the time of the
- * change is lost. Note that, at present, only dwInTransferSize is
- * supported.
- * @param inTransferSize Transfer size for USB IN request
- * @param outTransferSize Transfer size for USB OUT request
- * @throws FTD2XXException If something goes wrong.
- */
- public void setUSBParameters(int inTransferSize, int outTransferSize)
- throws FTD2XXException {
- ensureFTStatus(ftd2xx.FT_SetUSBParameters(ftHandle, inTransferSize,
- outTransferSize));
- }
-
- /**
- * Program the EEPROM data
- * @param programData EEPROM to program
- * @throws FTD2XXException If something goes wrong.
- */
- public void writeEEPROM(EEPROMData programData)
- throws FTD2XXException {
- ensureFTStatus(ftd2xx.FT_EE_Program(ftHandle,
- programData.ft_program_data));
- }
-
- /**
- * Read device EEPROM data
- * @return EEPROM data
- * @throws FTD2XXException If something goes wrong.
- */
- public EEPROMData readEEPROM() throws FTD2XXException {
- FTD2XX.FT_PROGRAM_DATA.ByReference ftByReference =
- new FTD2XX.FT_PROGRAM_DATA.ByReference();
- ensureFTStatus(ftd2xx.FT_EE_Read(ftHandle, ftByReference));
- return new EEPROMData(ftByReference);
- }
-
- /**
- * Get the available size of the EEPROM user area
- * @return available size in bytes, of the EEPROM user area
- * @throws FTD2XXException If something goes wrong.
- */
- public int getEEPROMUserAreaSize() throws FTD2XXException {
- IntByReference size = new IntByReference();
- ensureFTStatus(ftd2xx.FT_EE_UASize(ftHandle, size));
- return size.getValue();
- }
-
- /**
- * Read the contents of the EEPROM user area
- * @param numberOfBytes Size in bytes, to be read
- * @return User EEPROM content
- * @throws FTD2XXException If something goes wrong.
- */
- public byte[] readEEPROMUserArea(int numberOfBytes)
- throws FTD2XXException {
- IntByReference actually = new IntByReference();
- Memory dest = new Memory(numberOfBytes);
- ensureFTStatus(ftd2xx.FT_EE_UARead(ftHandle, dest, numberOfBytes,
- actually));
- return dest.getByteArray(0, actually.getValue());
- }
-
- /**
- * Read all contents of the EEPROM user area
- * @return User EEPROM content
- * @throws FTD2XXException If something goes wrong.
- */
- public byte[] readFullEEPROMUserArea()
- throws FTD2XXException {
- int numberOfBytes = getEEPROMUserAreaSize();
- return readEEPROMUserArea(numberOfBytes);
- }
-
- /**
- * Read all contents of the EEPROM user area as String
- * @return User EEPROM content as String
- * @throws FTD2XXException If something goes wrong.
- */
- public String readFullEEPROMUserAreaAsString() throws IOException {
- IntByReference actually = new IntByReference();
- int numberOfBytes = getEEPROMUserAreaSize();
- Memory dest = new Memory(numberOfBytes);
- ensureFTStatus(ftd2xx.FT_EE_UARead(ftHandle, dest, numberOfBytes,
- actually));
- return dest.getString(0);
- }
-
- /**
- * Write data into the EEPROM user area
- * @param data byte[] to write
- * @throws FTD2XXException If something goes wrong.
- */
- public void writeEEPROMUserArea(byte[] data) throws FTD2XXException {
- Memory source = new Memory(data.length);
- source.write(0, data, 0, data.length);
- ensureFTStatus(ftd2xx.FT_EE_UAWrite(ftHandle, source, data.length));
- }
-
- /**
- * Write string into the EEPROM user area
- * @param data byte[] to write
- * @throws FTD2XXException If something goes wrong.
- */
- public void writeEEPROMUserArea(String data) throws FTD2XXException {
- Memory source = new Memory(data.length());
- source.setString(0, data);
- ensureFTStatus(ftd2xx.FT_EE_UAWrite(ftHandle, source, data.length()));
- }
-
- /**
- * Write bytes to device.
- * @param bytes Byte array to send
- * @param offset Start index
- * @param length Amount of bytes to write
- * @return Number of bytes actually written
- * @throws FTD2XXException If something goes wrong.
- */
- public int write(byte[] bytes, int offset, int length)
- throws FTD2XXException {
- Memory memory = new Memory(length);
- memory.write(0, bytes, offset, length);
- IntByReference wrote = new IntByReference();
-
- ensureFTStatus(ftd2xx.FT_Write(ftHandle, memory, length, wrote));
-
- return wrote.getValue();
- }
-
- /**
- * Write bytes to device.
- * @param bytes Byte array to send
- * @return Number of bytes actually written
- * @throws FTD2XXException If something goes wrong.
- */
- public int write(byte[] bytes) throws FTD2XXException {
- return write(bytes, 0, bytes.length);
- }
-
- /**
- * Write byte to device.
- * @param b Byte to send (0..255)
- * @return It was success?
- * @throws FTD2XXException
- */
- public boolean write(int b) throws FTD2XXException {
- byte[] c = new byte[1];
- c[0] = (byte) b;
- return (write(c) == 1) ? true : false;
- }
-
- /**
- * Read bytes from device.
- * @param bytes Bytes array to store read bytes
- * @param offset Start index.
- * @param lenght Amount of bytes to read
- * @return Number of bytes actually read
- * @throws FTD2XXException If something goes wrong.
- */
- public int read(byte[] bytes, int offset, int lenght)
- throws FTD2XXException {
- Memory memory = new Memory(lenght);
- IntByReference read = new IntByReference();
-
- ensureFTStatus(ftd2xx.FT_Read(ftHandle, memory, lenght, read));
-
- memory.read(0, bytes, offset, lenght);
-
- return read.getValue();
- }
-
- /**
- * Read bytes from device.
- * @param bytes Bytes array to store read bytes
- * @return Number of bytes actually read
- * @throws FTD2XXException If something goes wrong.
- */
- public int read(byte[] bytes) throws FTD2XXException {
- return read(bytes, 0, bytes.length);
- }
-
- /**
- * Read a byte from device.
- * @return The byte what read or -1;
- * @throws FTD2XXException
- */
- public int read() throws FTD2XXException {
- byte[] c = new byte[1];
- int ret = read(c);
- return (ret == 1) ? ((int) c[0] & 0xFF) : -1;
- }
-
- /**
- * Read given bytes from device.
- * @param number How many bytes do you want to read?
- * @return Read bytes
- * @throws FTD2XXException If something goes wrong.
- */
- public byte[] read(int number)
- throws FTD2XXException {
- byte[] ret = new byte[number];
- int actually = read(ret);
- if (actually != number) {
- byte[] shrink = new byte[actually];
- System.arraycopy(ret, 0, shrink, 0, actually);
- return shrink;
- } else {
- return ret;
- }
- }
-
- /**
- * Get an InputStream to device.
- * @return InputStream
- */
- public InputStream getInputStream() {
- if (fTDeviceInputStream == null) {
- fTDeviceInputStream = new FTDeviceInputStream(this);
- }
- return fTDeviceInputStream;
- }
-
- /**
- * Get an OutputStream to device.
- * @return OutputStream
- */
- public OutputStream getOutputStream() {
- if (fTDeviceOutputStream == null) {
- fTDeviceOutputStream = new FTDeviceOutputStream(this);
- }
- return fTDeviceOutputStream;
- }
-
- @Override
- @SuppressWarnings("FinalizeDeclaration")
- protected void finalize() throws Throwable {
- try {
- close();
- } catch (FTD2XXException ex) {
- }
- super.finalize();
- }
-}
+/*
+ * The MIT License
+ *
+ * Copyright 2011 Peter Kocsis .
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.ftdi;
+
+import com.sun.jna.Memory;
+import com.sun.jna.Platform;
+import com.sun.jna.Pointer;
+import com.sun.jna.ptr.ByteByReference;
+import com.sun.jna.ptr.IntByReference;
+import com.sun.jna.ptr.PointerByReference;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Java class to communicate easily to a FTDI device.
+ * @author Peter Kocsis
+ */
+public class FTDevice {
+
+ static private final FTD2XX ftd2xx = FTD2XX.INSTANCE;
+ private final int devID, devLocationID, flag;
+ private final DeviceType devType;
+ private Pointer ftHandle;
+ private final String devSerialNumber, devDescription;
+ private FTDeviceInputStream fTDeviceInputStream = null;
+ private FTDeviceOutputStream fTDeviceOutputStream = null;
+
+ private FTDevice(DeviceType devType, int devID, int devLocationID,
+ String devSerialNumber, String devDescription, Pointer ftHandle,
+ int flag) {
+ this.devType = devType;
+ this.devID = devID;
+ this.devLocationID = devLocationID;
+ this.devSerialNumber = devSerialNumber;
+ this.devDescription = devDescription;
+ this.ftHandle = ftHandle;
+ this.flag = flag;
+ }
+
+ /**
+ * Get device description.
+ * @return device description
+ */
+ public String getDevDescription() {
+ return devDescription;
+ }
+
+ /**
+ * Get device ID.
+ * @return device ID
+ */
+ public int getDevID() {
+ return devID;
+ }
+
+ /**
+ * Get device serial number.
+ * @return device serial number
+ */
+ public String getDevSerialNumber() {
+ return devSerialNumber;
+ }
+
+ /**
+ * Get device type.
+ * @return device type.
+ */
+ public DeviceType getDevType() {
+ return devType;
+ }
+
+ /**
+ * Get device location.
+ * @return device location.
+ */
+ public int getDevLocationID() {
+ return devLocationID;
+ }
+
+ /**
+ * Get device flag.
+ * @return flag.
+ */
+ public int getFlag() {
+ return flag;
+ }
+
+ /**
+ * Is this FTDevice opened?
+ * @return True if FTDevice is opened.
+ */
+ public boolean isOpened(){
+ return (flag & FTD2XX.FT_FLAGS_OPENED) != 0;
+ }
+
+ /**
+ * Is the device enumerated as a high-speed USB device?
+ * @return True if the device is enumerated as a high-speed USB device, false
+ * if full-speed.
+ */
+ public boolean isHighSpeed(){
+ return (flag & FTD2XX.FT_FLAGS_HISPEED) != 0;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof FTDevice)) {
+ return false;
+ }
+ FTDevice eq = (FTDevice) obj;
+ return eq.ftHandle == this.ftHandle;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 5;
+ hash = (int) (97 * hash + ftHandle.hashCode());
+ return hash;
+ }
+
+ @Override
+ public String toString() {
+ return "FTDevice{" + "devDescription=" + devDescription
+ + ", devSerialNumber=" + devSerialNumber + '}';
+ }
+
+ private static void ensureFTStatus(int ftstatus) throws FTD2XXException {
+ if (!(ftstatus == FT_STATUS.OK.constant())) {
+ throw new FTD2XXException(ftstatus);
+ }
+ }
+
+ private static FTDevice getXthDevice(int Xth) throws FTD2XXException {
+ IntByReference flag = new IntByReference();
+ IntByReference devType = new IntByReference();
+ IntByReference devID = new IntByReference();
+ IntByReference locID = new IntByReference();
+ PointerByReference ftHandle = new PointerByReference();
+ Memory devSerNum = new Memory(16);
+ Memory devDesc = new Memory(64);
+
+ ensureFTStatus(ftd2xx.FT_GetDeviceInfoDetail(Xth, flag, devType, devID,
+ locID, devSerNum, devDesc, ftHandle));
+
+ return new FTDevice(DeviceType.values()[devType.getValue()],
+ devID.getValue(), locID.getValue(), devSerNum.getString(0),
+ devDesc.getString(0), ftHandle.getPointer(), flag.getValue());
+ }
+
+ /**
+ * A command to include a custom VID and PID combination within the internal
+ * device list table. This will allow the driver to load for the specified
+ * VID and PID combination. Only supported on Linux and Mac OS X.
+ *
+ * @param dwVID Device Vendor ID (VID)
+ * @param dwPID Device Product ID (PID)
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public static void setVidPid(int dwVID, int dwPID) throws FTD2XXException {
+ if (Platform.isLinux() || Platform.isMac()) {
+ Logger.getLogger(FTDevice.class.getName()).log(Level.INFO,
+ "Setting custom VID/PID to {0}/{1}.",
+ new Object[]{toHex4(dwVID), toHex4(dwPID)});
+ ensureFTStatus(ftd2xx.FT_SetVIDPID(dwVID, dwPID));
+ } else {
+ Logger.getLogger(FTDevice.class.getName()).log(Level.INFO,
+ "Ignoring request to set VID/PID. Windows not supported.");
+ }
+ }
+
+ private static String toHex4(int value) {
+ // Bitwise and (&) with 0xFFFF is to ensure unsigned value.
+ return String.format("0x%04x", (0xFFFF & value));
+ }
+
+ /**
+ * Get the connected FTDI devices. It will not contain opened devices.
+ * @return List contain available FTDI devices.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public static List getDevices() throws FTD2XXException {
+ return getDevices(false);
+ }
+
+ /**
+ * Get the connected FTDI devices.
+ * @param isIncludeOpenedDevices Would you like to see opened devices?
+ * @return List contain available FTDI devices.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public static List getDevices(boolean isIncludeOpenedDevices)
+ throws FTD2XXException {
+ IntByReference devNum = new IntByReference();
+
+ ensureFTStatus(ftd2xx.FT_CreateDeviceInfoList(devNum));
+
+ ArrayList devs = new ArrayList(devNum.getValue());
+
+ for (int i = 0; i < devNum.getValue(); i++) {
+ FTDevice device = getXthDevice(i);
+ //device is occupied?
+ if (isIncludeOpenedDevices) {
+ devs.add(device);
+ } else {
+ if ((device.flag & FTD2XX.FT_FLAGS_OPENED) == 0) {
+ devs.add(device);
+ }
+ }
+
+ }
+
+ Logger.getLogger(FTDevice.class.getName()).log(Level.INFO,
+ "Found devs: {0} (All:{1})",
+ new Object[]{devs.size(), devNum.getValue()});
+
+ return devs;
+ }
+
+ /**
+ * Get the connected FTDI devices. It will not contain opened devices.
+ * @param description Filtering option, exact match need.
+ * @return List contain available FTDI devices.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public static List getDevicesByDescription(String description)
+ throws FTD2XXException {
+ IntByReference devNum = new IntByReference();
+
+ ensureFTStatus(ftd2xx.FT_CreateDeviceInfoList(devNum));
+
+ ArrayList devs = new ArrayList(devNum.getValue());
+
+ for (int i = 0; i < devNum.getValue(); i++) {
+ FTDevice device = getXthDevice(i);
+
+ if (((device.flag & FTD2XX.FT_FLAGS_OPENED) == 0)
+ && description.equals(device.devDescription)) {
+ devs.add(device);
+ }
+
+ }
+
+ Logger.getLogger(FTDevice.class.getName()).log(Level.INFO,
+ "Found devs: {0} (All:{1})",
+ new Object[]{devs.size(), devNum.getValue()});
+
+ return devs;
+ }
+
+ /**
+ * Get the connected FTDI devices. It will not contain opened devices.
+ * @param serialNumber Filtering option, exact match need.
+ * @return List contain available FTDI devices.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public static List getDevicesBySerialNumber(String serialNumber)
+ throws FTD2XXException {
+ IntByReference devNum = new IntByReference();
+
+ ensureFTStatus(ftd2xx.FT_CreateDeviceInfoList(devNum));
+
+ ArrayList devs = new ArrayList(devNum.getValue());
+
+ for (int i = 0; i < devNum.getValue(); i++) {
+ FTDevice device = getXthDevice(i);
+
+ if (((device.getFlag() & FTD2XX.FT_FLAGS_OPENED) == 0)
+ && serialNumber.equals(device.devSerialNumber)) {
+ devs.add(device);
+ }
+
+ }
+
+ Logger.getLogger(FTDevice.class.getName()).log(Level.INFO,
+ "Found devs: {0} (All:{1})",
+ new Object[]{devs.size(), devNum.getValue()});
+
+ return devs;
+ }
+
+ /**
+ * Get the connected FTDI devices. It will not contain opened devices.
+ * @param deviceType Filtering option.
+ * @return List contain available FTDI devices.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public static List getDevicesByDeviceType(DeviceType deviceType)
+ throws FTD2XXException {
+ IntByReference devNum = new IntByReference();
+
+ ensureFTStatus(ftd2xx.FT_CreateDeviceInfoList(devNum));
+
+ ArrayList devs = new ArrayList(devNum.getValue());
+
+ for (int i = 0; i < devNum.getValue(); i++) {
+ FTDevice device = getXthDevice(i);
+
+ if (((device.flag & FTD2XX.FT_FLAGS_OPENED) == 0)
+ && device.devType.equals(deviceType)) {
+ devs.add(device);
+ }
+
+ }
+
+ Logger.getLogger(FTDevice.class.getName()).log(Level.INFO,
+ "Found devs: {0} (All:{1})",
+ new Object[]{devs.size(), devNum.getValue()});
+
+ return devs;
+ }
+
+ /**
+ * Open connection with device.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void open() throws FTD2XXException {
+ Memory memory = new Memory(64);
+ memory.setString(0, devSerialNumber);
+ PointerByReference handle = new PointerByReference();
+ ensureFTStatus(ftd2xx.FT_OpenEx(memory, FTD2XX.FT_OPEN_BY_SERIAL_NUMBER,
+ handle));
+ this.ftHandle = handle.getValue();
+ }
+
+ /**
+ * Close connection with device.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void close() throws FTD2XXException {
+ ensureFTStatus(ftd2xx.FT_Close(ftHandle));
+ }
+
+ /**
+ * Set desired baud rate.
+ * @param baudRate The baud rate.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void setBaudRate(long baudRate) throws FTD2XXException {
+ ensureFTStatus(ftd2xx.FT_SetBaudRate(ftHandle, (int) baudRate));
+ }
+
+ /**
+ * This function sets the data characteristics for the device
+ * @param wordLength Number of bits per word
+ * @param stopBits Number of stop bits
+ * @param parity Parity
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void setDataCharacteristics(WordLength wordLength, StopBits stopBits,
+ Parity parity) throws FTD2XXException {
+ ensureFTStatus(ftd2xx.FT_SetDataCharacteristics(ftHandle,
+ (byte) wordLength.constant(), (byte) stopBits.constant(),
+ (byte) parity.constant()));
+ }
+
+ /**
+ * Set the read and write timeouts for the device.
+ * @param readTimeout Read timeout in milliseconds.
+ * @param writeTimeout Write timeout in milliseconds.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void setTimeouts(long readTimeout, long writeTimeout)
+ throws FTD2XXException {
+ ensureFTStatus(ftd2xx.FT_SetTimeouts(ftHandle, (int) readTimeout,
+ (int) writeTimeout));
+ }
+
+ /**
+ * Sets the flow control for the device.
+ * @param flowControl Flow control type.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void setFlowControl(FlowControl flowControl) throws FTD2XXException {
+ ensureFTStatus(ftd2xx.FT_SetFlowControl(ftHandle,
+ (short) flowControl.constant(), (byte) 0, (byte) 0));
+ }
+
+ /**
+ * Sets the flow control for the device.
+ * @param flowControl Flow control type.
+ * @param uXon Character used to signal Xon. Only used if flow control is
+ * FT_FLOW_XON_XOFF
+ * @param uXoff Character used to signal Xoff. Only used if flow control is
+ * FT_FLOW_XON_XOFF
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void setFlowControl(FlowControl flowControl, byte uXon, byte uXoff)
+ throws FTD2XXException {
+ ensureFTStatus(ftd2xx.FT_SetFlowControl(ftHandle,
+ (short) flowControl.constant(), uXon, uXoff));
+ }
+
+ /**
+ * Set the Data Terminal Ready (DTR) control signal.
+ * @param status Status of DTR signal.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void setDtr(boolean status) throws FTD2XXException {
+ if (status) {
+ ensureFTStatus(ftd2xx.FT_SetDtr(ftHandle));
+ } else {
+ ensureFTStatus(ftd2xx.FT_ClrDtr(ftHandle));
+ }
+ }
+
+ /**
+ * Set the Request To Send (RTS) control signal
+ * @param status Status of RTS signal.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void setRts(boolean status) throws FTD2XXException {
+ if (status) {
+ ensureFTStatus(ftd2xx.FT_SetRts(ftHandle));
+ } else {
+ ensureFTStatus(ftd2xx.FT_ClrRts(ftHandle));
+ }
+ }
+
+ /**
+ * Gets the modem status and line status from the device.
+ * @return Modem and line statuses
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public EnumSet getDeviceStatus() throws FTD2XXException {
+ IntByReference modstat = new IntByReference();
+ ensureFTStatus(ftd2xx.FT_GetModemStatus(ftHandle, modstat));
+ return DeviceStatus.parseToEnumset(modstat.getValue());
+ }
+
+ /**
+ * Gets the number of bytes in the receive queue.
+ * @return The number of bytes in the receive queue
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public int getQueueStatus() throws FTD2XXException {
+ IntByReference reference = new IntByReference();
+ ensureFTStatus(ftd2xx.FT_GetQueueStatus(ftHandle, reference));
+ return reference.getValue();
+ }
+
+ /**
+ * Purge receive or transmit buffers in the device.
+ * @param rxBuffer Will rxBuffer be purged?
+ * @param txBuffer Will txBuffer be purged?
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void purgeBuffer(boolean rxBuffer, boolean txBuffer)
+ throws FTD2XXException {
+ int mask = 0;
+ if (rxBuffer) {
+ mask |= Purge.PURGE_RX.constant();
+ }
+ if (txBuffer) {
+ mask |= Purge.PURGE_TX.constant();
+ }
+ ensureFTStatus(ftd2xx.FT_Purge(ftHandle, mask));
+ }
+
+ /**
+ * Send a reset command to the device.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void resetDevice() throws FTD2XXException {
+ ensureFTStatus(ftd2xx.FT_ResetDevice(ftHandle));
+ }
+
+ /**
+ * Set the latency timer value.
+ * @param timer Latency timer value in milliseconds.
+ * Valid range is 2 – 255.
+ * @throws FTD2XXException If something goes wrong.
+ * @throws IllegalArgumentException If timer was not in range 2 - 255.
+ */
+ public void setLatencyTimer(short timer) throws FTD2XXException,
+ IllegalArgumentException {
+ if (!((timer >=1) && (timer < 255))) {
+ throw new IllegalArgumentException("Valid range is 2 – 255!");
+ }
+ ensureFTStatus(ftd2xx.FT_SetLatencyTimer(ftHandle, (byte) timer));
+ }
+
+ /**
+ * Get the current value of the latency timer.
+ * @return latency timer value.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public short getLatencyTimer() throws FTD2XXException {
+ ByteByReference byReference = new ByteByReference();
+ ensureFTStatus(ftd2xx.FT_GetLatencyTimer(ftHandle, byReference));
+ return (short) ((short) byReference.getValue() & 0xFF);
+ }
+
+ /**
+ * Enables different chip modes.
+ * @param ucMask Required value for bit mode mask. This sets up which bits
+ * are inputs and outputs. A bit value of 0 sets the corresponding pin to
+ * an input, a bit value of 1 sets the corresponding pin to an output. In
+ * the case of CBUS Bit Bang, the upper nibble of this value controls which
+ * pins are inputs and outputs, while the lower nibble controls which of the
+ * outputs are high and low.
+ * @param bitMode Mode value.
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void setBitMode(byte ucMask, BitModes bitMode)
+ throws FTD2XXException {
+ ensureFTStatus(ftd2xx.FT_SetBitMode(ftHandle, ucMask,
+ (byte) bitMode.constant()));
+ }
+
+ /**
+ * Gets the instantaneous value of the data bus.
+ * @return instantaneous data bus value
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public BitModes getBitMode() throws FTD2XXException {
+ ByteByReference byt = new ByteByReference();
+ ensureFTStatus(ftd2xx.FT_GetBitmode(ftHandle, byt));
+ return BitModes.parse(byt.getValue());
+ }
+
+ /**
+ * Set the USB request transfer size.
+ * This function can be used to change the transfer sizes from the default
+ * transfer size of 4096 bytes to better suit the application requirements.
+ * Transfer sizes must be set to a multiple of 64 bytes between 64 bytes and
+ * 64k bytes.
+ * When FT_SetUSBParameters is called, the change comes into effect
+ * immediately and any data that was held in the driver at the time of the
+ * change is lost. Note that, at present, only dwInTransferSize is
+ * supported.
+ * @param inTransferSize Transfer size for USB IN request
+ * @param outTransferSize Transfer size for USB OUT request
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void setUSBParameters(int inTransferSize, int outTransferSize)
+ throws FTD2XXException {
+ ensureFTStatus(ftd2xx.FT_SetUSBParameters(ftHandle, inTransferSize,
+ outTransferSize));
+ }
+
+ /**
+ * Program the EEPROM data
+ * @param programData EEPROM to program
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void writeEEPROM(EEPROMData programData)
+ throws FTD2XXException {
+ ensureFTStatus(ftd2xx.FT_EE_Program(ftHandle,
+ programData.ft_program_data));
+ }
+
+ /**
+ * Read device EEPROM data
+ * @return EEPROM data
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public EEPROMData readEEPROM() throws FTD2XXException {
+ FTD2XX.FT_PROGRAM_DATA.ByReference ftByReference =
+ new FTD2XX.FT_PROGRAM_DATA.ByReference();
+ ensureFTStatus(ftd2xx.FT_EE_Read(ftHandle, ftByReference));
+ return new EEPROMData(ftByReference);
+ }
+
+ /**
+ * Get the available size of the EEPROM user area
+ * @return available size in bytes, of the EEPROM user area
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public int getEEPROMUserAreaSize() throws FTD2XXException {
+ IntByReference size = new IntByReference();
+ ensureFTStatus(ftd2xx.FT_EE_UASize(ftHandle, size));
+ return size.getValue();
+ }
+
+ /**
+ * Read the contents of the EEPROM user area
+ * @param numberOfBytes Size in bytes, to be read
+ * @return User EEPROM content
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public byte[] readEEPROMUserArea(int numberOfBytes)
+ throws FTD2XXException {
+ IntByReference actually = new IntByReference();
+ Memory dest = new Memory(numberOfBytes);
+ ensureFTStatus(ftd2xx.FT_EE_UARead(ftHandle, dest, numberOfBytes,
+ actually));
+ return dest.getByteArray(0, actually.getValue());
+ }
+
+ /**
+ * Read all contents of the EEPROM user area
+ * @return User EEPROM content
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public byte[] readFullEEPROMUserArea()
+ throws FTD2XXException {
+ int numberOfBytes = getEEPROMUserAreaSize();
+ return readEEPROMUserArea(numberOfBytes);
+ }
+
+ /**
+ * Read all contents of the EEPROM user area as String
+ * @return User EEPROM content as String
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public String readFullEEPROMUserAreaAsString() throws IOException {
+ IntByReference actually = new IntByReference();
+ int numberOfBytes = getEEPROMUserAreaSize();
+ Memory dest = new Memory(numberOfBytes);
+ ensureFTStatus(ftd2xx.FT_EE_UARead(ftHandle, dest, numberOfBytes,
+ actually));
+ return dest.getString(0);
+ }
+
+ /**
+ * Write data into the EEPROM user area
+ * @param data byte[] to write
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void writeEEPROMUserArea(byte[] data) throws FTD2XXException {
+ Memory source = new Memory(data.length);
+ source.write(0, data, 0, data.length);
+ ensureFTStatus(ftd2xx.FT_EE_UAWrite(ftHandle, source, data.length));
+ }
+
+ /**
+ * Write string into the EEPROM user area
+ * @param data byte[] to write
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public void writeEEPROMUserArea(String data) throws FTD2XXException {
+ Memory source = new Memory(data.length());
+ source.setString(0, data);
+ ensureFTStatus(ftd2xx.FT_EE_UAWrite(ftHandle, source, data.length()));
+ }
+
+ /**
+ * Write bytes to device.
+ * @param bytes Byte array to send
+ * @param offset Start index
+ * @param length Amount of bytes to write
+ * @return Number of bytes actually written
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public int write(byte[] bytes, int offset, int length)
+ throws FTD2XXException {
+ Memory memory = new Memory(length);
+ memory.write(0, bytes, offset, length);
+ IntByReference wrote = new IntByReference();
+
+ ensureFTStatus(ftd2xx.FT_Write(ftHandle, memory, length, wrote));
+
+ return wrote.getValue();
+ }
+
+ /**
+ * Write bytes to device.
+ * @param bytes Byte array to send
+ * @return Number of bytes actually written
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public int write(byte[] bytes) throws FTD2XXException {
+ return write(bytes, 0, bytes.length);
+ }
+
+ /**
+ * Write byte to device.
+ * @param b Byte to send (0..255)
+ * @return It was success?
+ * @throws FTD2XXException
+ */
+ public boolean write(int b) throws FTD2XXException {
+ byte[] c = new byte[1];
+ c[0] = (byte) b;
+ return (write(c) == 1) ? true : false;
+ }
+
+ /**
+ * Read bytes from device.
+ * @param bytes Bytes array to store read bytes
+ * @param offset Start index.
+ * @param length Amount of bytes to read
+ * @return Number of bytes actually read
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public int read(byte[] bytes, int offset, int length)
+ throws FTD2XXException {
+ Memory memory = new Memory(length);
+ IntByReference read = new IntByReference();
+
+ ensureFTStatus(ftd2xx.FT_Read(ftHandle, memory, length, read));
+
+ memory.read(0, bytes, offset, length);
+
+ return read.getValue();
+ }
+
+ /**
+ * Read bytes from device.
+ * @param bytes Bytes array to store read bytes
+ * @return Number of bytes actually read
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public int read(byte[] bytes) throws FTD2XXException {
+ return read(bytes, 0, bytes.length);
+ }
+
+ /**
+ * Read a byte from device.
+ * @return The byte what read or -1;
+ * @throws FTD2XXException
+ */
+ public int read() throws FTD2XXException {
+ byte[] c = new byte[1];
+ int ret = read(c);
+ return (ret == 1) ? ((int) c[0] & 0xFF) : -1;
+ }
+
+ /**
+ * Read given bytes from device.
+ * @param number How many bytes do you want to read?
+ * @return Read bytes
+ * @throws FTD2XXException If something goes wrong.
+ */
+ public byte[] read(int number)
+ throws FTD2XXException {
+ byte[] ret = new byte[number];
+ int actually = read(ret);
+ if (actually != number) {
+ byte[] shrink = new byte[actually];
+ System.arraycopy(ret, 0, shrink, 0, actually);
+ return shrink;
+ } else {
+ return ret;
+ }
+ }
+
+ /**
+ * Get an InputStream to device.
+ * @return InputStream
+ */
+ public InputStream getInputStream() {
+ if (fTDeviceInputStream == null) {
+ fTDeviceInputStream = new FTDeviceInputStream(this);
+ }
+ return fTDeviceInputStream;
+ }
+
+ /**
+ * Get an OutputStream to device.
+ * @return OutputStream
+ */
+ public OutputStream getOutputStream() {
+ if (fTDeviceOutputStream == null) {
+ fTDeviceOutputStream = new FTDeviceOutputStream(this);
+ }
+ return fTDeviceOutputStream;
+ }
+
+ @Override
+ @SuppressWarnings("FinalizeDeclaration")
+ protected void finalize() throws Throwable {
+ try {
+ close();
+ } catch (FTD2XXException ex) {
+ }
+ super.finalize();
+ }
+}
diff --git a/src/com/ftdi/FT_STATUS.java b/src/com/ftdi/FT_STATUS.java
index 4ab46c7..e36a1e1 100644
--- a/src/com/ftdi/FT_STATUS.java
+++ b/src/com/ftdi/FT_STATUS.java
@@ -1,55 +1,56 @@
-/*
- * The MIT License
- *
- * Copyright 2011 Peter Kocsis .
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.ftdi;
-
-/**
- * FT_STATUS (DWORD)
- * @author Peter Kocsis
- */
-enum FT_STATUS {
-
- OK,
- INVALID_HANDLE,
- DEVICE_NOT_FOUND,
- DEVICE_NOT_OPENED,
- IO_ERROR,
- INSUFFICIENT_RESOURCES,
- INVALID_PARAMETER,
- INVALID_BAUD_RATE,
- DEVICE_NOT_OPENED_FOR_ERASE,
- DEVICE_NOT_OPENED_FOR_WRITE,
- FAILED_TO_WRITE_DEVICE,
- EEPROM_READ_FAILED,
- EEPROM_WRITE_FAILED,
- EEPROM_ERASE_FAILED,
- EEPROM_NOT_PRESENT,
- EEPROM_NOT_PROGRAMMED,
- INVALID_ARGS,
- NOT_SUPPORTED,
- OTHER_ERROR;
-
- int constant(){
- return this.ordinal();
- }
-}
+/*
+ * The MIT License
+ *
+ * Copyright 2011 Peter Kocsis .
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package com.ftdi;
+
+/**
+ * FT_STATUS (DWORD)
+ * @author Peter Kocsis
+ */
+enum FT_STATUS {
+
+ OK,
+ INVALID_HANDLE,
+ DEVICE_NOT_FOUND,
+ DEVICE_NOT_OPENED,
+ IO_ERROR,
+ INSUFFICIENT_RESOURCES,
+ INVALID_PARAMETER,
+ INVALID_BAUD_RATE,
+ DEVICE_NOT_OPENED_FOR_ERASE,
+ DEVICE_NOT_OPENED_FOR_WRITE,
+ FAILED_TO_WRITE_DEVICE,
+ EEPROM_READ_FAILED,
+ EEPROM_WRITE_FAILED,
+ EEPROM_ERASE_FAILED,
+ EEPROM_NOT_PRESENT,
+ EEPROM_NOT_PROGRAMMED,
+ INVALID_ARGS,
+ NOT_SUPPORTED,
+ OTHER_ERROR,
+ DEVICE_LIST_NOT_READY;
+
+ int constant(){
+ return this.ordinal();
+ }
+}