Have serial port working under Linux 64 bits with Java - java

I need to connect to and use a serial port using Java from a Linux 64bits machine. In my case an USB to Serial adapter since laptop have no more serial port since a while...
After struggling a lot, I got it working. Then changing my laptop, I lost it ;(. But finally got it working again.
I'll document how to do it in the answer.. so I can find it easily back next time I need it :D

First, you need the Java JAR file RXTX and the serial library for Linux (32 and 64 bits are different...).
Main library can be found here: http://rxtx.qbang.org/wiki/index.php/Download
But a nice package with a run-install.sh copying libraries directly in right place can be found here: http://fizzed.com/oss/rxtx-for-java
After that, make sure your user is member of correct groups. In openSuse, it requires lock, uucp, and dialout groups. Log off and login to make the groups effective.
To test it, there is a nice explanation and program here: http://pharos.ece.utexas.edu/wiki/index.php/How_to_Access_Your_Serial_Port_using_Java#Test_the_Installation_of_RXTX_on_Ubuntu_Linux

Related

windows 7 64 bits didn't found win32comm [duplicate]

I am using the javax.comm API to help my program communicate with hardware over serial port. I am using the Windows 7 and NetBeans IDE 9.
I used the common Java program to check the available ports on my PC. The program compiled and ran without error. However it returned nothing.
What can I do to use the javax.comm API on Windows? It seems win32com.dll does not work with a 64-bit operating system.
This is how I got it to work.
I've tested it using JDK 1.6 (32bit) on my Windows 7 64bit machine.
Install 32bit JDK.
Copy 'win32com.dll' to JDK_HOME\jre\bin.
Copy 'javax.comm.properties'to to JDK_HOME\jre\lib.
Copy 'comm.jar'to to JDK_HOME\jre\lib\ext.
Now run your program and it should work.
Recent 2.2pre versions of RXTX include binaries for 64-bit windows. I think the latest RXTX information source has changed to this: http://rxtx.qbang.org instead of http://www.rxtx.org though.
At one point the RXTX library included drop-in support for using the javax.comm api. I'm not sure if it still does, but the main change then to use the "native" RXTX packaging was primarily just a package name change.
it seem the win32com.dll does not work with 64-bit Operating system
I think that is correct. In fact, according to the relevant download page, Oracle no longer supports the javax.comm API for any Windows platform.
However, I found this page which has a 64bit build of the DLL, among other things.
EDIT
By an astounding piece of research (i.e. following the links and reading stuff) I found the download page for the latest RXTX, which claims to have binaries for various platforms. If your platform is not there, try building from source. If that doesn't work, consider investing the effort in making it work.
I've integrated RXTX libraries into some of my earlier projects and i found out this bug it has while working with comm ports under windows, so you might want to check this first before going into some serious app design.
Communication works fine, never had any problem with that, but once you open the port you cannot close it and reopen, if you use method provided for closing port, your app just hangs, no exception no nothing. I found later the same behavior described by users on web, but never really found the solution to this problem.
Again, this might help you save some time, check it first.
Latest release, which is this http://rxtx.qbang.org/pub/rxtx/rxtx-2.1-7-bins-r2.zip, doesn't have this issue no more. Unfortunately i think its solved only for windows, its still there on Linux binaries, and i haven't tried it on mac.
Have you got a look on RXTX ? I think it is still active.
I had this issue...on a 64 bit machine..running windows 7
a legacy application developed in jdk 1.4, for 32 bit windows... and using the win32 comm api binary
i tried the RXTX binary for 64 bit and i was able to communicate with my device on some level... but... there were other problems as my application referenced a version of the jpos library that internally was using the comm-api (had import javax.comm.*... in some Serial...Listener class)....
I installed a 32 bit jdk and setup the comm-api binaries for 32 bit windows as directed here...setup comm api on windows
all was fine afterwards
You might be interested at an alternative library I've authored: http://code.google.com/p/jperipheral/

Connect java pc application to a mobile hotspot

Objective : I want the java project to connect to a mobile(android) hotspot.
I referred to WIFI - Scan and Connect using Java and tried using jwlanSacn lib but unfortunately it works only for 32 bit systems. This lib uses JNI.
Is there a way to connect to a mobile hotspot in java? Any libraries ?
or can I create my own JNI code for it?
Also, referred to
WIFI - Scan and Connect using Java
Finding SSID of a wireless network with Java
I'm working on 64bit Windows.
I'm new in pure java programming. Please help!
Thanks
You have to do it from the command line. You pretty much have to execute OS-specific instructions from your java program to command line using Runtime.getRuntime().exec(...) And then do some kind of parsing for the response you get. That's the idea.
Sorry I can't help more right now. I will update my answer as soon as I investigate this further

USB flash drive manufacturer serial number

How can I retrieve the manufacturer serial number of an USB flash drive in java?
i look at this
How to get manufacturer serial number of an USB flash drive?
but it doesn't help me.
I don't think there is a pure Java solution for this that works across multiple platforms.
You will probably need to resort to "scraping" the output of an external command. (Or figure out what they are doing, and replicate it in a native code library ...)
On Linux:
The "lsusb" command's output includes the serial number. (Check the manual entry.)
On Windows:
Third-party commands called "usp64" and "USBDeview" do this: see http://ashfaqshinwary.wordpress.com/tag/how-to-find-usb-serial-number-from-windows/.
Apparently, you can use wmic to get the serial number, though you may need to apply a Microsoft fix to make it work: https://superuser.com/questions/600394/get-usb-key-manufacturer-serial-number
#FoggyDay has found a couple of 3rd-party libraries that supposedly support this:
jUSB is apparently only available for GNU/Linux.
usb4java supports a wider range of platforms.
Both depends on platform specific native libraries.
The comment that suggests using Files.getFileStore(path).getAttribute("volume:vsn") is incorrect, I think. The Java source code implies that that is returning a volume serial number that is assigned by Windows, not the manufacturer-provided serial number. The relevant code is here.
The jUSB library allows you to read this from usb.core.Configuration.
usb4java - another, newer Java library - probably also supports the same.

Using Rxtx library to send messages to USB connected phone causes computer lock up/crash — why?

Ultimately I would like to use a Java program to send and receive messages from a phone that I have plugged in via USB. I can do this using a C# program, however the program I want to send and receive messages is written in Java. To do this I am using the Rxtx library (but using the Windows x64 compiled version from Cloudhopper). But whenever I try and send any commands to the phone via USB my computer completely locks up and I have to hard-restart it.
The code I am running is here: Two way communication with the serial port. I think that it successfully establishes a link since it gets to the stage where it accepts input from the console, though when I press enter, and the input is sent, the computer locks up.
I am running Windows 7 x64, using Eclipse. Thank you for any help.
A little hard to tell from the code, but here are some debugging tips:
Try stepping through the code with the debugger line by line, and step in to the library itself to see if you can find the problem.
Instead of reading/writing from the console, try sending character codes programmatically. The console operates very differently from direct access. i.e. instead of System.in.read()) just try passing in a known good String.
Keep in mind that Java works with UCS-16 internally, but that consoles typically work with different character encodings (e.g. cp1252 for Windows). So, your "enter" may be a completely different character from what the system is expecting. If your device is expecting ASCII 13 and your keyboard is generating ASCII 12, that could be enough to confuse things.
The crash makes it seem very likely that there is something going on with the native library. If you find that the Java debugging keeps dropping you into the JNI boundary, you may need to debug with a C/C++ toolset.
Good luck!

How do you interface with a USB to Parallel adapter?

I'm currently doing a project where I have to interact with a circuit I made through the parallel port of a computer. However, my computer doesn't have a parallel port so I borrowed a Parallel to USB adapter cable. The cable didn't come with any drivers, but it's recognized by the device manager as a "USB Printing Support" controller, under the USB section.
It seems that old parallel printers can be plugged in and work properly without any problems. So my question is, if I write a program in Java that tries to interact with a parallel port directly, will it work? And if not, can anyone give me some pointers as to what I need to do to interact with it?
Thanks.
I think you should head toward javax.comm library here.. there is also a different version that is supposed to work better, called librxtx.. take a look here (it's a pluggable replacement for javax.comm)..
I used both of them for an embedded device and they worked great, they manage serial and parallel port.. maybe also usb in your case.
I can't speak for parallel or Java but I've done something similar with serial-via-USB and C#. In that case it was exactly the same as a native controller. YMMV.
As for testing things: get an old dot-matrix printer (and put it in hex dump mode if you really want the nitty-gritty).
If you really want drivers for the thing, find a utility (I think the windows device manager can do it) that gives you the vendor ID and product ID numbers and from those you can look up all kinds of fun stuff (many Linux distributions have a plain text file that maps the numbers to the name of the manufacturer and what not) that plus Google should give you a driver installer.
You need java parallel port drivers which I haven't found for free. You'll have to pay for the driver for Windows.
I think there might be some free drivers if you use Linux.
USB "parallel port" adapters and cables generally aren't. They contain chips that emulate USB printers and send the print data out the parallel port like it might be sent to a similar printer using a parallel (printer) port.
Unless the device you have is actually a printer, there are probably very few (if any) adapters that will work.
There are ways of attaching GPIO "parallel"/bus pins into USB including certain FTDI chips, UARTs and various microcontrollers. If you can write software to use one of these, it could let you drive arbitrary circuits the way olde PC parallel ports were (not through the same MMIO, though).

Categories