Applet - Serialport communication - java

I'm trying to create a simple Java applet that reads data coming in through a serial port.
Is it possible?

By default, Java has no support for communicating with serial ports. There are libraries like RXTX that allow you to do that, but unfortunately RXTX requires a platform-specific native library in order to use the serial ports.
Further complication is that Java applets run in a very restricted sandbox by default, which means you need to a) sign the applet and b) manually install the necessary RXTX libraries on the host computer, which is not that user-friendly.
An alternative solution is discussed in this SO question (in short: use Java Web Start, not an applet, and everything gets a lot easier).

Yes, it is possible. Having said that, I think #andri pointed out the best path to a solution.

For that you can use jSSC lib (Java Simple Serial Connector). Page on google code: http://code.google.com/p/java-simple-serial-connector/
Also see this page: http://code.google.com/p/java-simple-serial-connector/wiki/jSSC_Terminal
This is jSSC based serial port terminal applet. Source code of jSSC-Terminal you can download on "Downloads" page.
Best regards, Sokolov Alexey.

Related

Block all Windows network connections using Java

I'd like to program a little application in Java which would block all network connections (for whole os, not just VM) on demand. The application is for the Windows platform only and I would like to use Windows specific APIs.
I looked at the Windows Firewall API, but didn't find anything useful. Also, I don't know how to call these APIs using JNA.
I'm asking you for a few pointers or examples for how I could accomplish these tasks:
Using Windows Firewall or other APIs in Java using JNA or some other library (JNI is not preferred)
Block/Unblock all connections
You can use the "netsh" command line, see http://support.microsoft.com/kb/875357
Invoke netsh command using the followinf syntax:
Runtime.getRuntime().exec(command)
But, I think, firewall is not what you need in this case. Here is the command line utility to enable/disable network interfaces for Windows: http://www.novell.com/communities/node/2338/network-configuration-command-line-control
There is no API support for this in Java. You cannot do it.

Best way to deal with COM ports for a cross-platform program?

I am writing an application which need to send data to a serial device attached to a COM port.
I am confused as to what is the best way to deal with such a device?
Shall I write the communication module in C++ or shall I write this in Java?
I want to run the application on Windows as well as Linux.
On Linux I would recommend libserial. You could also consider using Python. There is a multi platform pySerial module. If you decide for Java, rxtx is a multi platform library. On Windows you may use the Windows API for serial communications and combine it with libserial using #ifndef as #Dharma suggested.
I recommend you:
Boost ASIO
QextSerialPort (based on Qt)
You can write the module in c++ by specyfying the #ifndef "_WINDOWS_CODE" for windows code and else part for the linux code.
while compiling in Vc++ put the (_WINDOWS_CODE)macros in the projecty settings
and in gc++ remove the macro from project file
COM port is just a plain bit pipe. The APIs are expected to be fairly simple. In C++, the world has much more experience with writing to ports.
Other question would be - do you know what port number it is? There're several ways to find out which one is yours, like setup API on windows.
My suggestion, if you want to run you application in both linux and Windows, go for JAVA!. you can run your program without any need of compilation. otherwise you have to distribute seperate binary for both Windows and Linux.
Also programming model in both windows and linux for accessing SerialPort in C++, As i am preliminary a Windows C++ developer, you can use CreateFile WIn32 Api to access serial port.
shall i write the communication module
in C++ or shall i write this in JAVA?
Which are you more familiar with? Are you limited to these two languages? You could also use python with pyserial.
Are you doing this as a personal project? Is it for work? Is someone else working on this with you? What are they more familiar with?
For C++ you could use Boost.Asio.
For Java ... I don't know.

How can I use Java to communicate to device through USB port?

