Serial communication from JavaScript? - javascript

Is it possible to communicate over a machine's serial port through JavaScript?
I have to write a short program that sends data to a microcontroller over the serial port that has a GUI and is cross-platform compatible, and I really don't want to use Java's Swing.

JavaScript itself doesn't have any built in functionality to allow you to access the serial port. However, various JavaScript engines (v8, rhino, etc) allow you to write your own custom native objects.
You might want to check out node.js, which is a JavaScript library for v8 that's focused on writing server-side code (rather than web browser client code). It seems that someone's already written a serialport package for that:
https://github.com/voodootikigod/node-serialport

This is an old question, but in case this helps anyone else, Chrome Apps have access to a serial API - http://developer.chrome.com/apps/serial.html - which might help.
It's Chrome specific (obviously..), but Chrome is available cross-platform so might answer the question.

There's a cross platform plugin for serial port communication called jUART.

Yes, it's possible using an ActiveX(I did it). You can make an activeX and use JavaScript to invoke it.
If you prefer, you can make a .net dll and register it using regasm. Take a look at this link
You also can write an activeX using VB6 and register it. Both works fine.
Ps.: if you are using ActiveX, the JavaScript code will run just on IE.

If you have a DLL library (this includes e.g. most Windows APIs) that allows you to communicate over serial port you can invoke it from Firefox chrome code (or content code with universalxpconnect privileges) by using ctypes.

What you could do is to use a Java applet that connects to the local computer's Java application that reads the serial port. The applet would then transfer the data to a JavaScript class or something that can hold the information. Then additional JavaScript code can be used to access the data. It's a complicated solution but should work.
Another way is to create a POJO service.

Related

JavaScript Device Communication

I need to communicate with an already connected (paired) device attached to my computer via JavaScript.
This is a Bluetooth device however it does NOT use 'low power technology' thus is currently inaccessible via WebBluetooth.
Is there any way to communicate with my device using a different method due to the fact that it is already paired with the computer? Maybe as some sort of serial connection?
Targeting support for Google Chrome.
Node.js or anything outside the realm of HTML5/JavaScript/Chrome Specific JavaScript will not be accepted as an answer. WebBluetooth already shows an example however my device does not use Low-Power-Bluetooth..
You will need to use something like NodeJS. Browsers cannot access hardware attached to the computer unless the browser provides an API for it or you have an app on the host machine that the browser communicates with.
I suggest learning NodeJS as it is a great language and considering you already know JS the syntax will be familiar.
There is a way. Look into pubnub IoT api for bi-dir nearby device communications:
https://www.pubnub.com/solutions/iot/
This is a solution for multiplayer gaming as well. JS api here:
https://www.pubnub.com/docs/web-javascript/pubnub-javascript-sdk

Is Node.js the One Allows to Write Cross Platform Applications in JavaScript?

