how i can take data from USB to java ?

Dani AI

Generated

was right for flash drives, but a temperature meter is usually not mass storage. noted a driver and that javax.usb was added; the next step is to see how the OS actually exposes the device. On Windows inspect Device Manager (look under Ports, HID, or the device Details tab for VID/PID). On Linux use lsusb and dmesg (check for a /dev/ttyUSB* or /dev/ttyACM* entry). On macOS use system_profiler SPUSBDataType or ioreg. Identifying the USB class (CDC/ACM, HID, vendor-specific) determines the correct Java approach.

If the device is a virtual COM (CDC) port, a Java serial library is the simplest route (examples: jSerialComm). A minimal read loop with jSerialComm looks like this:

import com.fazecast.jSerialComm.SerialPort;
import java.io.InputStream;

SerialPort sp = SerialPort.getCommPort("COM3"); // or "/dev/ttyUSB0"
sp.setComPortParameters(9600, 8, SerialPort.ONE_STOP_BIT, SerialPort.NO_PARITY);
sp.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 1000, 0);
if (sp.openPort()) {
  try (InputStream in = sp.getInputStream()) {
    byte[] buf = new byte[256];
    int len;
    while ((len = in.read(buf)) > 0) {
      System.out.write(buf, 0, len);
    }
  } finally {
    sp.closePort();
  }
}

If the device is HID or uses a vendor driver, use a HID wrapper (hidapi/hid4java) or a libusb-backed solution. Vendor drivers may claim the device and block libusb/java backends; in that case use the vendor SDK or install a WinUSB-style driver. On Linux add a udev rule for non-root access and ensure native library bitness matches the JVM. Useful projects: jSerialComm, libusb, hidapi. For protocol debugging consider USB captures (usbmon on Linux or Wireshark+USBPcap on Windows).

Recommended Answers

All 4 Replies

If it is a USB drive just like any other file from a regular hard disk.

If it is a USB drive just like any other file from a regular hard disk.

no that data send from machine by USB
how i take it to java as data ?

What type of device is it ?

device measure Temperature ( i have the driver of this )
i do every thing add javax.usb
but, how i can get the USB function to take data from device ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.