Solved

Java applet to control serial port from web browser?

Posted on 2011-09-29
12
3,636 Views
Last Modified: 2012-05-12
I realize there have been several posts in the last few years about this topic, but after reviewing them all I have not found a concrete solution.

I have already concluded that it is not possible to access a local PC's serial ports using Javascript running on a browser, unless there is a new JQuery or something else I overlooked that is capable of it (if so, please enlighten me).  So I am looking for a Javascript to Java applet solution.  I CANNOT USE ACTIVEX controls, since the application will be running on Firefox or Chrome only.  Please do not suggest that I try using IE with ActiveX.

The application is simple; I need to read an RS-232 postal scale and put the value in a Javascript variable.  There may also be the possibility of utilizing the USB port as well, so a Java applet that can be loaded into the browser for USB communication would be an acceptable solution as well.

One requirement: I do not want to install anything on the local PC; if there is anything to download, it must be done natively through the browser (as in a Java applet).  I want to be able to walk up to a new PC on our LAN that has Firefox installed but has never run the application and be able to open it instantly.

For reference, here is a similar question that was asked: 23176331.  The response mentions "a Java applet with the right permissions" but then refers to an ActiveX without following up with the Java suggestion.

Any thoughts?
0
Comment
Question by:RareSeeds
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 36815838
You'd probably be better off with a Web Start app. It would need to be signed
0
 

Author Comment

by:RareSeeds
ID: 36815923
A JAWS would first require the installation of JRE (requiring administrator permissions on our domain; the average user will not be able to do that).  Also, how would I get the returned value back to Javascript?

The process would need to be transparent to the user.  When they click the WEIGH button on the browser, the weight needs to appear in a text box.  Just like that; no popup, click another button, etc.
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36816536


You'll need to write a signed applet to access the serial port - look here for instructions:
http://www-personal.umich.edu/~lsiden/tutorials/signed-applet/signed-applet.html
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 36816602
>>A JAWS would first require the installation of JRE (requiring administrator permissions on our domain; the average user will not be able to do that).

That would also be the case for a Java applet.

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36816616

Still, I would suggest not to deal with Applets in this case.

Look, JDK or JRE in fact do not require any installation. Moreover, you can even use it from network share.
So waht you do - you just copy the java home directory to your fileshare and have path incluse fileshare/jdk/bin
folder. Then java cmmand will work and execute your classes.

Then yuou write your program as normal java application and put your classes also
to some folder on fileshare

then you make a .bat file in that folder and make sure that it has a path referencing your java on fileshare/bin
folder (and of course required classpath)

Then each user at his/her PC have only to map the fileshare (if they already don't have it mapped) and
then create shortcut on their desktop to that .bat file
You can even arrange it so, that you send them an email, from which they can drag the shortcut to their desktop

This system worked very well for me for many site-wide applications


0
 
LVL 47

Expert Comment

by:for_yan
ID: 36816642
The great advantage of having java on the filesahre is that you will not depend on the java
they have on their machine - and you'll never have any issues when they install a new java

It is true, that application may open a little bit slower than when java is local, but
that applies only to the opening and if network is more or less OK - then the difference is not that
dramatic
 
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 86

Expert Comment

by:CEHJ
ID: 36817836
>>You'll need to write a signed applet to access the serial port - look here for instructions:

>>Still, I would suggest not to deal with Applets in this case.

??
0
 

Author Comment

by:RareSeeds
ID: 36904149
So exactly how does the batch file get called from the browser when the WEIGH button is clicked?  Your suggestion may work well for you, but honestly that's by far more work-around that I am looking for.  If JRE does not require installation privileges and can run off a share, then why not just go back to the applet idea?  Because JRE needs to be installed locally to access the local ports?

What I am really looking for is a simple solution, whether Java applet or Flash.  What that means is either a product name or an actual code sample.  Like I mentioned before, it needs to be a simple click on the web interface that queries the scale and puts the weight in the text box (or Javascript variable, etc.).

If anyone can provide a ready-to-go solution (not just suggestions or theories or "try this"), that would be the ideal answer.

@for_yan: I'm not bashing your suggestions, your idea seems like it would work for some situations.  It's just not what I really need for this case.  If there IS no real answer, I may have to do it that way in the end.
0
 

Accepted Solution

by:
RareSeeds earned 0 total points
ID: 36942405
I have finally found a working solution for this long-standing problem.  There is a Java applet that communicates with the serial ports here:

http://code.google.com/p/java-simple-serial-connector/

The code and several examples are provided.  If a person knows Java programming, the applet can be customized for your specific application.  My modified applet is called and receives parameters (baud, parity, etc.) from a JavaScript function, and in turn calls a specified JS function with the returned data from the serial device (or a different function if an error occurs).

There is much documentation about JavaScript-Java interaction, but this is the resource I used as a guide:

http://www.raditha.com/java/javascript.php

This approach is completely transparent to the user.  As mentioned before, the applet will need to be signed, or the browser settings changed to allow it to load without prompting.
0
 

Author Closing Comment

by:RareSeeds
ID: 36978251
This solution has the potential to help many of the other questions asked along the same lines over the past few years.
0
 

Expert Comment

by:ads711
ID: 37898297
I'm also trying to achieve the same result, a java applet that reads the data from a serial port and then passes that data through to the javascript. I'm currently trying the accepted solution posted by RareSeeds, but i'm experiencing some issues. First i followed the documentation about Javascript-Java interaction with some basic examples (without making use of the classes in the jssc library yet). It works fine in both ways (java <-> javascript)

Now my problem is the following, when i want to make use of the classes provided by the jssc library i get the following exception in my java console log.

http://dl.dropbox.com/u/17090181/NoClassDefFoundError.png

This exception occurs when i want to get a list of available ports on my system by using the getPortsNames function provided by the SerialPortList class. It works fine when i run the applet in the Applet Viewer but when i integrate the applet in the html file it doesn't work anymore.

I tried to use other functions from other classes in the jssc jar and keep getting the same NoClassDefFoundError, so it seems to me every time i use a class from the jar the interaction between my java applet and javascript drops the moment when i use these functions.

considering you managed to get things working, RareSeeds, i was hoping you could help me out here.

Download link to the application:

http://dl.dropbox.com/u/17090181/EquineLifeApplet.zip
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 37899733
I'm also trying to achieve the same result

You need to open a new question
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now