Node.js allows to access IO layer / database and it allows write javascript code in server-side.
I'm just wondering is Node.js the one allows to write cross platform applications ?
If yes,
How this possible?
Node.js just release on 2009 and has it opens up almost all platforms.
What is the reason preventing other languages such as C# to get this ability ?
(Apologies if i am mistaking the concept. i'm just stated to learn node.js) (googled)
How this possible?
It (or library code written in other languages) abstracts operating system specific stuff. Code is then compiled for each platform by the node executable that runs on each platform.
What is the reason preventing other languages such as C# to get this ability ?
Nothing. That is why C# programs are also able to run cross platform. Here is, for example, a C# compiler for Linux.
NodeJS does allow cross platform development, as node abstracts out the system specific functionality into APIs your code can access.
Regarding C#,you can do the same thing, you'll just need to run the code in in something like mono for *nix. However, it's worth noting that .net has gone open source and will soon be compiled natively for other environments (and won't need to run within mono). This also enables you to run it on arm devices as well, such as raspberry pi.

Check if JDK is installed through javascript

The topic-title speaks for itself.
Is it possible to check if the client has JDK installed trough javascript?
I know that it is possible to check the os and the browser but is that possible too?
You can check whether the client has java enabled with window.navigator.javaEnabled().
Note that:
The return value for this method
indicates whether the preference that
controls Java is on or off - not
whether the browser offers Java
support in general.
For more information, have a look at https://developer.mozilla.org/en/DOM/window.navigator.javaEnabled
I am presuming you have an Applet or a Web Start application which you want to run.
For those cases Oracle provides the Java Deployment Toolkit JavaScript which helps to detect Java versions and also offers methods to automatically write applet tags and Web Start launcher buttons.
As you can see at http://download.oracle.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit (also contains link to downloading .js file) it can retrieve installed JREs or send the user to installation page of latest one. This might be what you are looking for.
Notes:
This applies to detecting JREs. JDKs aren't used by the browser so there isn't a need to detect them.
It might not work because of privacy settings or other browser/JRE configuration options.
I don't think you can. It would require javascript to access information beyond your browser. Maybe there's some browser specific solutions.
Its not possible to know the version of Java through javascript .If its possible then it will be a security breach.

Javascript app in Android

I am new to Android programming, and looking for some general knowledge. I am considering writing logic of my application in javascript so that the same code could be executed in a webapp and in a desktop application. Would it be possible to also have it working on Android? I know that:
SL4A is marked as alpha-quality, and user would need to install it to make such an app work. Still it provides access to Android API. SL4A scripts also cannot go to Android Market, as far as I know.
A simple webapp doesn't have access to most Android API.
Would it be possible to write a simple Java app that would embed an HTML widget with javascript code and provide some wrapper to access necessary API?
I am not looking for a fully portable thing--I intend to adapt UI to each environment manually. I just would like to have the internal logic common to all ports.
PhoneGap allows you to write an HTML-based app that not only works with Android, but also iPhone, Windows Phone 7, WebOS and more. The API is standardized, so you can use the same page on all the platforms.
There's support for the most common native features on most platforms. (Here's a chart of the features supported on each platform) In addition, if you find that there's a feature you cannot replicate using only their API, you can write a plugin in the native platform language (so, for Android that'd be Java), and then call that plugin from your HTML/Javascript-page.
If you want to use javascript and access the native api then you should try Appcelerator.com. Those people are providing this.
There is Rhino, which is a Javascript engine written in Java. It works in Android, and it is used by Appcelerator's Titanium mentioned in another answer here.
User interface and Android-specific API can then be written and wrapped in Java, then called by the logic code written in Javascript and run by Rhino.
Consider GWT, a Java to javaScript compiler. You can write your logic and a lot of other code in plain old Java(There are a few things(e.g. reflection) that you can't do like reflection but you wouldn't be able to do it in javaScipt either) Applications like Google inbox are using GWT to reuse a lot of their code in javaScript. They don't just reuse logic either. You can reuse dependency injection, your architecture, AJAX calls and more. Also, GWT is faster than javaScript in both the browser and the JVM. The biggest problem you might have with GWT is that it's more complicated javaScript. Regular Java is already more complicated. Making it work on both the JVM and browser can only make things more complicated. Also, GWT was designed from the ground up for extremely complciated web apps.

Developing Windows apps with JavaScript

