I have to re-implement an existing system from scratch.
At one point, when the user navigates to a certain web page the server must read data from the user's serial port.
Currently, the web page has an ActiveX control; when the page is loaded the ActiveX control calls into a COM DLL on the user's PC which reads data from the serial port.
The system is 10 years old. Is there any "better" way that I could implement this?
For instance, technology has move on in the last ten years. And this solution seems only to work in MS IE, which now has a market share of about 26% (it had, in 2013, when I last updated this question. As of Feb 2107, MS IE has 3-4% and Edge has 1-2%. As Edge is also a MS product, it might support Active X - I have not tried. Otoh, since it is new from the ground up, there is a good chance that it does not).
Did HTML 5 offer any new possibilities? What about products like Cordova?
Are there any other possibilities?
Could I add a Raspberry Pi to do the reading over serial port & and have the browser app communicate with that over a RESTful service?
[Update] @ EuroMicelli said "I'm going to assume that you have a very good reason to run your app from a web browser, instead of a native app". I don't know as I wasn't around when the original project was planned (and the company which designed it is now defunct).
Perhaps they didn't want the end user interfacing directly with the database? Perhaps "browser based" was a new buzzword back then? I, personally, have no problem with a desktop app (as I find them easier to implement), but maybe we should consider remaining browser based? (besides, I can handle the desktop app myself; it's only browser based reading from the COM port that leads me to offer a bonus ;-)
The serial port is much more than just a connector. It converts the data from parallel to serial and changes the electrical representation of the data. Inside the computer, data bits flow in parallel (using many wires at the same time).
COM port data logging FREE Serial Port Monitor has a simple interface, so to begin serial logging, you just need to select a serial port, choose where to file serial communication data, define RS232 port's parameters and click "Start".
You can indeed simultaneously read and write through the serial port. At the hardware level, the serial port (the UART) is a transmitter and a receiver, which are almost independent. At the software level, they are both handled through interrupts that read from / write to a software buffer.
To minimize external library or plugin requirements on the client machines, I would write a Java Applet.
Summary (including links to most of the documentation you will need to make it happen):
More details:
According to StatOwl, about two-thirds of all machines have the required Java frameworks already installed, so you might not even need to ask your clients to provide any additional infrastructure. And if you do, at least you are asking for a (for the most part) well-maintained piece of software that people know and won't be too skeptical about. And, most browsers should have the ability to prompt your users to install the Java framework automatically if it's missing.
There are several different libraries you can use in Java to access the serial port. PureJavaComm seems to be one of the few, though, that don't require external code to run. Specifically, on Windows, their WinAPI Java class gives you direct access to COM ports including all their settings just using calls to the already installed Windows libraries. Since PureJavaComm is a Java-only library, you can package it with your applet in one .jar file, which the browser downloads automatically, so there is nothing to install.
You can then write a minimal Java Applet (probably only around 50-100 lines total) that defines public methods to do the serial port access you need, which you can then easily call from JavaScript directly: Invoking Applet Methods From JavaScript Code
The only thing you need to make sure is that you sign your applet and that you wrap your serial port code in doPrivileged(...) calls so that it will be granted the required system access from within the JVM Sandbox. For this, you can either get a hold of a purchased SSL certificate (which you may already have if your service uses https) or generate your own. If you generate your own, the users will be prompted, whether they want to trust your applet, but they can choose "always trust" and so it's just a one-time checkbox- and ok-click. But beyond that, this should be a completely transparent solution that will minimize impact on your user-experience.
Alternative 1:
Another option would be, to simply ditch the web-interface altogether and instead provide a Java program that users can easily run (with or without installing it) directly from your website using JNLP (Java Web Start).
Alternative 2 (Likely Windows only):
I guess you could also use Microsoft Silverlight, which also seems fairly widely deployed:
Serial Communication with Silverlight 5 (COM port)
Some might consider it more "modern" than Java Applets, but it's probably less cross-platform.
It also seems a bit more involved to call your Silverlight code from JavaScript, but it is possible:
Making Silverlight Scriptable by JavaScript
One thing for sure, you will never be able to communicate with the local machine hardware without installing some special binaries (and run it with appropriate privileges) on the local machine. However, that doesn't mean you necessary need to use an ActiveX component and stay stuck with Internet Explorer. Of course, you could also develop a component for every browser in the market.
I suggest another approach:
Here is how it would look like:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With