Pages: [1]   Go Down
Author Topic: How to... RXTX on Mac  (Read 1208 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i'm following that guide http://www.arduino.cc/playground/Interfacing/Java but i don't know how to do this:

"Append the directory containing librxtxSerial.jnilib files into your DYLD_LIBRARY_PATH environment variable"

Could someone help me, please?
Logged

IDE 1.0.5 - Arduino Uno R3 - Arduino Wifi Shield - Arduino GSM Shield -  IMU Digital Combo Board 6 DOF ITG3200/ADXL345

noplace,Fl,US
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, could you start by explaining what you're trying to do?
Serial communications to upload compiled sketches and send/receive
text from the arduino in the monitor worked for me with no
special installation steps. I just ran the newest Arduino.app and selected the
proper Board and Serial Port.

Could be that the documentation you are reading is out of date.

On my Mountain Lion 2010 macbook pro, DYLD_LIBRARY_PATH is unset. To see all environment variables,
go to the terminal and type set.

To append something to an existing environment variable, you
would do something like the line below. This is assuming you're using BASH,
the default Linux, Mac shell. Other shells have different syntax.

export PATH="$PATH:/newstuff"


means add /newstuff to the end of what is currently in the variable called PATH.


If you just want to talk to an arduino over a serial link, ie. get sensor data or whatever your sketch is sending using Serial.print(), there is no need to use the Arduino IDE.

For example, at the terminal typing

cat /dev/tty.usbmodemfa141

spits out whatever is coming in on that serial device. (Your /dev/usbmodemXXXXX will probably be different.  Connect the arduino and look to see what it is.)

This can easily be redirected to a file:

cat /dev/tty.usbmodemfa141 >log.txt

If you want an interactive session (you uploaded a sketch to make your arduino do something in response to stuff you type over the serial link):

try:

screen /dev/tty.usbmodemfa141 9600

(9600 is the default baud rate.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot for your wide reply!

This is the sketch i loaded on my Arduino Uno: (a simple light sensor)
Code:
int ledPin = 7;    // il LED e' collegato al pin digitale 7
int sensorPin = 0;  // il sensore di luce è connesso al piedino analogico 0  
int sensorValue;    // variabile per memorizzare il valore rilevato dal sensore  
  
void setup()  
{  
         pinMode(ledPin, OUTPUT);   // imposta ledPin come pin di output  
         Serial.begin(9600);    //inizializza la porta seriale  
         digitalWrite(ledPin, LOW);    // accende il LED  
}      
  
void loop()  
{  
          sensorValue = analogRead(sensorPin);  // legge il valore dal sensore  
          Serial.println(sensorValue);  // invia il valore al computer  
          Serial.println(" ");
          if (sensorValue > 600)
          {
            digitalWrite(ledPin,HIGH);
          } else digitalWrite(ledPin,LOW);
          delay(500);
}

i would create a java application that receive the "sensorValue" data (from tty.usbmodemXXXXX) and than do something with it.

This is the java code i use:
Code:
import java.io.InputStream;
import java.io.OutputStream;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import gnu.io.SerialPortEvent;
import gnu.io.SerialPortEventListener;
import java.util.Enumeration;
 
public class ArduinoJava implements SerialPortEventListener {
    SerialPort serialPort;
        /** The port we're normally going to use. */
    private static final String PORT_NAMES[] = {
            "/dev/tty.usbmodemfa131", // Mac OS X
            "/dev/ttyUSB0", // Linux
            "COM3", // Windows
            };
    /** Buffered input stream from the port */
    private InputStream input;
    /** The output stream to the port */
    private OutputStream output;
    /** Milliseconds to block while waiting for port open */
    private static final int TIME_OUT = 2000;
    /** Default bits per second for COM port. */
    private static final int DATA_RATE = 9600;
 
    public void initialize() {
        CommPortIdentifier portId = null;
        Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
 
        // iterate through, looking for the port
        while (portEnum.hasMoreElements()) {
            CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
            for (String portName : PORT_NAMES) {
                if (currPortId.getName().equals(portName)) {
                    portId = currPortId;
                    break;
                }
            }
        }
 
        if (portId == null) {
            System.out.println("Could not find COM port.");
            return;
        }
 
        try {
            // open serial port, and use class name for the appName.
            serialPort = (SerialPort) portId.open(this.getClass().getName(),
                    TIME_OUT);
 
            // set port parameters
            serialPort.setSerialPortParams(DATA_RATE,
                    SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);
 
            // open the streams
            input = serialPort.getInputStream();
            output = serialPort.getOutputStream();
 
            // add event listeners
            serialPort.addEventListener(this);
            serialPort.notifyOnDataAvailable(true);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }
 
    /**
     * This should be called when you stop using the port.
     * This will prevent port locking on platforms like Linux.
     */
    public synchronized void close() {
        if (serialPort != null) {
            serialPort.removeEventListener();
            serialPort.close();
        }
    }
 
    /**
     * Handle an event on the serial port. Read the data and print it.
     */
    public synchronized void serialEvent(SerialPortEvent oEvent) {
        if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
            try {
                int available = input.available();
                byte chunk[] = new byte[available];
                input.read(chunk, 0, available);
 
                // Displayed results are codepage dependent
                System.out.print(new String(chunk));
            } catch (Exception e) {
                System.err.println(e.toString());
            }
        }
        // Ignore all the other eventTypes, but you should consider the other ones.
    }
 
    public static void main(String[] args) throws Exception {
        ArduinoJava main = new ArduinoJava();
        main.initialize();
        System.out.println("Started");
    }
}

so ok...i understand now that i don't need RXTX library, but i don't understand why i got this error with the java code still:

Code:
java.lang.UnsatisfiedLinkError: /Library/Java/Extensions/librxtxSerial.jnilib:  no suitable image found.  Did find:  /Library/Java/Extensions/librxtxSerial.jnilib: no matching architecture in universal wrapper thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Library/Java/Extensions/librxtxSerial.jnilib:  no suitable image found.  Did find:  /Library/Java/Extensions/librxtxSerial.jnilib: no matching architecture in universal wrapper
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1827)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1716)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:83)
at ArduinoJava.initialize(ArduinoJava.java:28)
at ArduinoJava.main(ArduinoJava.java:101)

Anyway, i tried
screen /dev/tty.usbmodemfa131 9600
and it works fine, so it's just a good start point for me  smiley-red
« Last Edit: November 04, 2012, 12:47:43 pm by abstract » Logged

IDE 1.0.5 - Arduino Uno R3 - Arduino Wifi Shield - Arduino GSM Shield -  IMU Digital Combo Board 6 DOF ITG3200/ADXL345

noplace,Fl,US
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
blah, blah ..../librxtxSerial.jnilib: no matching architecture in universal wrapper thrown while loading .....blah, blah

The problem could be 32/64 -bit silliness.  

Look at this:
http://forum.processing.org/topic/serial-library-in-eclipse

I am also having problems with librxtx-java on PPC linux and just don't use it. Maybe I'm just an old Moomintroll, but I think it is totally nuts to work with serial ports in java. This should be handled at a lower level by the operating system.

btw, if you don't want to use Arduino IDE, you can build everything from the command line using scons and SConstruct. (Look at the Arch Linux wiki on scons and arduino to see details.)
« Last Edit: November 05, 2012, 09:55:17 am by ceratophyllum » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes i readed the post... but it don't work with -d32 argument too.  smiley-sad
Logged

IDE 1.0.5 - Arduino Uno R3 - Arduino Wifi Shield - Arduino GSM Shield -  IMU Digital Combo Board 6 DOF ITG3200/ADXL345

Pages: [1]   Go Up
Jump to: