Coder Social home page Coder Social logo

hid4java's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hid4java's Issues

Shameless plug for Pure Java HIDAPI

Hi,

sorry to abuse the issue system and hope you don't mind but I felt that some small group of hid4java users might be interested in a different take on the subject matter and I could not figure out how to reach them.

With the help of reading the HIDAPI code I've managed to put together a Pure Java alternative that requires no native libraries when deployed and no C-tool chain to develop:

You can find it here:

https://github.com/nyholku/purejavahidapi

This is not really an alternative to signal11/HIDAPI as this is Jave or actually JVM only where as HIDAPI is C-API/ABI.

br Kusti

Write not working with Windows 7

Hi,

this might be related to issue #13.
We were having problems using the write function in HidDevice - we had it working with Windows 8.1 and 10, but it didn't work in Windows 7.Digging a little bit we found about the Report ID problem with Windows platforms, that it should be set to 0x00 (as seen here: signal11/hidapi#253). We are working with version 0.4.0.

The problem might be within the write called from HidApi, where the if clause for reportId == 0 ends up sending the data without an ID.

if (Platform.isWindows() && reportId == 0) {
      // Compensate on Windows for 0x00 report ID misalignment
      // This avoids "The parameter is incorrect" on Windows
      report = new WideStringBuffer(len);
      if (len > 1) {
        System.arraycopy(data, 0, report.buffer, 0, len);
      }
    } else {
      // Put report ID into position 0 and fill out buffer
      report = new WideStringBuffer(len + 1);
      report.buffer[0] = reportId;
      if (len > 1) {
        System.arraycopy(data, 0, report.buffer, 1, len);
      }
    }
    return hidApiLibrary.hid_write(device.ptr(), report, report.buffer.length);

We could make things work with Windows 7 by sending a data array with an extra 0x00 byte in position 0 and the data starting in position 1 (which happens to be what the else clause does for reportId != 0), and using a reportId = 0, so we kind of bypassed the write from HidApi.

Should this if clause work like this? Am I missing something here?

Support for Yubico (and other devices showing up as keyboard or mouse)

Hello,

I am trying to use the hid4java library with a Yubikey dongle (VID 0x1050, PID 0x0114). Among others, the Yubikey supports a HmacSha1 challenge-response mechanism via feature reports.

I tested the hid4java library using the 'UsbHidTrezorV1Example' examples, but replacing the trezor VID and PID with the Yubikey one.

