Skip to content

Commit e9f87bb

Browse files
committed
Initial commit.
0 parents  commit e9f87bb

File tree

9 files changed

+538
-0
lines changed

9 files changed

+538
-0
lines changed

.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
target
2+
.settings
3+
.classpath
4+
*.log
5+
.project
6+
libtool
7+
install-sh
8+
Makefile.in
9+
missing
10+
stamp-h1
11+
depcomp
12+
configure
13+
config.sub
14+
config.status
15+
config.h
16+
config.h.in
17+
config.h.in~
18+
config.guess
19+
config.log
20+
aclocal.m4
21+
.cproject
22+
.deps
23+
m4
24+
Debug
25+
autom4te.cache
26+
dump
27+
ltmain.sh
28+
.libs
29+
*.lo
30+
*.o
31+
*.la
32+
INSTALL
33+
Makefile

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
language: java

LICENSE.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2013 Klaus Reimer <[email protected]
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to
5+
deal in the Software without restriction, including without limitation the
6+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7+
sell copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19+
IN THE SOFTWARE.

README.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
usb4java examples
2+
Copyright (C) 2013 Klaus Reimer <[email protected]>
3+
See LICENSE.txt for licensing information.
4+
==============================================================================
5+
6+
This project just contains some example programs demonstrating how to
7+
use usb4java.

pom.xml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>de.ailis.usb4java</groupId>
6+
<artifactId>usb4java-examples</artifactId>
7+
<packaging>jar</packaging>
8+
<name>usb4java-exampels</name>
9+
<version>1.0.0-SNAPSHOT</version>
10+
<url>http://github.com/kayahr/usb4java-examples/</url>
11+
<description>
12+
usb4java examples
13+
</description>
14+
<inceptionYear>2013</inceptionYear>
15+
<organization>
16+
<name>Klaus Reimer</name>
17+
<url>http://www.ailis.de/~k/</url>
18+
</organization>
19+
20+
<licenses>
21+
<license>
22+
<name>MIT</name>
23+
<url>LICENSE.txt</url>
24+
<distribution>repo</distribution>
25+
</license>
26+
</licenses>
27+
28+
<mailingLists>
29+
<mailingList>
30+
<name>Discussions</name>
31+
<subscribe>[email protected]</subscribe>
32+
<unsubscribe>[email protected]</unsubscribe>
33+
<post>[email protected]</post>
34+
<archive>http://groups.google.com/group/usb4java</archive>
35+
</mailingList>
36+
</mailingLists>
37+
38+
<developers>
39+
<developer>
40+
<id>kayahr</id>
41+
<name>Klaus Reimer</name>
42+
<email>[email protected]</email>
43+
<roles>
44+
<role>Developer</role>
45+
</roles>
46+
<timezone>+1</timezone>
47+
<url>http://www.ailis.de/~k/</url>
48+
</developer>
49+
</developers>
50+
51+
<properties>
52+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
53+
</properties>
54+
55+
<scm>
56+
<connection>scm:git:git://github.com/kayahr/${project.artifactId}.git</connection>
57+
<developerConnection>scm:git:ssh://[email protected]/kayahr/${project.artifactId}.git</developerConnection>
58+
<url>http://github.com/kayahr/${project.artifactId}</url>
59+
</scm>
60+
61+
<issueManagement>
62+
<system>GitHub</system>
63+
<url>https://github.com/kayahr/${project.artifactId}/issues</url>
64+
</issueManagement>
65+
66+
<ciManagement>
67+
<system>Travis CI</system>
68+
<url>https://travis-ci.org/kayahr/${project.artifactId}/</url>
69+
</ciManagement>
70+
71+
<build>
72+
<plugins>
73+
74+
<!-- Use Java 6 -->
75+
<plugin>
76+
<groupId>org.apache.maven.plugins</groupId>
77+
<artifactId>maven-compiler-plugin</artifactId>
78+
<version>3.0</version>
79+
<configuration>
80+
<source>1.6</source>
81+
<target>1.6</target>
82+
<encoding>${project.build.sourceEncoding}</encoding>
83+
</configuration>
84+
</plugin>
85+
86+
</plugins>
87+
</build>
88+
89+
<repositories>
90+
<repository>
91+
<id>ailis-releases</id>
92+
<name>Ailis Maven Releases</name>
93+
<url>http://nexus.ailis.de/content/groups/public/</url>
94+
<releases><enabled>true</enabled></releases>
95+
<snapshots><enabled>false</enabled></snapshots>
96+
</repository>
97+
<repository>
98+
<id>ailis-snapshots</id>
99+
<name>Ailis Maven Snapshots</name>
100+
<url>http://nexus.ailis.de/content/groups/public-snapshots/</url>
101+
<releases><enabled>false</enabled></releases>
102+
<snapshots><enabled>true</enabled></snapshots>
103+
</repository>
104+
</repositories>
105+
106+
<distributionManagement>
107+
<repository>
108+
<id>ailis-releases</id>
109+
<name>Ailis Maven Releases</name>
110+
<url>http://nexus.ailis.de/content/repositories/releases</url>
111+
</repository>
112+
<snapshotRepository>
113+
<id>ailis-snapshots</id>
114+
<name>Ailis Maven Snapshots</name>
115+
<url>http://nexus.ailis.de/content/repositories/snapshots</url>
116+
</snapshotRepository>
117+
</distributionManagement>
118+
119+
<dependencies>
120+
<dependency>
121+
<groupId>junit</groupId>
122+
<artifactId>junit</artifactId>
123+
<version>4.11</version>
124+
<scope>test</scope>
125+
</dependency>
126+
<dependency>
127+
<groupId>de.ailis.usb4java</groupId>
128+
<artifactId>usb4java</artifactId>
129+
<version>1.0.0-SNAPSHOT</version>
130+
</dependency>
131+
</dependencies>
132+
133+
</project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2013 Klaus Reimer <[email protected]>
3+
* See LICENSE.txt for licensing information.
4+
*/
5+
6+
package de.ailis.usb4java.examples.jsr80;
7+
8+
import java.util.List;
9+
10+
import javax.usb.UsbDevice;
11+
import javax.usb.UsbException;
12+
import javax.usb.UsbHostManager;
13+
import javax.usb.UsbHub;
14+
import javax.usb.UsbServices;
15+
16+
/**
17+
* Dumps a tree of all found USB devices.
18+
*
19+
* @author Klaus Reimer <[email protected]>
20+
*/
21+
public class DumpDeviceTree
22+
{
23+
/**
24+
* Dumps the specified device and its sub devices.
25+
*
26+
* @param device
27+
* The USB device to dump.
28+
* @param level
29+
* The indentation level.
30+
*/
31+
public static void dump(UsbDevice device, int level)
32+
{
33+
for (int i = 0; i < level; i += 1)
34+
System.out.print(" ");
35+
System.out.println(device);
36+
if (device.isUsbHub())
37+
{
38+
final UsbHub hub = (UsbHub) device;
39+
for (UsbDevice child: (List<UsbDevice>) hub.getAttachedUsbDevices())
40+
{
41+
dump(child, level + 1);
42+
}
43+
}
44+
}
45+
46+
/**
47+
* Main method.
48+
*
49+
* @param args
50+
* Command-line arguments (Ignored).
51+
* @throws UsbException
52+
* When USB communication fails.
53+
*/
54+
public static void main(String[] args) throws UsbException
55+
{
56+
UsbServices services = UsbHostManager.getUsbServices();
57+
dump(services.getRootUsbHub(), 0);
58+
}
59+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (C) 2013 Klaus Reimer <[email protected]>
3+
* See LICENSE.txt for licensing information.
4+
*/
5+
6+
package de.ailis.usb4java.examples.jsr80;
7+
8+
import java.util.List;
9+
10+
import javax.usb.UsbConfiguration;
11+
import javax.usb.UsbDevice;
12+
import javax.usb.UsbEndpoint;
13+
import javax.usb.UsbException;
14+
import javax.usb.UsbHostManager;
15+
import javax.usb.UsbHub;
16+
import javax.usb.UsbInterface;
17+
import javax.usb.UsbPort;
18+
import javax.usb.UsbServices;
19+
20+
/**
21+
* Dumps all devices by using the high-level JSR80 API.
22+
*
23+
* @author Klaus Reimer <[email protected]>
24+
*/
25+
public class DumpDevices
26+
{
27+
/**
28+
* Dumps the specified USB device to stdout.
29+
*
30+
* @param device
31+
* The USB device to dump.
32+
*/
33+
private static void dumpDevice(final UsbDevice device)
34+
{
35+
// Dump information about the device itself
36+
System.out.println(device);
37+
final UsbPort port = device.getParentUsbPort();
38+
if (port != null)
39+
{
40+
System.out.println("Connected to port: " + port.getPortNumber());
41+
System.out.println("Parent: " + port.getUsbHub());
42+
}
43+
44+
// Dump device descriptor
45+
System.out.println(device.getUsbDeviceDescriptor());
46+
47+
// Process all configurations
48+
for (UsbConfiguration configuration: (List<UsbConfiguration>) device
49+
.getUsbConfigurations())
50+
{
51+
// Dump configuration descriptor
52+
System.out.println(configuration.getUsbConfigurationDescriptor());
53+
54+
// Process all interfaces
55+
for (UsbInterface iface: (List<UsbInterface>) configuration
56+
.getUsbInterfaces())
57+
{
58+
// Dump the interface descriptor
59+
System.out.println(iface.getUsbInterfaceDescriptor());
60+
61+
// Process all endpoints
62+
for (UsbEndpoint endpoint: (List<UsbEndpoint>) iface
63+
.getUsbEndpoints())
64+
{
65+
// Dump the endpoint descriptor
66+
System.out.println(endpoint.getUsbEndpointDescriptor());
67+
}
68+
}
69+
}
70+
71+
System.out.println();
72+
73+
// Dump child devices if device is a hub
74+
if (device.isUsbHub())
75+
{
76+
final UsbHub hub = (UsbHub) device;
77+
for (UsbDevice child: (List<UsbDevice>) hub.getAttachedUsbDevices())
78+
{
79+
dumpDevice(child);
80+
}
81+
}
82+
}
83+
84+
/**
85+
* Main method.
86+
*
87+
* @param args
88+
* Command-line arguments (Ignored)
89+
* @throws UsbException
90+
* When an USB error was reported which wasn't handled by this
91+
* program itself.
92+
*/
93+
public static void main(final String[] args) throws UsbException
94+
{
95+
// Get the USB services and dump information about them
96+
final UsbServices services = UsbHostManager.getUsbServices();
97+
System.out.println("USB Service Implementation: "
98+
+ services.getImpDescription());
99+
System.out.println("Implementation version: "
100+
+ services.getImpVersion());
101+
System.out.println("Service API version: " + services.getApiVersion());
102+
System.out.println();
103+
104+
// Dump the root USB hub
105+
dumpDevice(services.getRootUsbHub());
106+
}
107+
}

0 commit comments

Comments
 (0)