Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #19317

Re: I need to write Simple JAVA program to read and write from USB serial to use it with Arduino

From Martin Gregorie <martin@address-in-sig.invalid>
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 2012-10-14 00:02 +0000
Organization UK Free Software Network
Message-ID <k5cvfb$682$1@localhost.localdomain> (permalink)
References <ba723146-04af-433c-9b5b-8ca39828039f@googlegroups.com>

Show all headers | View raw


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       |

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

I need to write Simple JAVA program to read and write from USB serial to use it with Arduino sahm <sahm007@gmail.com> - 2012-10-13 12:54 -0700
  Re: I need to write Simple JAVA program to read and write from USB serial to use it with Arduino Lew <lewbloch@gmail.com> - 2012-10-13 13:07 -0700
  Re: I need to write Simple JAVA program to read and write from USB serial to use it with Arduino Arne Vajhoej <arne@vajhoej.dk> - 2012-10-13 19:00 -0400
  Re: I need to write Simple JAVA program to read and write from USB serial to use it with Arduino Martin Gregorie <martin@address-in-sig.invalid> - 2012-10-14 00:02 +0000
  Re: I need to write Simple JAVA program to read and write from USB serial to use it with Arduino Knute Johnson <nospam@knutejohnson.com> - 2012-10-13 17:30 -0700
  Re: I need to write Simple JAVA program to read and write from USB serial to use it with Arduino stledger@lanl.gov - 2012-10-15 11:24 -0700

csiph-web