Recent Changes - Search:

edit SideBar

RxTx

RxTx is one of the Java Serial Port Interfaces.

The XBee page was getting long, so the RxTx information was moved here.

See Also

Raw serial interface

To communicate with the XBee, we could try using the code in ptolemy.actor.lib.io.comm.SerialComm.

One of the big issues is that we would need to figure out the protocol and what commands to send. This is documented as AT commands, see XBee

Mac OS X: Update the Java Library

The SerialComm actor uses RXTX, which needs to be installed in the correct location.

With the version of RxTx that ships with the XBeeJava, a shared library must be loaded.

With nrjavaserial, the shared library is included in the jar file, much like how JNA loads the foreign function interface.

Below is documentation about how to install the RxTx that shipped with XBeeJava. Ptolemy II is using nrjavaserial, so this is moot.

With the version of RxTx that ships with XBeeJava, one of the problems is that installing RXTX for use by $PTII/bin/vergil requires adding it to a directory referred to by the java.library.path System property. On the Mac, this is /Library/Java/Extensions.

I copied versions from the XBeeJavaLibrary

ealmac23:~ root# cp ~/src/workspacePt/myFirstXBeeApp/libs/native/Mac_OS_X/librxtxSerial.jnilib /Library/Java/Extensions/librxtxSerial.jnilib
ealmac23:~ root# cp ~cxh/src/workspacePt/myFirstXBeeApp/libs/rxtx-2.2.jar /Library/Java/Extensions/

An alternative is to set java.library.path from the command line:

export JAVAFLAGS=-Djava.library.path=${PTII}/lib
$PTII/bin/vergil -v ptolemy/actor/lib/io/comm/demo/SerialConsole/SerialConsole.xml

Under Eclipse, we can set something in .classpath.

        <classpathentry kind="lib" path="lib/rxtx-2.2.jar">
                <attributes>
                        <attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="myFirstXBeeApp/libs/native/Mac_OS_X"/>
                </attributes>
        </classpathentry>

The problem here is that the value has to have the name of the project in it a runtime. If we hardwire the project name "ptII", then running a model that uses the shared library will only work if the project is named ptII. I was not able to generate a .classpath file that would work if the project name changed. There are a number of variables, but I could not find one that worked here.

Attribute key for a classpath attribute referencing a list of shared libraries that should appear on the -Djava.library.path system property.
The factory methods newLibraryPathsAttribute(String[]) and getLibraryPaths(IClasspathAttribute) should be used to encode and decode the attribute value.
Each string is used to create an IPath using the constructor Path(String), and may contain IStringVariable's. Variable substitution is performed on the string prior to constructing a path from the string. If the resulting IPath is a relative path, it is interpreted as relative to the workspace location. If the path is absolute, it is interpreted as an absolute path in the local file system.

This points to setting the java.library.path variable inside Ptolemy II, which is covered next

Setting the java.library.path property at runtime

The idea is to get the usr_paths field from the ClassLoader and set it and also update the java.library.paths property. This was done in ptolemy.util.StringUtilities. addDirectoryToJavaLibraryPath(String) and addPtolemyLibraryDirectoryToJavaLibraryPath().

$PTII/ptolemy/actor/gui/ConfigurationApplication invokes addPtolemyLibraryDirectoryToJavaLibraryPath().

Now it is possible to open $PTII/ptolemy/actor/lib/io/comm/demo/SerialConsole/SerialConsole.xml using $PTII/bin/vergil and Eclipse.

Mac OS X: Remove the Quarantine Flag from the RXTX jar and native library

As an aside, when files are downloaded, they get a quarantine tag, which shows up as a @ sign when ls is run.

If you need to remove the quarantine tag from a file, do the following:

root# cd /Library/Java/Extensions/
ealmac23:Extensions root# xattr librxtxSerial.jnilib
com.apple.quarantine
ealmac23:Extensions root# xattr -d com.apple.quarantine librxtxSerial.jnilib
ealmac23:Extensions root# xattr librxtxSerial.jnilib
ealmac23:Extensions root# xattr -d com.apple.quarantine rxtx-2.2.jar
ealmac23:Extensions root#

RxTx Versions

There is some confusion about RxTx Versions.

  • http://rxtx.qbang.org/wiki/index.php/Main_Page - The main RxTx page
    • http://users.frii.com/jarvi/rxtx/ - Old RxTx page that includes a timeline:
      • "Wed Feb 4 2009 RXTX 2.2pre2 is available for testing as binaries and source. wiki download. 64 bit fixes, Maintain DTR=false during setSerialPortParams, Solaris build fixes."
    • http://rxtx.qbang.org/wiki/index.php/Download - Has a link for rxtx 2.2pre2:
      • "Release Binary Source"
      • "rxtx 2.2pre2 (prerelease) rxtx-2.2pre2-bins.zip rxtx-2.2pre2.zip"
      • "TODO: The 2.2pre2 bins contain the 2.2pre1 jar file and the 2.2pre2 native lib which causes a mismatch warning"
        • rxtx-2.2pre2-bins.zip contains a Mac OS X 10.5 library from 2009 that has PPC, x86 and x86_64 libraries:
          bash-3.2$ ls -l rxtx-2.2pre2-bins/mac-10.5/librxtxSerial.jnilib  
          -rwxr-xr-x@ 1 cxh  staff  169488 Feb  4  2009 rxtx-2.2pre2-bins/mac-10.5/librxtxSerial.jnilib
          bash-3.2$ file rxtx-2.2pre2-bins/mac-10.5/librxtxSerial.jnilib  
          file rxtx-2.2pre2-bins/mac-10.5/librxtxSerial.jnilib
          rxtx-2.2pre2-bins/mac-10.5/librxtxSerial.jnilib: Mach-O universal binary with 3 architectures
          rxtx-2.2pre2-bins/mac-10.5/librxtxSerial.jnilib (for architecture i386):        Mach-O bundle i386
          rxtx-2.2pre2-bins/mac-10.5/librxtxSerial.jnilib (for architecture x86_64):      Mach-O 64-bit bundle x86_64
          rxtx-2.2pre2-bins/mac-10.5/librxtxSerial.jnilib (for architecture ppc7400):     Mach-O bundle ppc
          bash-3.2$

RxTx Version Mismatch

When running Vergil using the RxTx from the XBeeJava Github installation, we get:

WARNING: RXTX Version mismatch
Jar version = RXTX-2.2pre1
native lib Version = RXTX-2.2 (CVS snapshot 2011.02.03, modified by CMU CREATE Lab, http://code.google.com/p/create-lab-commons/)

This warning can be ignored.

One interesting thing is that this version has a date of 2011, but was based on pre1 instead of pre2?

RxTx Sources

Edit - History - Print - Recent Changes - Search
Page last modified on December 28, 2015, at 05:34 PM