Comments (17)
I should have read the FAQ better, my problem sounds a lot like the "SIGSEV (0xb)" question. That said, I'm afraid the answer doesn't tell me much and I'm at a loss as to what I'm doing wrong. I'm having a very minimal script that I'm trying to run. I apologize, it's in Clojure, I hope that's not an issue:
(ns cheekyled.core
(:gen-class)
(:import [org.hid4java HidDevice HidDeviceManager HidManager HidServices HidServicesListener]
[org.hid4java.event HidServicesEvent]))
(defn hid-services []
(let [p (proxy [HidServicesListener] []
(hidDeviceAttached [e] (prn 'ATTACHED e))
(hidDeviceDetached [e] (prn 'DETACHED e))
(hidFailure [e] (prn 'FAILURE e)))
services (HidManager/getHidServices)]
(.addHidServicesListener services p)
services))
(defn attached-devices []
(.getAttachedHidDevices (hid-services)))
(defn write [device message packet-length report-id]
(.write device message packet-length (byte report-id)))
(defn find-led []
(let [vendor 0x1d34
device 0x0013]
(.getHidDevice (hid-services) vendor device nil)))
(defn with-led [f]
(let [led (find-led)]
(f led)
(.close led)))
(defn write-diamond [led]
(let [diamond [[0x00, 0x00, 0xFF,0xFE,0xFF, 0xFF,0xFD,0x7F,],
[0x00, 0x02, 0xFF,0xFB,0xBF, 0xFF,0xF7,0xDF,],
[0x00, 0x04, 0xFF,0xFB,0xBF, 0xFF,0xFD,0x7F,],
[0x00, 0x06, 0xFF,0xFE,0xFF,]]]
(doseq [row diamond]
(write led (byte-array row) 8 0))))
This works if I run a (with-led (find-led) write-diamond)
but crashes 30 seconds later. I can't see a difference to your UsbHidTrezorV1Example that would explain to me what you mean by your FAQ answer.
from hid4java.
Hi there,
@mgerlach-klick just to complement, I also had some issues with this SIGSEV crash on my mac (OSX 10.11.3). As I don't need the automatic scanning right now, I didn't investigate further the problem and I ended up using a lower level scan process (using the hidApi enumeration). However, I'm willing to cooperate.
@gary-rowe any plans for a next release? 👍
Thanks again.
from hid4java.
@gabrielpaim Any chance you have a code snippet somewhere that I could have a look at?
from hid4java.
Nevermind, I figured it out! This now works!
(ns cheekyled.core
(:gen-class)
(:import [org.hid4java HidDevice HidDeviceManager HidManager HidServices HidServicesListener]
[org.hid4java.event HidServicesEvent]
[org.hid4java.jna HidApi]))
(defn write [device message packet-length report-id]
(.write device message packet-length (byte report-id)))
(defn find-led []
(let [vendor 0x1d34
device 0x0013]
(HidDevice. (HidApi/enumerateDevices vendor device))))
(defn with-led [f]
(let [led (find-led)]
(.open led)
(f led)
(.close led)))
(defn write-diamond [led]
(let [diamond [[0x00 0x00 0xFF 0xFE 0xFF 0xFF 0xFD 0x7F ]
[0x00 0x02 0xFF 0xFB 0xBF 0xFF 0xF7 0xDF ]
[0x00 0x04 0xFF 0xFB 0xBF 0xFF 0xFD 0x7F ]
[0x00 0x06 0xFF 0xFE 0xFF]
]]
(dotimes [i 10]
(doseq [row diamond]
(write led (byte-array row) 8 0))
(Thread/sleep 100))))
from hid4java.
Glad you managed to figure it out, and good to see a nice example of using the library with Clojure. Thank you for posting it.
I'm not sure why the scanning thread would cause SIGSEV crash, but I'll take a look and see if I can replicate it. Will be a good excuse for me to sharpen my Clojure skills...
from hid4java.
Thank you Gary, I appreciate you looking into it! Let me know if you'd like some help to get it set up as a Clojure project or if you'd like me to upload the whole thing somewhere!
from hid4java.
No worries. If you happen to have an example in Clojure that I could use as a launch pad that would be grand. I'm pretty flexible and I use Intellij 15 for development. Just pop something into github with a few basic instructions for a Java bod and I should be fine.
from hid4java.
Here you go: https://github.com/mgerlach-klick/cheekyled
This includes the working implementation (core.clj), the crashing implementation (crash.clj) and some experiments with the purejavahidapi that you can ignore :)
Just import the project into IntelliJ (presumably you will want to install the Cursive Clojure plugin, but I don't use IntelliJ and can't really tell you how to do that), run a REPL and evaluate the full crash.clj file. Then, in the repl (make sure you're in the in the cheekyled.crash namespace), evaluate (hid-services)
. After pretty exactly 30 seconds it'll crash. Let me know how it goes and thank you!
from hid4java.
OK. Thanks - that's really helpful. It's a bit late here (UK time) so I'll probably get started on it tomorrow.
from hid4java.
For those still suffering this bug, calling shutdown()
on the HidManager.getHidServices()
object after you're done listing the devices (e.g. sometime soon after services.getAttachedHidDevices()
) on Mac seems to prevent the random crashes.
Side note... There's still a second (seemly unrelated) crash that seems to occur randomly when the Java application closes, but it's too intermittent to provide steps for at this point and it's relatively benign as the by then the application had been used properly and a crash report will only popup up on close.
from hid4java.
Update... We're running several hours stable now after the following changes:
Intermittent crashes
- Calling
shutdown()
on theHidManager.getHidServices()
object after you're done listing the devices (e.g. sometime soon afterservices.getAttachedHidDevices()
) on Mac seems to prevent the random crashes.
Releasing device crash
- Remove this line:
hid.c#L1025
, recompile on a suitable Mac build environment, re-bundle.
More
- Optional additional unmerged fixes: mrpippy/hidapi@75b8627
from hid4java.
I'll see if I can include those changes into the bundled libraries for 0.6.0.
from hid4java.
@gary-rowe I'm working with my team to bump hid4java and was wondering if you had a list of patches that you apply on top of hidapi before a release so we know whether or not to ship our own hidapi with the above patch?
from hid4java.
Apologies for the slow response. I don't do anything special to hidapi
before compilation - it's straight from the master
branch of libusb/hidapi
.
from hid4java.
@gary-rowe gotcha, thanks.
Releasing device crash
- Remove this line:
hid.c#L1025
, recompile on a suitable Mac build environment, re-bundle.
Since upstream has changed considerably, I'll retest. The line mentioned isn't changed, but I also don't see @mrpippy
's patches, so if it continues with the latest, I'll open a new bug report and track accordingly.
from hid4java.
Streaming on MacOS has been consistent both after suspend and without suspend/hibernate for over 72 hours :)
Edit: This is with hid4java-0.7.0.jar
from hid4java.
Good to know. Thanks for revisiting this one, @tresf.
from hid4java.
Related Issues (20)
- HID write always fails with 64bit OS running under Raspberry PI 4 HOT 2
- setAutoDataRead(true) - nothing happens, program waits forever HOT 2
- Add module name HOT 3
- I am not scanning my device using UsbHidEnumerationExample. Do I need to do anything to set the MAC? HOT 6
- Event hidDataReceived not working. HOT 2
- Option to open device in non-exclusive mode HOT 1
- When will 0.8.0 be released as example code doesn't compile when tried with latest published jar? HOT 7
- Support for Raspberry pi 4 HOT 4
- MacOS ARM incompatible HOT 3
- Unable to open connection to multiple identical devices HOT 1
- HidApi.read returning -2(DEVICE_ERROR) and "Device not initialised" seen when trying to fetch SN, PID HOT 4
- Specify minimum JNA version required HOT 1
- hid4java always uses the libusb variant of libhidapi on linux-x86-64 HOT 1
- support hidapi 0.14.0 HOT 2
- Branch cleanup HOT 1
- Update MVN repository content
- USB HID Set Report and Get Report HOT 10
- How can i read the scanner data. HOT 3
- Pre-release checklist for 0.8.0
- Regression in `hidApiLibrary.hid_open_path(path)` v 0.8 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hid4java.