The hid4java library find two devices with the given VID and PID (it's actually the same device):
HidDevice [path=?\hid#vid_1050&pid_0114&mi_00#8&a6f8690&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}, vendorId=0x1050, productId=0x114, serialNumber=null, releaseNumber=0x340, manufacturer=Yubico, product=Yubikey NEO OTP+U2F, usagePage=0x1, usage=0x6, interfaceNumber=0]
&
HidDevice [path=?\hid#vid_1050&pid_0114&mi_01#8&2e46c452&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}, vendorId=0x1050, productId=0x114, serialNumber=null, releaseNumber=0x340, manufacturer=Yubico, product=Yubikey NEO OTP+U2F, usagePage=0xfffff1d0, usage=0x1, interfaceNumber=1]

However, it cannot attach to the Yubikey device apparently:
HidDevice trezor = hidServices.getHidDevice(VID, PID, null) returns null
=> "Waiting for Trezor attach..."

Any idea why it fails to attach to the device?
I am working on Windows 8, intel64 (x64) processor

Using the SimpleHIDwrite utility (http://janaxelson.com/files/SimpleHIDWrite3.zip), I can confirm that I am able to send feature reports to the Yubikey and receive response...

Best regards,

Toporin

New version (0.5) and dependencies

When is new release planned?

Would it be possible to upgrade jna dependencies to latest/last 4.x (which would be 4.2.2)? I will do some tests over weekend if it works (at least on linux)...

Andy

Classes in root package

Do not add classes to the default (root) package, this is bad style and causes errors using maven to build projects.
Currently the class UsbHidTrezorV1Example.class is located in the root package.

You can no longer import from default packages. (You used to be able to in Sun's early javac implementations, but this was not allowed for in the language spec.)

1-byte Reports do not get written correctly

I think there is an off-by-one error in the "write" method of org.hid4java.jna.HidApi:

The JavaDoc says the Report data should not include the Report ID. It will get prepended to the data automatically.
However, both the Windows- and regular code path execute the arraycopy only if the data length is larger than 1. Thus, a 1-byte Report gets written out, but not including the supplied data...
I think it should be "if (len >= 1) {".

Kind regards,
Stefan

Can't read port in Windows 8.1

Hi, thank so much for the Api is very useful for me.Actually i'm working in a device that have a set of external sensors like Temperature, Humidity, Light ,etc. It´s device report an array of byte when it is writing a command every x interval.

My trouble is only in Windows can't read the response from my device.

This method write a command in to device, REPORT_ID = (byte) 0

    public int write(byte command) {
        byte[] data = new byte[1];     
        data[0] = command;
        int result = currentDevice.write(data, data.length, REPORT_ID);
        return result;
    }

This try to read port every 100 ms.

    public void report() {
        timer.schedule(new TimerTask() {
            public void run() {
                byte inBuffer[] = new byte[PACKET_LENGTH];
                int val = currentDevice.read(inBuffer);
                switch (val) {
                    case -1:
                        //System.err.println(currentDevice.getLastErrorMessage()); always throw null
                        break;
                    case 0:
                        break;
                    default:
                        if (inBuffer != null) {
                            reportData(inBuffer);
                        }
                        break;
                }
            }
        }, 0, 100);
    }

I tested the same code in Mac and worked perfectly.

What am I doing wrong?

Thank in Advance.

Library not working on MAC OS (10.7)

Hello,

first of all thank you for the great work you did, this library is really making my project easier :)

Unfortunately, I have a small problem.....everything is working fine under windows, but when I move to a MAC, I am not even able to read the attached device....when I send an initial "hello" message to discover the unit, the whole interface freezes (I created a small Swing GUI).

Do you have any idea how I should set the system? I tried to look in the /resources folder for a library for MAC OS, but I did not find the folder.

I am completely unexperienced with MAC, but I need my project to work even there, so if you can give me a hint this would be extremely welcome.

Thank you once again,

best

Lorenzo

how to add hid4java to my project?

Hi
I'm working on a java project in netbeans and i want to use usb hid, how can i add hid4java to my project?
Can i use jar file of hid4java for library?
please teach me step by step to add your library to my project.
Thanks

Unable to Open Device Handle

I am using a DS6878 Barcode Scanner (in HID mode) on OS X. I am running the example code which enumerates the devices allows me to see attached and detached events. However, open always returns false, and my OS retains ownership of the interface. hidDevice.getLastErrorMessage() returns Device not initialised.

JVM crashed

Sometimes JVM is crashed after closing the device in Linux. In Windows it not appear.
I use Ubuntu 16.04

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f1031548352, pid=5125, tid=0x00007f105a872700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_112-b15) (build 1.8.0_112-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.112-b15 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libusb-1.0.so.0+0x8352]  libusb_submit_transfer+0x142
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/anama/Projects/JavaUsb/hs_err_pid5125.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)`

Class for test it( this is UsbHidTrezorV1Example):


import org.hid4java.*;
import org.hid4java.event.HidServicesEvent;

/**
 * <p>Demonstrate the USB HID interface using a production Bitcoin Trezor</p>
 *
 * @since 0.0.1
 *
 */
public class TestUSB implements HidServicesListener {


    private static final short VENDOR_ID = (short) 0xfc58;
    private static final short PRODUCT_ID = (short)0x0001;
    private static final int PACKET_LENGTH = 64;
    public static final String SERIAL_NUMBER = null;

    public static void main(String[] args) throws HidException {

        TestUSB example = new TestUSB();
        example.executeExample();


    }

    public void executeExample() throws HidException {

        // Configure to use custom specification
        HidServicesSpecification hidServicesSpecification = new HidServicesSpecification();
        hidServicesSpecification.setAutoShutdown(true);
        hidServicesSpecification.setScanInterval(500);
        hidServicesSpecification.setPauseInterval(5000);
        hidServicesSpecification.setScanMode(ScanMode.SCAN_AT_FIXED_INTERVAL_WITH_PAUSE_AFTER_WRITE);

        // Get HID services using custom specification
        HidServices hidServices = HidManager.getHidServices(hidServicesSpecification);
        hidServices.addHidServicesListener(this);

        // Start the services
        System.out.println("Starting HID services.");
        hidServices.start();

        System.out.println("Enumerating attached devices...");

        // Provide a list of attached devices
        for (HidDevice hidDevice : hidServices.getAttachedHidDevices()) {
            System.out.println(hidDevice);
        }

        // Open the device device by Vendor ID and Product ID with wildcard serial number
        HidDevice hidDevice = null;
        for(int i=0;i<30;i++) {

            hidDevice = hidServices.getHidDevice(VENDOR_ID, PRODUCT_ID, SERIAL_NUMBER);
            if (hidDevice != null) {
                System.out.println(i);
                sendMessage(hidDevice);
            }
        }

        // Shut down and rely on auto-shutdown hook to clear HidApi resources
        hidServices.shutdown();

    }

    @Override
    public void hidDeviceAttached(HidServicesEvent event) {

        System.out.println("Device attached: " + event);

        // Add serial number when more than one device with the same
        // vendor ID and product ID will be present at the same time
        if (event.getHidDevice().isVidPidSerial(VENDOR_ID, PRODUCT_ID, null)) {
            sendMessage(event.getHidDevice());
        }

    }

    @Override
    public void hidDeviceDetached(HidServicesEvent event) {

        System.err.println("Device detached: " + event);

    }

    @Override
    public void hidFailure(HidServicesEvent event) {

        System.err.println("HID failure: " + event);

    }

    private void sendMessage(HidDevice hidDevice) {

        // Ensure device is open after an attach/detach event
        if (!hidDevice.isOpen()) {
            hidDevice.open();
        }

        hidDevice.close();

    }


}

I use cycle for catch problem, but jvm crashed periodically without open-close cycle

Problems with hid.read callback on OSx

Hello Gary,

after a few months, here I am again asking for your help.
I was finally able to use your library for transmitting some data from our MAC to our HID device.
The transmission direction (hidDevice.write) works flawlessly.
Due to a redesign of the application, we wanted to add the reverse channel, namely we want the device to return some data when the control software asks to do so.
Well, this works fine on Windows, but on OSx the application blocks when calling the hidDevice.read() instruction. I am trying to understand what happens, but there is no exception thrown and no debug message. The application simply freezes (it does not even shutdown).

Do you have any suggestion on how to find the error?
In my code, the read() instruction is called after the write() (I will send a command code to the device, telling it that I need some data, and it should reply with those data).
Again, this works fine in Windows.

Thanks for your precious support,

Best

Lorenzo

Reopen device

Hello,

I developed a desktop application based on your wonderful library (many thanks!!).

I start the connection using:

public void open() throws IOException {
        if (!this.dev.open()) {
            throw new IOException();
        } else {
            report_size = dev.getFeatureReport(new byte[1000], report_id);
            if (report_size < 0) {
                throw new IOException();
            }
        }
    }

And close the connection like this:

public void close() {
        while (dev.isOpen()) {
            this.dev.close();
        }
    }

note that dev is of class HidDevice.

The device only uses the Feature Report to dialog with the host.

Sometimes (many times), the dev.open() method fails (return false), especially when the connection is opened a few seconds after it has been closed.

Physically the cables or device is not touched. This happens when the user chooses a device to connect (the application can handle several connections, one at a time), or, when the application is closed, and the connection is also closed (before the application).

The workaround is disconnect and reconnect the USB cable on the device....

My question, is if this is the proper way to close a connection? Is there something else that I should do to prevent errors in a re-connection?

Thanks.

Device not initialized

I am attempting to open a device (A Buzz! controller) to be written to. Unfortunately, the writes don't seem to be working, Upon printing the last error message, it tells me "Device not Initialized". The String representation of the device is like this:

HidDevice [path=\\?\hid#vid_054c&pid_0002#6&1795862b&2&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}, vendorId=0x54c, productId=0x2, serialNumber=null, releaseNumber=0x1101, manufacturer=Logitech, product=Logitech Buzz(tm) Controller V1, usagePage=0x1, usage=0x4, interfaceNumber=-1]

Any help would be appreciated.

Native part loading and missing library

You need to add class for loading native parts from jar... Project nrjavaserial uses something similar and it work great...
Library for linux x64 is missing at least one version of it, you need to create linux-amd64 directory and copy from linux-x86-64 (leave that one here).

HidDevice.onInputReport not supported

This is more kind of a feature than a bug!

I found https://github.com/nyholku/purejavahidapi to support above feature among others. However purejavahidapi library does not support listeners on device addition (only removal is supported) - so I am not going to keep using that library only if hid4java library is going to support arbitrary retrieval of data from HID devices.

HID devices can send arbitrary data on certain events (such as key presses) and hid4java as of now does not support this. Could anybody look into implementing this feature.

Thanks in Advance!

HidServices.getHidDevice( ... ) returns NULL when device is attached on Windows 10

I've built the Maven project and extracted the resultant JAR file to use as a reference in a test project.

I have the following code snippet :

public static boolean Initialize() throws HidException{
    if (JR3Controller.Ctor != null) return true;
    JR3Controller.Ctor = new JR3Controller();
    JR3Controller.Ctor.mgr.addHidServicesListener(JR3Controller.Ctor);
    return JR3Controller.Ctor.dev != null;
}

private JR3Controller(){
    this.mgr = HidManager.getHidServices();
    this.dev = this.mgr.getHidDevice(0x0003, 0x1001, null);
    if (this.dev != null){ /*Do Stuff; Doesn't matter, dev is always null*/ }

Following the code execution, I can see that this.mgr is being set to a non-null value, but when I try to open my device, well, it fails...

This was the same issue I was running into using the Java HIDAPI library (which, coincidentally, is why I switched over to hid4java).

Something I read somewhere said that Windows 10 hijacks devices that are connected to the system as soon as they are connected (My knowledge of such things is nil, however); could this be the problem here? Am I doing something incorrectly?

EDIT : I believe that signal11/hidapi#231 may have something to do with this problem...

hid4java Device Scanner crashes on mac after 30-40 seconds

Hi Gary,

Thanks for this great library! It works great except that as soon as I connect to a HID device (through HidDevice#getHidDevice) my JVM commits suicide after 30-40 seconds, complaining about a SIGSEV in the "hid4java Device Scanner" daemon thread.

Do you have any idea what that could be? I'm attaching a recent crash log, that should have all the relevant information. Thanks!
hs_err_pid40191.txt

Support Java 1.6 (and below if possible)

Hi !

I have application which is built with Java 1.5. Is there specific reason, why Java 7 is used... I have seen that JNA 4 is done with 1.7, is this the only reason? Would it be possible to create 1.5 binaries? I mean I can build them, question is what was reason to use J7?

Take care,
Andy

Groovy script for DYMO M10 scales

I have some simple Groovy to read from DYMO M10 scales.

It works the first time when run, but then the device is never found again until a complete shutdown of the environment
Any clues???

import org.hid4java.*
import org.hid4java.jna.*

Short VENDOR_ID = 0x0922
Short PRODUCT_ID = 0x8003
message = new byte[8]
hidServices = HidManager.getHidServices()
devices = hidServices.getAttachedHidDevices()
//hidServices.addHidServicesListener()
dymo = hidServices.getHidDevice(VENDOR_ID, PRODUCT_ID, null)
if (dymo){
	val = dymo.read(message, 1000)
}
hidServices.shutdown()
if (dymo){ 
	return message[0] + ' ' + message[1] + ' ' + message[2] + ' ' + message[3] + ' ' + message[4] + ' ' + message[5] + ' ' + message[6] + ' ' + message[7] 
} else {
	return 'not found'
} //end if

Minor bug found

Hello Gary,

I must tell you I am really enjoying your library, it is working really fine :)

I just wanted to inform you that I found a minor bug in your code....nothing serious and easy to fix ;)

In class HidDevice.java, on line 66, you have a method called

public String getId()

which should return a string made of vid + pid + serial_number.

Well, the current code was returning the path :)

I fixed it in my code, I thought you would have liked to know it ;)

Best and once again thank you for your work.

Lorenzo

Improve device identification

Some HID devices use more than one interface. For that case, I suggest that you include the interface number in HidDeviceInfo.getId() or - maybe even better - just use the unique device path as ID.

Windows takes a long time to start hidapi

Sometimes during development you'll get a JVM crash with a message like

siginfo: ExceptionCode=0xc0000005, reading address 0xffffffffffffffff

On Windows, this will cause an opportunistic lock on the DLL causing very slow startup times (15-20s). The quickest way to fix this for a developer is to simply reboot.

Creating Runnable jar file

I have everything working so far within Eclipse project.
I exported to create a Runnable jar file.
The gui comes up but no usb connection.
When I run from cmd line with console enabled, I get a resource not found error.
See console text below.
I tried exporting several ways but similar issue.
When I open the jar file, I see a resources\win32-x86-64 folder with the hidapi.dll in it.
I am sure it is something simple I am overlooking, but I can't find it.

Manifest
Manifest-Version: 1.0
Class-Path: .
Main-Class: mxUSB.MXBootTool
"
C:\Users\r12528\Desktop>java -jar iMX_Boot_Utility.jar
Launching application...
Operating System : Windows 7 6.1
Java Version: 1.8.0_91
Java Home: C:\Program Files\Java\jre1.8.0_91
Showing GUI.
Loading hidapi...
Exception in thread "AWT-EventQueue-0" org.hid4java.HidException: Hidapi did not
 initialise: Unable to load library 'hidapi': Native library (win32-x86-64/hidap
i.dll) not found in resource path ([file:/C:/Users/r12528/Desktop/iMX_Boot_Utili
ty.jar])
        at org.hid4java.HidDeviceManager.<init>(HidDeviceManager.java:89)
        at org.hid4java.HidServices.<init>(HidServices.java:88)
        at org.hid4java.HidServices.<init>(HidServices.java:76)
        at org.hid4java.HidServices.<init>(HidServices.java:63)
        at org.hid4java.HidManager.getHidServices(HidManager.java:50)
        at mxUSB.MXConnectUSB.<init>(MXConnectUSB.java:57)
        at mxUSB.MXBootTool.createAndShowGUI(MXBootTool.java:92)
        at mxUSB.MXBootTool$1.run(MXBootTool.java:85)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$500(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionP
rivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

Reopen device causes null device

Hello, I already wrote my issue here but I think it may be better to open it as a new one.
Hello! I am writing you because I have been days struggling with an error. I am experiencing a similar issue as @xgonc . There is one special functionality (all others work cross-platform but this one is not working on windows 7) that I have developed to update the firmware of a control board with which I am communicating with using your library.
To be able to access the flashing mode of the board, I have to disconnect first from the board in normal mode (which has a productId = 0x0001 for example), and access the bootloader mode that lasts 2 seconds after the board is restarted, being this mode with productId = 0x1001. To do so, I send a restart command to the board, wait, and try to connect to the bootloader mode. This is working well under Ubuntu 14, Windows 8.1 and Windows 10 so far, but under Windows 7 it always throw the same exception:

java.io.IOException: Cannot read from USB device!

So, the error jumps in when I never unplug the USB of the board but just send a restart command and try to connect ,BUT if I unplug and plug it again and try to flash the board withing those 2 seconds that the mode is open...it works!

This error seems very weird to me because after deep debugging for days I have managed to see that when trying to connect to this bootloader mode after the restart command, which involves a disconnection of previous mode and re-connection to another mode (for the program a new USB device), the detection actually works but is the read() which fails returning getLastErrorMessage(): "device is not connected".

When trying to communicate I first do:

device = hidServices.getHidDevice(VENDOR_ID, deviceMode.getValue(), null);

if (device != null)
{
    System.out.println("CONNECTED");
}

Which prints CONNECTED on the bootloader mode!

But then, deviceRead() throws java.io.IOException: Cannot read from USB device!

public byte[] deviceRead() throws IOException
    {
        final byte[] data = new byte[200];
        int read = 0;

        read = this.device.read(data, 250);

        /* Error occurred - nothing read */
        if (read < 0){
            throw new IOException("Cannot read from USB device!");
            //read = 0;
            //System.err.println("USBHID LAST ERROR MESSAGE: " + device.getLastErrorMessage());
        }

        byte[] ret_val = new byte[read];
        for (int i = 0; i < read; i++)
            ret_val[i] = data[i];

        return ret_val;
    }

Due to

public static HidDeviceStructure open(String path) {
    Pointer p = hidApiLibrary.hid_open_path(path);
    return (p == null ? null : new HidDeviceStructure(p));
  }

Is returning P = null.

I have already tried re-initializing the library when disconnecting, using single instances of the library objects as some other issues here recommend...everything with no luck.

Any help/idea/holy-light would be really really helpful. I am breaking my mind here trying to understand why is not working and I am pretty sure I am missing something important.

Have a great day!

Multiple devices with the same vid and pid

Hi,
Thx for making this library, I have encountered a few issues with usb4java ;) I have a question - there can be attached multiple devices with the same vid and pid. How then hidServices.getHidDevice will react?

unable to open device

I see my device when using getAttachedHidDevices but it doesn't open:

for (HidDevice hidDevice : hidServices.getAttachedHidDevices()) {
    if (hidDevice.isVidPidSerial(0x077d, 0x0410, null)) {
        System.out.println(hidDevice);
        System.out.println(hidDevice.open());
    }
}

Output:

HidDevice [path=\\?\hid#vid_077d&pid_0410#7&325c568b&1&0000#{4d1e55b2-f16f-11cf-
88cb-001111000030}, vendorId=0x77d, productId=0x410, serialNumber=?, releaseNumb
er=0x400, manufacturer=Griffin Technology, Inc., product=Griffin PowerMate, usag
ePage=0xc, usage=0x1, interfaceNumber=-1]
false

I'm at a loss. Any ideas?

I'm on Windows 7.

Missing linux-arm/libhidapi.so

In the maven bundle version 0.4.0 there is no native code for arm. But there is a file "libhidapipi.so" in the root of the jar, shall that be the arm library?

Writes of 1 byte size doesn't work fine

Writing one byte size always writes 0. This seems to be because of the following conditional that checks for above one byte.
File org.hid4java.jna.HidApi.java

Function write:
public static int write(HidDeviceStructure device, byte[] data, int len, byte reportId)

Section:
} else {
// Put report ID into position 0 and fill out buffer
report = new WideStringBuffer(len + 1);
report.buffer[0] = reportId;
if (len > 1) {
System.arraycopy(data, 0, report.buffer, 1, len);
}
I did the following:
} else {
// Put report ID into position 0 and fill out buffer
report = new WideStringBuffer(len + 1);
report.buffer[0] = reportId;
if (len > 0) {
System.arraycopy(data, 0, report.buffer, 1, len);
}

Device scanning interferes with keyboard key presses

Ever since I integrated hid4java into my project I've noticed that when my application is running my USB keyboard behaves oddly. Specifically what happens is that when I'm typing on my keyboard (in another application) the occasional keyboard key press gets duplicated. So if I were to type hello world into an application like Notepad the result may actually be helloo world (notice the duplicate oo). Exiting my application that is using hid4java resolves the issue and future key presses are accurate.

Today I decided to investigate this problem a bit further and I think I've narrowed it down to something that may be helpful. I believe the issue is related to the device scanning. Because if I disable device scanning by passing a value of 0 to the scanInterval param of the HidServices constructor the problem goes away.

I'm observing this issue when running my application on Windows 7 64-bit. I also run my application on a Raspberry Pi, but I haven't noticed the same problem there.

Java 1.5 issue "undefined symbol: libusb_init" on Linux

Hi !

I used 0.3.1 for testing so far, now my library (classes) is ready for production, so I build 0.4.0 version locally, but now when I try to run it, I get problem with binary file (I use linux-amd64). This is what I get...

symbol lookup error: /home/andy/workspaces/andy-iplayground4/ggc/hid4java/target/classes/linux-amd64/libhidapi.so: undefined symbol: libusb_init

Do I need any special dependencies on system to run with new version?

And before you ask, I build my own version because I need 1.5 compatibility.

Andy

Scanning for attached/detached devices

Hi,

two ideas about the scanning for changed devices:
1.) The 500ms intervall cannot be changed when starting the api. It would be great to have that configurable.
2.) The automatic scanning can be stopped but not restarted. I could build my own thread to scan for devices easily (fixing #1 as well), but as you already have that functionality, why not reusing it.

Kind regards,
Peter

Support for ARM

Hi!
I am working on embedded application that is running on ARM Linux. Is there any instruction on how to enable hid4java on ARM environment? I was able to find manual only for javahidapi. Am I correct that SO file has to be saved under linux-arm/libhidapi.so inside hid4java-0.4.0.jar. And if so, is it possible to add pre-compiled library in hid4java repository for everyone else to use?

Take care,
Max

Improved Error Handling

Hi!

It would be great to have a little better error handling, especially two scenarios, I have just encountered:
1.) on Linux, you need write access to the devices to open them. The corresponding error message is printed to stderr, but HidDevice.open() simply fails (returns false). An exception or error code would be great to indicate missing privileges.
2.) when a device is detached, read() returns with -1, indicating an error. The corresponding error message (HidDevice.getLastErrorMessage()) even tells you, that the device is not attached - but again as this is a localized String, it is hard to react on it. E.g. if the read fails, because the device is not attached, I would like to stop reading at all. On another error, I could want to retry.

Kind regards,
Peter

hid write not sending correct number of bytes

I just started working on a project to communicate with a hid device.
Since the Java app needs to run on Windows and Linux(maybe Mac down the road), I thought hid4java would be a good fit.
I was able to get everything working and I can connect to my device.
The issue I have and can't figure out is:
When I send a 16 byte packet plus 1 byte report ID set to 0x01, the return bytes written length is 1025.
I can't seem to understand why I am getting 1025 vs 17. This is causing my hid read to be too big and after the initial few bytes, wrong data.
I am running on Windows 7 x64.

To be more specific, I put a print statement right after this call in HidApi:
int res = hidApiLibrary.hid_write(device.ptr(), report, report.buffer.length);
res is equal to 1025 after the call.
report.buffer.length was equal to 17 right before the call.

Any idea why I may be getting a different return value?

Thanks,
Brett

String descriptors constantly accessed on Windows 7

I developed a small app using hdi4java. The app works great and as expected on Mac, but when I try the same jar file on Windows 7 64bit the string descriptors are constantly being read from the device. This happens when I start the HID Services (i.e. hidServices = HidManager.getHidServices();), so the problem is occurring before connecting to any device. I can see the string descriptors constantly going by on the USB analyzer.
Has anyone seen this behavior before?

Unfortunately I don't have access to a Windows 8/10 or Linux machine to see if the problem exists on other OS's.

Thanks,

Running in Linux (Ubuntu 15/10)

Hello,

I built my application to a single JAR file, and it works as expected in Windows 7/8, and Mac (mountain lion). However in Ubuntu 15/10 I see the devices with lsusb, but I cannot get them from the Java code. I suspect this a dependency issue.
Libusb is installed in a non standard location, so I created a symbolic link like this:
/usr/lib/libusb.a -> /usr/lib/i386-linux-gnu/libusb.a

I don't have any more clues to solve this...

Note java installed:
java version "1.7.0_85"
OpenJDK Runtime Environment (IcedTea 2.6.1) (7u85-2.6.1-5)
OpenJDK Server VM (build 24.85-b03, mixed mode)

Please help me. Thanks.

Attempting to run sample program errors out (Windows 10)

I'm switching over from Java HIDAPI to HID4Java.
I am running JNA 3.5.2.

The exception message I'm getting is :

Exception in thread "main" org.hid4java.HidException: Hidapi did not initialise: Unable to load library 'hidapi': JNA native support (win32-x86/hidapi.dll) not found in resource path (C:\Users\Will\Documents\NetBeansProjects\Libraries\jna-3.5.2.jar;C:\Users\Will\Documents\NetBeansProjects\Libraries\platform-3.5.2.jar;

Likely it means that I'm doing something wrong but... I don't know what it is.

I'm running Windows 10 (x64) on a 32 bit JVM (for logistical reasons - some people run dinosaurs).

Please, help?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.