Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!usenet.ukfsn.org!not-for-mail From: Martin Gregorie Newsgroups: comp.lang.java.programmer Subject: Re: I need to write Simple JAVA program to read and write from USB serial to use it with Arduino Date: Sun, 14 Oct 2012 00:02:51 +0000 (UTC) Organization: UK Free Software Network Lines: 61 Message-ID: References: NNTP-Posting-Host: 84.45.235.129 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: localhost.localdomain 1350172971 6402 84.45.235.129 (14 Oct 2012 00:02:51 GMT) X-Complaints-To: usenet@localhost.localdomain NNTP-Posting-Date: Sun, 14 Oct 2012 00:02:51 +0000 (UTC) User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Xref: csiph.com comp.lang.java.programmer:19317 On Sat, 13 Oct 2012 12:54:48 -0700, sahm wrote: > Hi every one > > I’m trying to write simple JAVA program that could send command to > Arduino board or read output from Arduino. > I tried java-simple-serial-connector library but I keep getting error. > And in Arduino web site they use gnu.io. classpath witch I have no idea > how to use it with java > > Please help me > You can't drive a serial connection from Linux/OS X/Windows using pure Java. SimpleSerial, RxTx or my SerialPort package all use C in various ways to build a bridge between the Java program and the serial port. This code is *always* compiled for the target operating system: it has hopefully been written to be portable but its always possible that it wasn't, or at least has never been ported to the version of the OS you're using. I think SimpleSerial and RxTx both use the JNI interface to their C code modules. My package uses a socket connection from the Java program to a separate server, written in GNU C, that drives the serial port(s) and that has only been compiled & tested under Linux. As far as I know all three were designed to work with built-in serial ports. I'd expect Linux or OS X to be capable of transparently driving a USB-serial adapter[1]. I don't use Windows so can't tell you about it. In any case, you still need some form of C glue because Java doesn't have any knowledge of USB-serial adapters. However, there are other approaches that are worth a look. These all use the fact that Java can handle socket connections: - use an Arduino board with an Ethernet interface and an onboard TCP/IP software stack. Something like these: http://www.amazon.com/Arduino-Ethernet-Power-over-Ethernet-Serial- Adapter/dp/B005EJN5X6 http://arduino.cc/en/Main/ArduinoBoardEthernet - You can buy relatively inexpensive modules that take an Ethernet connection (RJ-45) socket and provide an RS-232 serial connection for your Arduino board. These are what I mean: http://gridconnect.com/network-components/xport.html http://kanda.com/products/Sena/NEMO10.html http://www.radi.com/modular64.htm - or you can get back-to-back sockets (Ethernet (RJ45) one side, RS-232 (D9) the other): http://microcontrollershop.com/product_info.php? cPath=98_284&products_id=1459 [1] maybe. There are USB-serial adapters and USB-serial adapters: some will 'just work' with Linux and some won't. If the adapter needs a driver to work under Windows, then that's possibly also a trial and error game. I have a pFranc USB-serial adapter that works like a charm with native Linux programs but refused point blank to work with a Windows program running on Linux under Wine. Go figure. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |