Java applet to control serial port from web browser?

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?
Who is Participating?
RareSeedsAuthor Commented:
I have finally found a working solution for this long-standing problem.  There is a Java applet that communicates with the serial ports here:

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:

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.
You'd probably be better off with a Web Start app. It would need to be signed
RareSeedsAuthor Commented:
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.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.


You'll need to write a signed applet to access the serial port - look here for instructions:
>>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.


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

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
>>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.

RareSeedsAuthor Commented:
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.
RareSeedsAuthor Commented:
This solution has the potential to help many of the other questions asked along the same lines over the past few years.
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.

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:
I'm also trying to achieve the same result

You need to open a new question
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.