EmbeddedRelated.com
Forums

Using Java to talk to an embedded system

Started by larwe June 15, 2007
A longtime customer has asked me to build a PC-hosted GUI to control
an existing system I designed for him a long time ago. Actually the
system was designed to control a vending machine, but he now wants to
use the same hardware as a sort of poor man's PLC, to operate various
other machinery in his facility.

I don't like wasting effort on Windows-specific code if I don't have
to, so I was thinking of writing the GUI in Java.

Can anyone who has been down this path (i.e. talking to an embedded
system over serial from a PC running a JVM) give any tips on the pros
and cons of using something like javacomm vs. JNI? (I figure the JNI
DLL would be <100 lines of code, just wrapping a few comm functions).

Thanks.

larwe wrote:
> A longtime customer has asked me to build a PC-hosted GUI to control > an existing system I designed for him a long time ago. Actually the > system was designed to control a vending machine, but he now wants to > use the same hardware as a sort of poor man's PLC, to operate various > other machinery in his facility. > > I don't like wasting effort on Windows-specific code if I don't have > to, so I was thinking of writing the GUI in Java. > > Can anyone who has been down this path (i.e. talking to an embedded > system over serial from a PC running a JVM) give any tips on the pros > and cons of using something like javacomm vs. JNI? (I figure the JNI > DLL would be <100 lines of code, just wrapping a few comm functions). >
Hi Lewin, This no doubt is not particularly helpful but I use a java telnet applet to talk to an embedded system which is online here: http://www.cybertheque.org/homebrew/rcvr The embedded controller talks over RS-232 to a terminal server which is accessed by the telnet applet. Embedded in the web page, the opportunity for GUI window dressing presents itself; I also use VT-100 graphics in the telnet session for GUI-like features (not particularly evident in my example yet). Regards, Michael
On Fri, 15 Jun 2007 07:48:54 -0700, larwe wrote:

> I don't like wasting effort on Windows-specific code if I don't have > to, so I was thinking of writing the GUI in Java. > > Can anyone who has been down this path (i.e. talking to an embedded > system over serial from a PC running a JVM) give any tips on the pros > and cons of using something like javacomm vs. JNI? (I figure the JNI > DLL would be <100 lines of code, just wrapping a few comm functions).
If it was for Linux that you wanted I would have happily emailed you some JNI code, but alas, for Windows, I don't have any. But you are right, the JNI code is basically wrapper code. You may also want to have a look at groovy - it has something called SwingBuilder to easily build Swing apps (easier than using Java). You can find some examples on the Groovy in Action book's website. In future, I can see myself using Groovy/Javacomm for simple GUI apps with serial port. You might have seen from sun's website that the latest Javacomm from sun now supports Linux/Solaris but not Windows. Previous versions supported Solaris/Windows but not Linux. I think you can get a windows compatible version off the net somewhere (not written by sun). HTH Paul.
On Jun 15, 1:12 pm, Paul Taylor <paul_ng_pls_...@tiscali.co.uk> wrote:


> > and cons of using something like javacomm vs. JNI? (I figure the JNI > > DLL would be <100 lines of code, just wrapping a few comm functions). > > If it was for Linux that you wanted I would have happily emailed you some > JNI code, but alas, for Windows, I don't have any. But you are right, the
Oh, I can write the JNI stuff. That's no problem. Actually, I will do the development in MacOS anyway :) My question is, asking someone who's already tried to do something of this sort, whether it is a better prospect to look for native Java solutions or just go the simple route with JNI.
On Fri, 15 Jun 2007 17:27:29 +0000, larwe wrote:

> whether it is a > better prospect to look for native Java solutions or just go the > simple route with JNI.
Well I have always gone the JNI route, and found it to work as expected. But as in my previous post, next time I will try javacomm + groovy, because it means I can write the sorts of simple apps I write using a scripting language + existing library, then drop the c compiler + makefile. I _suspect_ javacomm also works as expected. I will look with interest to see if anyone posts to your original question anything that puts me off ;-) Regards, Paul.
On Jun 15, 1:49 pm, Paul Taylor <paul_ng_pls_...@tiscali.co.uk> wrote:


> But as in my previous post, next time I will try javacomm + groovy, > because it means I can write the sorts of simple apps I write using a
Well, I was pointed to this: <http://en.wikibooks.org/wiki/Serial_Programming:Serial_Java> which is extremely interesting. I'll experiment with that this weekend. Yay Intarwebs.
I had a lot of luck with using a JNI interface to a USB DLL. With
something as straight forward as serial communications, it should be a
snap.