I'm currently in the need of developing a Windows application. I want to keep things simple (in the spirit of uTorrent) and I would like the result program to be a single .exe file containing all that it needs.
The program is simple. It just needs some UI. It needs to run for a long period of time (lay there as a tray icon). It needs to do some routine tasks like simple I/O. It also needs to access the internet, specifically some web server.
Apart from these small requirements I would like to write all of it in JavaScript, as I feel more comfortable with it than any other language.
I know there's things like Windows Script Host that let you run JavaScript programs and interact with some Win32 API, but will I be able to do everything I need with Windows Script Host? Can I pack all of the Windows Script Host in a single .exe?
If not, what alternatives do I have for JavaScript?
I found that there's actually a JavaScript compiler that comes with the .NET framework called jsc.exe.
For more information:
http://www.phpied.com/make-your-javascript-a-windows-exe/
http://msdn.microsoft.com/en-us/library/7435xtz6(VS.80).aspx
I guess it's not really JavaScript since it introduces extra things like import and even some class syntax which is weird for me. But this works perfectly for me as I will just doing things as I am used to on the web.
Aside from Windows Script Host, there are
Windows Desktop Gadgets (Vista and Windows 7 only)
HTML Applications (HTAs)
Both are written with standard web technologies, HTML, JavaScript, Flash, etc. They can also be extended with COM objects/ActiveX controls such as FileSystemObject, WMI, WScript or even ones that you write yourself. Windows Desktop Gadgets have access to a separate API/namespace with various Win32-esque properties and methods.
It seems that nobody mentioned JSDB.
JSDB offers a command line environment which you can execute arbitrary javascript code. You can easily compile to a .exe file by using the command copy /b jsdb.exe+program.zip program.exe
It's important to know that you've got to call your main js file main.js within a standard zip file. Not sure if the name program.zip is required.
I haven't actually tried making GUI applications with this yet - although it seems to support various APIs like ActiveX.
It's possible that by using the copy /b command mentioned above, you could compile a script from the wscript.exe file - but I tried and couldn't get it working. Let me know if anybody tries and has success somehow.
I think you're looking for Adobe AIR
The Adobe® AIR® 2 runtime enables developers to use HTML, JavaScript, Adobe Flash® software, and ActionScript® to build web applications that run as standalone client applications without the constraints of a browser. ~ The AIR website
Internet Explorer introduced the concept of Hypertext Applications in IE 5. It never made a big breakthrough, so resources and documentation are scarce.
Mozilla-backed competitor Prism seems to be alive and well, though, and is definitely worth a look.
Prism is an application that lets users split web applications
out of their browser and run them directly on their desktop
I believe the best way to go is V8 JavaScript Engine provided by Google.
"V8 can run standalone, or can be embedded into any C++ application." - which I believe is perfect for your needs, because you can do most of the stuff in JavaScript and use provided interfaces to communicate with the system.
I'm not 100% but I believe WSH uses JScript or WScript, not JavaScript.
Color me crazy, but its only a short step form Javascript to Java or C#. I'd suggest C# as, on a windows machine, the libraries are already there. You can just copypaste your .exe and let 'er rip.
If you want a single .EXE, what runtimes are you okay if they are required pre-requisites?
If you're okay with requiring .NET runtime to be preinstalled, then you do all your work in JScript.NET
Chromium Embedded Framework (CEF) may give you some help. i have not clearly know how, but i realy found many Apps using this framework.
http://code.google.com/p/chromiumembedded/
Introduce for CEF are:
The Chromium Embedded Framework (CEF) is an open source project founded by Marshall Greenblatt in 2008 to develop a Web browser control based on the Google Chromium project. CEF currently supports a range of programming languages and operating systems and can be easily integrated into both new and existing applications. It was designed from the ground up with both performance and ease of use in mind. The base framework includes C and C++ programming interfaces exposed via native libraries that insulate the host application from Chromium and WebKit implementation details. It provides close integration between the browser control and the host application including support for custom plugins, protocols, JavaScript objects and JavaScript extensions. The host application can optionally control resource loading, navigation, context menus, printing and more, while taking advantage of the same performance and HTML5 technologies available in the Google Chrome Web browser.
Numerous individuals and organizations contribute time and resources to support CEF development, but more involvement from the community is always welcome. This includes support for both the core CEF project and external projects that integrate CEF with additional programming languages and frameworks (see the "External Projects" section below).
Why not use Rhino -- JavaScript on the JVM? You can even compile your scripts to .class files and package them into a JAR along with Rhino for easy distribution...

Categories

Resources