Aren't there any system calls or OS specific functions that can be called by Java to get just the names of the USB devices attached?
I've seen probably 6-7 questions here only, but everyone mentions the C++ functions GetRawInputDeviceList() etc, and they are not cross-platform compliant. Either for Windows in C# or C++ or for Linux only.
But I'm working in Java. Also, this needs to be cross platform.
Atleast, it needs to be working for Windows,Linux and Mac. I can work with terminal/shell/command-prompt commands also. I guess I can run them with Java.
I've tried getFileSystemView and listRoots. But they give out names of all drives [dvd, hdd partitions,floppy etc].
I need to get only USB devices.
Please don't mention jUSB or JSR080. Why:
jUSB: access to USB devices currently requires that they be connected to a GNU/Linux host system
javax.usb: pre-alpha Windows implementation is not certified and requires a kernel driver.
usb4java: basically, it just implements JSR80 with little more abstraction, perhaps
Although to be honest I haven't tried libusb since it is in C++.
If you are going to mention APIs, mention completely tested and tried ones, that work across Linux,Windows and Mac.
If that wasn't the case, I wouldn't have put this question up. I've seen the mention of jUSB, javax.usb, etc on many other posts.
You can use the jUsb API, for Linux.
Or you could launch the terminal in Linux using the Process class, and run
ls -la /dev/disk/by-id/usb-* and catch the stdout to know the results.
For Windows, you can try this : How to find my USB flash drive's path with PowerShell
EDIT:
For Windows, another helpful utility is the devcon.exe.
For more info, check this.
EDIT 2:
For Mac, you could launch the terminal using the Process class, and run system_profiler SPUSBDataType
Yoy can try javahidapi. I think it some c/c++ code and JNI. Declarated linux, mac and windows support. I have tried it with linux (ok), with clean windows in virtual box (not ok, UnsatisfiedLinkError, i think some MSVS libs was missed). If you'll compile it from source, it should work, i belive.
here is example:
import com.codeminders.hidapi.HIDDeviceInfo;
import com.codeminders.hidapi.HIDManager;
public class TestHid {
public static void main(String[] args) throws Exception {
try {
com.codeminders.hidapi.ClassPathLibraryLoader.loadNativeHIDLibrary();
HIDManager hidManager = HIDManager.getInstance();
HIDDeviceInfo[] infos = hidManager.listDevices();
for (HIDDeviceInfo info : infos) {
System.out.println("info: " + info.toString());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
EDIT
output shows only one plugged in usb device, genius laser mouse.
[grigory#gr testRSA]$ pwd
/home/grigory/testRSA/out/production/testRSA
[grigory#gr testRSA]$ whoami
grigory
[grigory#gr testRSA]$ java -cp ".:hidapi-1.1.jar" Test
libusb couldn't open USB device /dev/bus/usb/003/002: Permission denied.
libusb requires write access to USB device nodes.
info:HIDDeviceInfo [path=0003:0002:00, vendor_id=1112, product_id=58, serial_number=null, release_number=0, manufacturer_string=null, product_string=null, usage_page=0, usage=0, interface_number=0]
[grigory#gr testRSA]$ sudo java -cp ".:hidapi-1.1.jar" Test
[sudo] password for grigory:
info:HIDDeviceInfo [path=0003:0002:00, vendor_id=1112, product_id=58, serial_number=null, release_number=0, manufacturer_string=Genius, product_string=Laser Mouse, usage_page=0, usage=0, interface_number=0]
[grigory#gr testRSA]$
and for fresh Windows XP it isn't work (only one windows i can find. I haven't Visual Studio for compile lib from source):
E:\testRSA\out\production\testRSA>java -cp ".;hidapi-1.1.jar" -Djava.library.pat
h="e:\testRSA\out\production\testRSA" Test
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.codeminders.hidap
i.HIDManager.init()V
at com.codeminders.hidapi.HIDManager.init(Native Method)
at com.codeminders.hidapi.HIDManager.<init>(HIDManager.java:53)
at com.codeminders.hidapi.HIDManager.getInstance(HIDManager.java:121)
at Test.main(Test.java:14)
Maybe things have improved since you first asked this question. I recently began exploring usb4java on the Mac, and it seems to work. There is example code available, both for the low-level (libusb-like) API, and the high-level (javax) API.
To list all USB-devices, look the examples.
I downloaded all libraries directly from usb4java.org and the examples from github. I did not manage to get the maven build working, but I could import the libraries and examples in Eclipse and run them all.
There are same native code included in usb4java, but the library wraps them all quite beautifully and hides all the messy details, only extracting and deploying the native code at demand.
Related
I'm trying open this application: http://www1.icsi.berkeley.edu/~lucag/
(It's a research tool might might be great for my work so I really want to access it).
I'm running big sur on a 2014 mac book pro. It has Java 8 (I'm assuming that this is the 'Java Virtual Machine' which is specified in the instructions).
When I try and open the app I get the message:
"You do not have permission to open the application "ECGWorkbench'.
Contact your computer or network administrator for assistance."
I've tried everything on these two threads:
Can't run app because of permission in Big Sur
https://developer.apple.com/forums/thread/666611?page=3
I've tried opening the app on a mac which hadn't been upgraded to big sur. I can't get hold of a Windows or Linux computer.
I have two questions:
Is there a work around? I'm not a programer so bear with this question but if the app is written in Java and I had the code could I execute it? The folder with the app in had lots of other files. Or if I installed Linux in a virtual environment on my mac could I then open the Linux version of the app?
If it can't be fixed I'm going to try to contact the developers. The project doesn't seem to be very active so I'm not convinced they'd be interested in updating the app. If I could suggest what amendment they need to make or at least say why it's not working they might be more willing to help me out. Can anyone suggest what I could say to them? Something along the lines of 'I can't open the app because of XYZ, could you change the ABC' would be perfect. The NTL (neural theory of language) project created the app but they are part of the ICSI (international computer science institute) at berkley so I'm assuming they know what code is etc.
Thank you.
Rachel
I've been a little late with my reply, but I hope my solution will help you.
I had the same issue with eclipse (i need it for study things), so i opened my terminal and typed the following command...
codesign --force --deep --sign -/Application/Eclipse.app
After a reasign everything works fine for me.
For some reasons I have to work under windows 10 OS with Android-Studio as IDE. My problem is that, exoplayer uses software and hardware decoders of Android-TV device to decode video streams.
Apparently, most of the Android-TV devices have no built-in decoder for decoding mpeg-2 sounds and therefore, the sound of the mpeg-2 streams are mute however, mpeg-2 videos are playing well. In order to solve such problems, I believe that I have to embed Ffmpeg extension into exoplayer. To do this, I followed the instruction of here under Windows PowerShell as recommended, but there are some problems.
First: What should be the value of HOST_PLATFORM variable for windows when using PowerShell?
Second: For unknown reasons I am receiving the following messages when executing Shell script "build_ffmpeg.sh".
What I receive when I execute shell script
Now, how can I embed ffmpeg extension for exoplayer (under windows 10 OS), enable it for decoding and solve these problems? My programming language is java. Thanks.
Note: Please tell me if you have any other (Other than embedding Ffmpeg into exoplayer) suggestions to solve my problem.
To build FFmpeg for ExoPlayer under Windows, you can use Git Bash for Windows to perform the building process.
All commands are almost the same (we'll get to the differences in a minute). Please note that NDK_PATH is the path of your NDK's folder (it's usually the version number, you can find it in default cases in YourAndroidSDK\ndk\yourNDKversion).
As for the differences, it's only for HOST_PLATFORM, you should use windows-x86_64, by inspecting the build_ffmpeg.sh, there is a line that says:
TOOLCHAIN_PREFIX="${NDK_PATH}/toolchains/llvm/prebuilt/${HOST_PLATFORM}/bin"
The variable HOST_PLATFORM is only utilized to get the correct NDK tools for Windows. If you go and check the above path, you'll find a folder named windows-x86_64 under 'prebuilt'. That's what goes in HOST_PLATFORM.
If you get the NDK path correctly, HOST_PLATFORM correctly, FFMPEG_MODULE_PATH correctly, and last but not least the ENABLED_DECODERS, you should be able to build FFmpeg very easily.
If you don't want to go through setting the variables all over again, just edit the build_ffmpeg.sh file using Notepad, and edit the variable to make 'em be as you want without having to do it in the PowerShell terminal all over again.
I recently downloaded the JEthereal.jar file to capture packet traffic on my internet connection through JEthereal and also to study it. It reads the packets from a .pcap file just fine but on trying to capture packets it gave me a message that:
"No device found. This probably means that you installed JPcap but not
libpcap / WinPcap.Please follow the instructions on the website to
install it. It takes about 15 seconds and is well worth it."
So I downloaded its source code and opened it in Eclipse since I had already installed WinPcap.
On going through the code I came to the part where network devices are supposed to be discovered. The static method getDeviceList() from the JpcapCaptor class in the jpcap package which should return an array of network devices of type NetworkInterface. The following is its declaration given on the internet:
public static NetworkInterface[] getDeviceList()
However, in the source code that I have downloaded the method is left without a body and its been declared native i.e.
public static native NetworkInterface[] getDeviceList();
What should I do now to identify my devices? On searching on the net and on this portal I came to know that a jpcap.dll file should be present in my system32 folder (I am using Windows7) and I should install WinPcap for that. I had already installed WinPcap and there is no jpcap.dll file in the system32 folder. Also, i suppose i should add system32 to my PATH variable, i haven't done that yet since there is no jpcap.dll there.
Thanx in advance!!
If "On searching on the net and on this portal I came to know that a jpcap.dll file should be present in my system32 folder (I am using Windows7) and I should install WinPcap for that.", then, as the saying goes, someone is wrong on the Internet.
jpcap.dll is not part of WinPcap, and you do not install WinPcap to get it. You need to install Keita Fujii's Jpcap (he no longer seems to be working on it, and the site the JEthereal site links for it no longer exists, but the JEthereal site has some local download links, and some people have created their own forks of it).
Have you installed any version of Jpcap? If so, where did you get it from? It may be a version that doesn't work with JEthereal.
Why is getDeviceList() method in jpcap.JpcapCaptor class native in JEthereal?
Because getDeviceList() is implemented as native (C/C++) code.
on trying to capture packets it gave me a message that says: "No device found..."
I am using Windows7
Touchè. Starting with Windows Vista (which is the first Windows that implement root-like pretensions), you need to run jpcap as an administrator. This has to be done at least the first time that you run jpcap after the system has been restarted (so that the winpcap library is authorized to access network resources).
From jpcap FAQ
Q: I cannot obtain the list of network interfaces or cannot capture any packets. Why?
It may be because you don't have administrative privileges, which are
required to run Jpcap-based applications.
On Windows 2000/XP, your account should be in the Administrator group.
On Windows Vista, even if your account is in the administrator group,
you still need to use "run as administrator" option. To use the
option, right-click the application icon, and choose "run as
administrator". If your application is command-line based, you need to
open Command Prompt by using "run as administrator" option, and run
your application within that Command Prompt.
I'm currently developing a programm with Java to interact with an Arduino module. Now in Windows, it's running pretty well so far (I receive what I expect; I can work with the data), but in Linux (Ubuntu in my case); it's like the opposite. I installed Arduino and rxtx-java packages.
When I tried to use the Arduino program to connect to the Arduino board, I had to set a softlink on the ACM module to some serial or USB module. For example,
ln -s /dev/ttyACM0 /dev/ttyS99
Otherwise it won't even show up in the list in the Arduino program. So what I did then was starting the serial monitor tool (Ctrl + Shift + M) and sent it my start sequence waiting for an answer. It worked without a problem there (it was binary data so I couldn't verify if it was correct, but I got an answer at least).
The next thing I did was trying to do the same with my program, so the Arduino was connected to the PC, the softlink was set correctly, the device listed along with two normal COM-ports I have in my PC in my program, and I tried to connect, but it didn't work.
No error, no nothing, simply no answer of the board. After I waited a couple of minutes, it still didn't do anything, so I disconnected it from the PC, and then I got an array of zero-bytes as the answer.
What could cause this kind of problems and how would I fix it?
Thanks for your help
Volker
PS: the program is a jar file with all libraries/dependencies included
EDIT:
Hardware is an Arduino UNO Board Model R3,and on windows i'm using Arduino 1.0 to program it
Your symlink to /dev/ttyACM0 is double dubious:
Disconnecting+reconnecting or powering off+on might change the number of the dev.
ttyACM usually refers to modems, not to plain USB-serial converters like that used by Arduino (at least those with the FT232 chip). I would expect something like ttyUSB0. For those you also would not need a symlink.
If you installed from the Ubuntu packages you're bound to have problems. I tried this first myself only to find that there are serious issues. I would recommend downloading the most recent version of the IDE arduino-1.0-src.tar.gz.
You'll notice it's the source, I think you'll like it better that way. Or you can get the repository from Git, you'll find that information plus how to build the IDE in Building Arduino, Steps for First Time Setup. Besides the fact that the Ubuntu distribution version is buggy, it's also like old, big time.
I first tried to use javax.comm to connect to the serial port (COM4). It did not even open the serial port.
Then I tried to use rxtx libraries (rxtx-2.2pre2) to connect. It connects and writes the data but does not read any data from the serial port.
Is there any JDK/platform dependency to use javax.comm or rxtx libraries?
I am using:
Windows XP SP3,
JDK 1.6.0_22,
rxtx-2.2pre2,
USB to Serial adapter,
Portmon (by Microsoft) - to monitor activity on serial ports
Hyperterminal - to check if the COM port really works.
http://rxtx.qbang.org/wiki/index.php/Two_way_communcation_with_the_serial_port - sample code used to check read and write
After some digging, I was able to solve this myself, by explicitly setting the flow control mode. Even if you don't require flow control, setting it explicitly to FLOWCONTROL_NONE helps.
The same call was not required on Linux.
If you are setting the flow control to Hardware, I think it is also required to setRTS explicitly in order to get notifications in this mode. (Not verified).
I tried this code and was successful. You need to have three files with you:
comm.jar
javax.comm.properties
win32com.dll
and you need to put these files in specific directories:
comm.jar
in /java/jre6/lib/ext , /java/jdk_1.6.0.20/jre6/lib/ext , java/jdk_1.6.0.20/lib
win32com.dll
in /java/jre6/bin, /java/jdk_1.6.0.20/bin, /windwos/System32
javax.comm.properties
in /java/jdk_1.6.0.20/lib, java/jre/lib , /java/jdk_1.6.0.20/jre/lib
I would recommend trying out purejavacomm: http://www.sparetimelabs.com/purejavacomm/index.html
It is an implementation of javax.comm written in pure java + JNA, which completely solved the problem of portability between Windows and Linux for me. It should also work on OSX or FreeBSD (haven't tried), and should be easy to port to other OS-es that JNA supports, such as Solaris.
Another benefit is that you don't need to install a DLL like you do with rxtx, and that it doesn't seem to have a certain 100% CPU eating bug that rxtx sometimes has on windows.