Pages: [1]   Go Down
Author Topic: Java example is for Unix, what about Windows  (Read 533 times)
0 Members and 1 Guest are viewing this topic.
Turku
Offline Offline
Full Member
***
Karma: 0
Posts: 201
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are imports for gnu. and processing. Besides there are no run.bat or testrun.bat files in C:\Program Files\arduino-0017\ folders. Perhaps the instructions are dated?

Edit: I have problems with contacting Arduino forums today. This post was here 3 times. I deleted other two.
« Last Edit: September 14, 2009, 04:29:14 pm by LMI1 » Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Which example are you talking about?
Logged

Turku
Offline Offline
Full Member
***
Karma: 0
Posts: 201
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From this:
http://www.arduino.cc/playground/Main/InterfacingWithSoftware

to here (Java)
http://www.arduino.cc/playground/Interfacing/Java
Logged

Turku
Offline Offline
Full Member
***
Karma: 0
Posts: 201
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, no answers.
I googled "serial communication java" and this I found. Among others:
http://en.wikibooks.org/wiki/Serial_Programming/Serial_Java
 Sun has stopped Java serial port support and those strange imports are from an other serial port library rxtx http://www.rxtx.org/.
I have not tried it, but it is promised to work.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is a sample I wrote which runs under Windows with the RXTX library. It connects to the Arduino on COM3 and prints the character 'H' to it and closes the port. You can change the port parameters easily.

I had to insert a sleep instruction into the code as trying to talk to the serial port immediatly doesn't seem to work, it needs a second or so before it will send data.

You will need the RXTXcomm.jar in the classpath as well as rxtxSerial.dll

Code:
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.InputStream;
import java.io.OutputStream;

public class CommTest {

    static InputStream input;
    static OutputStream output;
    static SerialPort port;

    public static void main(String[] args) throws Exception {

        // Open the serial port
        CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("COM3");
        port = (SerialPort) portId.open("Arduino", 4000);

        // Get the port input/output streams
        input = port.getInputStream();
        output = port.getOutputStream();

        // Set the port parameters
        port.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

        // Wait for the serial port
        Thread.sleep(1500);

        // Write 'H' to the serial port
        output.write(72);

        // Close the serial port
        port.close();
    }
}
Logged

Turku
Offline Offline
Full Member
***
Karma: 0
Posts: 201
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks

There is also a useful info about how to install rxtx on homepage, I think. Although RXTX wepsite is a bit messy.

I have not tried your code yet, because our project is "resting" for a while, but java code is nice to have.

Is the java example code any good?
Logged

Pages: [1]   Go Up
Jump to: