Skip to content

Commit 0bc9ec5

Browse files
committed
Update README
1 parent 2ebba93 commit 0bc9ec5

File tree

1 file changed

+64
-42
lines changed

1 file changed

+64
-42
lines changed

README.md

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
1-
# Java Does USB: USB library for Java
1+
# Java Does USB: USB Library for Java
22

33
[![javadoc](https://javadoc.io/badge2/net.codecrete.usb/java-does-usb/javadoc.svg)](https://javadoc.io/doc/net.codecrete.usb/java-does-usb)
44

5-
*Java Does USB* is a library for working with USB devices from Java. It allows to query information about all conntected USB devices and to communicate with USB devices using custom / vendor specific protocols. (It is not intended for communication with standard types of USB devices such as mass storage devices, keyboards etc.)
6-
7-
The library uses the [Foreign Function & Memory API](https://github.com/openjdk/panama-foreign) to access native APIs of the underlying operating system. It only uses Java code and does not need JNI or any native third-party library.
8-
9-
The Foreign Function & Memory API (aka as project Panama) is in preview and will be introduced in a future Java version. Currently, it can be tested with Java 19 Early Access (with preview features enabled).
10-
11-
12-
## Prerequisite
13-
14-
- Java 19, preview features enabled (available at https://www.azul.com/downloads/?package=jdk)
15-
- Windows (x86 64-bit), macOS (x86 64-bit, ARM 64-bit) or Linux 64 bit (x86 64-bit, ARM 64-bit)
16-
17-
It has been tested with Azul Zulu 19.0.77 EA 34.
5+
*Java Does USB* is a library for working with USB devices. It allows to query information about all conntected USB devices and to communicate with USB devices using custom / vendor specific protocols. (It is not intended for communication with standard types of USB devices such as mass storage devices, keyboards etc.)
186

7+
The library uses the [Foreign Function & Memory API](https://github.com/openjdk/panama-foreign) to access native APIs of the underlying operating system. It only uses Java code and does not need JNI or any native third-party library. The *Foreign Function & Memory API* (aka as project Panama) is in preview and will be introduced in a future Java version. Currently, it can be tested with Java 19 (with preview features enabled).
198

209

2110
## Features
2211

23-
### Implemented
24-
2512
- Single API for all operating systems (similar to WebUSB API)
2613
- Enumeration of USB devices
2714
- Control, bulk and interrupt transfers (optionally with timeout)
@@ -30,7 +17,7 @@ It has been tested with Azul Zulu 19.0.77 EA 34.
3017
- Support for alternate interface settings, composite devices and interface association
3118
- Published on Maven Central
3219

33-
### To do
20+
### Planned
3421

3522
- Isochronous transfer
3623

@@ -41,29 +28,84 @@ It has been tested with Azul Zulu 19.0.77 EA 34.
4128
- Providing information about USB buses, controllers and hubs
4229

4330

44-
## Platform-specific considerations
31+
## Getting Started
32+
33+
The library is available at Maven Central. To use it, just add it to your Maven or Gradle project.
34+
35+
If you are using Maven, add the below dependency to your pom.xml:
36+
37+
```xml
38+
<dependency>
39+
<groupId>net.codecrete.usb</groupId>
40+
<artifactId>java-does-usb</artifactId>
41+
<version>0.4.0</version>
42+
</dependency>
43+
```
44+
45+
If you are using Gradle, add the below dependency to your build.gradle file:
46+
47+
```groovy
48+
compile group: 'net.codecrete.usb', name: 'java-does-usb', version: '0.4.0'
49+
```
50+
51+
```java
52+
package net.codecrete.usb.sample;
53+
54+
import net.codecrete.usb.USB;
55+
56+
public class EnumerateDevices {
57+
58+
public static void main(String[] args) {
59+
for (var device : USB.getAllDevices()) {
60+
System.out.println(device);
61+
}
62+
}
63+
}
64+
```
65+
66+
67+
## Documentation
68+
69+
- [Javadoc](https://javadoc.io/doc/net.codecrete.usb/java-does-usb)
70+
71+
72+
## Examples
73+
74+
- [Bulk Transfer](examples/bulk_transfer/) demonstrates how to find a USB device, open it and communicate using bulk transfer.
75+
- [Enumeration](examples/enumerate/) lists all connected USB devices and displays information about interfaces and endpoints.
76+
- [Monitor](examples/monitor/) lists the connected USB devices and then monitors for USB devices being connected and disconnnected.
77+
78+
79+
## Prerequisite
80+
81+
- Java 19, preview features enabled (available at https://www.azul.com/downloads/?package=jdk)
82+
- Windows (x86 64-bit), macOS (x86 64-bit, ARM 64-bit) or Linux 64 bit (x86 64-bit, ARM 64-bit)
83+
84+
85+
86+
## Platform-specific Considerations
4587

4688

4789
### macOS
4890

49-
No special considerations apply. Using this library, a Java application can connect to any USB device and claim any interfaces that aren't claimed by an operating system driver or another application.
91+
No special considerations apply. Using this library, a Java application can connect to any USB device and claim any interfaces that isn't claimed by an operating system driver or another application.
5092

5193

5294
### Linux
5395

5496
*libudev* is used to discover and monitor USB devices. It is closely tied to *systemd*. So the library only runs on Linux distributions with *systemd* and the related libraries. The majority of Linux distributions suitable for desktop computing (as opposed to distributions optimized for containers) fulfill this requirement.
5597

56-
Similar to macOS, a Java application can connect to any USB device and claim any interfaces that aren't claimed by an operating system driver or another application.
98+
Similar to macOS, a Java application can connect to any USB device and claim any interfaces that isn't claimed by an operating system driver or another application.
5799

58-
Most Linux distributions by default set up user accounts without the permission to access USB devices directly. The *udev* system daemon is responsible for assigning permissions to USB devices. It can be configured to assign specific permissions or ownership.
100+
Most Linux distributions by default set up user accounts without the permission to access USB devices directly. The *udev* system daemon is responsible for assigning permissions to USB devices. It can be configured to assign specific permissions or ownership:
59101

60102
Create a file called `/etc/udev/rules.d/80-javadoesusb-udev.rules` with the below content:
61103

62104
```text
63105
SUBSYSTEM=="usb", ATTRS{idVendor}=="cafe", MODE="0666"
64106
```
65107

66-
This adds the rule to assign permission mode 0666 to all USB devices with vendor ID `0xCAFE`. This unregistered vendor ID is used by test device.
108+
This adds the rule to assign permission mode 0666 to all USB devices with vendor ID `0xCAFE`. This unregistered vendor ID is used by the test devices.
67109

68110

69111
### Windows
@@ -85,20 +127,6 @@ The Foreign Function & Memory API has not been implemented for 32-bit operating
85127

86128

87129

88-
## Documentation
89-
90-
- [Javadoc](https://javadoc.io/doc/net.codecrete.usb/java-does-usb)
91-
92-
93-
94-
## Examples
95-
96-
- [Bulk Transfer](examples/bulk_transfer/) demonstrates how to find a USB device, open it and communicate using bulk transfer.
97-
- [Enumeration](examples/enumerate/) lists all connected USB devices and displays information about interfaces and endpoints.
98-
- [Monitor](examples/monitor/) lists the connected USB devices and then monitors for USB devices being connected and disconnnected.
99-
100-
101-
102130
## Code generation
103131

104132
Many bindings for the native APIs have been generated with *jextract*. See the [jextract](java-does-usb/jextract) subdirectory for more information.
@@ -126,9 +154,3 @@ Or (if modules are ignored):
126154
```
127155
--enable-preview --enable-native-access=ALL-UNNAMED
128156
```
129-
130-
If you don't have the test device, you can get a glimpse at the library running the below command. It enumerates all connected USB devices.
131-
132-
```
133-
MAVEN_OPTS="--enable-preview --enable-native-access=ALL-UNNAMED" mvn install exec:java -Dexec.classpathScope="test" -DskipTests -Dexec.mainClass="net.codecrete.usb.sample.EnumerateDevices"
134-
```

0 commit comments

Comments
 (0)