I just recently learn Java and try to communicate to the device through USB port connection. I've have used C# with OpenNETCF which allows me to send file and retrieve file on the device through USB port; how can I achieve this with java?
I seearch on stackoverflow thread, How to communicate with a USB device under Windows and Java?, the comment made by christoffer is to hack the native code, but I don't quite which native code api that he referred to. RAPI, maybe?
The only USB API I could find for Windows is here. Seems as if it has limited functionality, but it might suit your needs. A more complete UNIX API is also available.
ETA: Found a link to the official Java USB implementation, but looks like the windows version is still in alpha.
The native code API I referred to was the Windows DDK, i.e. the Driver Development Kit. The modern version seem to be called Windows Driver Kit, so google for Windows WDK :)
There should be a few C samples on how to communicate with USB devices, and it should be pretty straightforward to write a JNI wrapper from those.
As a quick thought, you could use JNI, the Java Native Interface. I've never used it myself though.
I found this page that explains how to perform a communication between a microcontroller and a java application: http://javausbapi.blogspot.com/
The Best way I found to communicate with USB is through RxTx library.
You can find an example of the usage here:
http://www.snip2code.com/Snippet/1044/Java--read-from-USB-using-RXTX-library

Dynamically loading a native library inside Java applet

I am trying to write a Java applet that will read from a user's serial port. For this I am using the Java Comm API in conjuction with the RXTX library. I've successfully managed to read data through a local Java application but I can't seem to do the same from within an applet. The problem is that the RXTX library is a native library and I haven't found a way to load this library inside the Java applet. I've found two interesting articles (Using JNI in Applets which references to this article), but both are over 10 years old and I am wondering if there is a newer solution. Or if you can suggest an alternative, I would love to hear it!
Use Java Web Start. You can include the native library as a signed jar and everything should work.
1) put the native librarys in a jar in the ROOT directory
2) sign ALL the jars
3) write a JNLP referencing all the jars (go do a search on how to write jnlp's)
after that it should work
Firstly I'd suggest doing that in an Applet is probably a bad idea.
If you do go ahead anyway, JNLPAppletLauncher may help.
I don't know about applets, other than they're locked down heavily wrt. security/accessing the machine's resources etc.
If you need a web-deployable solution, have you looked at Java Web Start ? See in particular this FAQ entry
Frankly, trying to access devices from a Java applet is a bad idea even if you could make it work, and loading a dynamic library into the conventional applet is an even worse idea; in fact, I'd be astounded if you could find a way to trick a modern browser into doing it. (Consider the possible security implications.)
You're better off, as suggested on other questions, building an app that can be launched with Web Start.
I'd be real interested in the answer here also. My suggestion would be to install the .jar and .dll for RXTX into the \program files\java\ tree. You could install them on the target system before trying to use the applet. I like the idea of using Java Web Start. If you sign the applet, can't you read/write any file on the machine? So you could install the .jar and .dll and then use them afterward?
For windows, I suggest using "Windows Java Serial Com Port Driver" rather than rxtx.
You can download it from http://www.engidea.com/blog/informatica/winjcom/winjcom.html
I've found it much easier to install and use and much more bug-free.
I was unable to use RXTX with USB serial devices because RXTX would crash when the USB port was unplugged. winjcom solved these problems for me, and more.
I'm still trying to decide how to deploy the DLL, but I'm not sweating it because I don't expect the DLL for "Windows Java Serial Com Port Driver" to change.
-Stosh

Java Media Framework on client side?

If I’m writing an applet that shows a video sequence (eg. streaming from a camera, or the applet itself is running the on the camera), do my clients need to download the Java Media Framework libraries inorder to see the sequence?
They need to install Java Media Framework on their computers, or you'll need to bundle the JMF together with your applet somehow.
If the applet makes use of the JMF libraries they need to be downloaded to the client machine (where the applet executes). However, JMF gets very little development from Sun (read none) and is pretty much legacy now (subjective).
Depending on how modern the camera is and what codecs it can output it may also be worth considering the video support in either javafx of flash.
Distributing the JMF.jar with your applet is sufficient.
Create a JAR ( Java DLL ) and put all the jar files from the install directory, JMF is 32-bit only, so the x86\java\JMF2.1.1e\lib is where it's usually located.
If you customized the customizer.jar you want that one too.
You can download it from a server like an applet and embed the applet inside and then run it. It's worked for me for 14+ years in Adult Pay sites.
Did you consider to use Java FX? This technology is dealing with this problem of downloading media libraries and so no. Of course. It is still in development. If to be first-adopter is option, it will be worth of considering this.

Categories