Index: trunk/code/projects/calibration_platform/server/DEV-NOTES.txt
===================================================================
--- trunk/code/projects/calibration_platform/server/DEV-NOTES.txt	(nonexistent)
+++ trunk/code/projects/calibration_platform/server/DEV-NOTES.txt	(revision 1946)
@@ -0,0 +1,122 @@
+DEV-NOTES - Development notes for the cal_sta_server Java code
+Author: John Sexton
+Date: 3/20/11
+
+
+SUMMARY:
+-Tried to install Sun's Java Comm API, doesn't work for 64-bit machines.
+-Changed from open source IcedTea Java 6 to Sun's Java 6.
+-Tried to install RXTX library. Need special version for 64-bit. Does not
+   allow you to open any port, only can open what it scans.
+-Downloaded RXTX source code, added "arduino" and "robot" port prefixes
+   to RXTX library, compiled it and installed it on Marvin.
+
+USEFUL JAVA LOCATIONS:
+/usr/lib/jvm -
+   location of java installations
+
+/usr/lib/jvm/java-6-sun/jre/lib/ext -
+   java extension .jar files (like RXTXcomm.jar) go here (for Sun's Java)
+
+/usr/lib/jvm/java-6-sun/jre/lib/amd64 -
+   the librxtx______.so files go here (for Sun's Java + 64-bit)
+
+   /usr/lib/jvm/java-6-sun/jre/lib/amd64
+                     ^               ^
+                Sun's Java       64-bit architecture
+
+
+USEFUL WEBSITES:
+http://en.wikibooks.org/wiki/Serial_Programming/Serial_Java -
+   General overview of serial programming in Java.
+
+http://download.oracle.com/docs/cd/E17802_01/products/products/javacomm/reference/api/index.html -
+   API for javax.comm / gnu.io
+
+http://www.capybara.org/~dfraser/archives/29 -
+   Article describing how to edit RXTX source code to add port prefixes.
+
+http://rxtx.qbang.org/wiki/index.php/Main_Page -
+   RXTX development wiki. Very good resource for installing and obtaining
+   source code.
+
+http://www.cloudhopper.com/opensource/rxtx/ -
+   Location of 64-bit compiled binaries for RXTX library.
+
+
+
+
+
+NOTES:
+
+Java does not play nice with serial ports right out of the box. You must
+install additional libraries to gain the ability to speak to serial ports
+in Java. The most common library that I found is the JAVA COMMUNICATIONS
+API LIBRARY.
+
+
+== Sun's Java Communications API ==
+
+Sun does a very poor job of maintaining this library (after all, they
+support platform-independent development and this is difficult when a
+serial port inherently relies on the underlying hardware). My first
+attempts to successfully listen over a serial port involved using Sun's
+implementation of the Java Communications API. It was difficult to find a
+good download of this online, but I eventually ended up using an Oracle
+website (http://www.oracle.com/technetwork/java/index-jsp-141752.html) to
+obtain the library. Followed installation instructions and successfully
+installed, but when I tried to run a program I got an error which cited
+the ELF compiled binary file. Also mentioned the word size might be wrong.
+This error was confirmed online where I found support for the fact that
+Sun/Oracle only supports 32-bit versions of the Java Communications API
+and doesn't support windows. All of these limitations led me to abandon
+using Sun's version.
+
+
+== RXTX Library ==
+
+I found an open source library called the RXTX library which follows the
+Java Communications API exactly (except it's called 'gnu.io' instead of
+'javax.comm'). The development website
+(http://rxtx.qbang.org/wiki/index.php/Main_Page) was very useful. I was
+able to successfully install the RXTX library, but when I tried to run
+sample code, Java seg-faulted (OMG... XD). In an attempt to fix this, I
+removed the open source IcedTea java and installed Sun's Java, but the
+error still remained. I then traced the error back to the Thread function,
+so I believe the problem is not actualy with the RXTX functionality that
+we need and instead has to do with using threads with the RXTX library.
+
+I proceeded to write a small Java program to test the
+RXTX library, and discovered that you can only address ports which the
+library finds on its own. This was a problem because the library only
+looked for a few prefixes and did not show the 'arduino' or the 'robot#'
+nodes in the /dev folder. I found an article online
+(http://www.capybara.org/~dfraser/archives/29) which describes how
+to edit the source code for the RXTX library to include more ports. I
+used the link included in the article to obtain the source code, but when
+I edited the necessary source file (RXTXCommDriver.java), recompiled it
+into a .jar file again (had to remove a 'import javax.comm.*' line from
+the source file which seemed strange to me), and transfered it into the
+proper directory (/usr/lib/jvm/java-6-sun/jre/lib/ext) it did not work.
+Java threw an error which I can't remember the content of at the moment
+(but it wasn't a seg-fault like the thread error). To obtain a better copy
+of the source code, I again resorted to the RXTX development wiki
+(http://rxtx.qbang.org/wiki/index.php/Main_Page). I downloaded a recent
+copy of the source code, unzipped it, ran '/configure', and ran 'make'.
+I received some errors, but there was still a brand new 'RXTXComm.jar'
+file in the folder now, so I proceeded to install it
+(replace the RXTXComm.jar file in the
+/usr/lib/jvm/java-6-sun/jre/lib/ext folder). To my relief, my test program
+did NOT throw an error this time. I did get a warning that looked like this:
+
+WARNING:  RXTX Version mismatch
+        Jar version = RXTX-2.2
+        native lib Version = RXTX-2.2pre2 
+
+(versions are not the same as the versions I saw, but I did have a mismatch
+warning). To solve this, I just went back to the development wiki and
+found the version that made these two lines agree (turned out to be 
+rxtx-2.2pre2). Now (finally), my little test program can find the 'arduino'
+and 'robot#' ports and listen to them!
+
+Hope this helps for anyone who has to take this project up after me!
Index: trunk/code/projects/calibration_platform/server/cal_sta_server/SimpleRead.java
===================================================================
--- trunk/code/projects/calibration_platform/server/cal_sta_server/SimpleRead.java	(nonexistent)
+++ trunk/code/projects/calibration_platform/server/cal_sta_server/SimpleRead.java	(revision 1946)
@@ -0,0 +1,127 @@
+import gnu.io.*;
+
+public class SimpleRead {
+
+	static CommPortIdentifier portId;
+    static Enumeration	      portList;
+    InputStream		      inputStream;
+    SerialPort		      serialPort;
+    Thread		      readThread;
+
+    public static void main(String[] args) {
+    boolean		      portFound = false;
+    String		      defaultPort = "/dev/ttyUSB0";
+
+ 	if (args.length > 0) {
+	    defaultPort = args[0];
+	} 
+   
+	portList = CommPortIdentifier.getPortIdentifiers();
+
+	while (portList.hasMoreElements()) {
+	    portId = (CommPortIdentifier) portList.nextElement();
+	    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
+		if (portId.getName().equals(defaultPort)) {
+		    System.out.println("Found port: "+defaultPort);
+		    portFound = true;
+		    SimpleRead reader = new SimpleRead();
+		} 
+	    } 
+	} 
+	if (!portFound) {
+	    System.out.println("port " + defaultPort + " not found.");
+	} 
+
+    Opens
+    } 
+
+    /**
+     * Constructor declaration
+     *
+     *
+     * @see
+     */
+    public SimpleRead() {
+	try {
+	    serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
+	} catch (PortInUseException e) {}
+
+	try {
+	    inputStream = serialPort.getInputStream();
+	} catch (IOException e) {}
+
+	try {
+	    serialPort.addEventListener(this);
+	} catch (TooManyListenersException e) {}
+
+	serialPort.notifyOnDataAvailable(true);
+
+	try {
+	    serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, 
+					   SerialPort.STOPBITS_1, 
+					   SerialPort.PARITY_NONE);
+	} catch (UnsupportedCommOperationException e) {}
+
+	readThread = new Thread(this);
+
+	readThread.start();
+    }
+
+    /**
+     * Method declaration
+     *
+     *
+     * @see
+     */
+    public void run() {
+	try {
+	    Thread.sleep(20000);
+	} catch (InterruptedException e) {}
+    } 
+
+    /**
+     * Method declaration
+     *
+     *
+     * @param event
+     *
+     * @see
+     */
+    public void serialEvent(SerialPortEvent event) {
+	switch (event.getEventType()) {
+
+	case SerialPortEvent.BI:
+
+	case SerialPortEvent.OE:
+
+	case SerialPortEvent.FE:
+
+	case SerialPortEvent.PE:
+
+	case SerialPortEvent.CD:
+
+	case SerialPortEvent.CTS:
+
+	case SerialPortEvent.DSR:
+
+	case SerialPortEvent.RI:
+
+	case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
+	    break;
+
+	case SerialPortEvent.DATA_AVAILABLE:
+	    byte[] readBuffer = new byte[20];
+
+	    try {
+		while (inputStream.available() > 0) {
+		    int numBytes = inputStream.read(readBuffer);
+		} 
+
+		System.out.print(new String(readBuffer));
+	    } catch (IOException e) {}
+
+	    break;
+	}
+    } 
+
+}
\ No newline at end of file
Index: trunk/code/projects/calibration_platform/server/cal_sta_server/SimpleSerial.java
===================================================================
--- trunk/code/projects/calibration_platform/server/cal_sta_server/SimpleSerial.java	(nonexistent)
+++ trunk/code/projects/calibration_platform/server/cal_sta_server/SimpleSerial.java	(revision 1946)
@@ -0,0 +1,71 @@
+import java.io.*;
+import java.util.Enumeration;
+import gnu.io.*;
+
+import java.lang.Character;
+
+public class SimpleSerial {
+
+	public static void main(String[] args) {
+		
+		String port_path = "/dev/ttyUSB0";
+/*
+		FileInputStream port_stream;
+		
+		try {
+			port_stream = new FileInputStream(port_path);
+		} catch (IOException e) {
+			System.out.print(e);
+		}
+		
+		port_stream.getFD()
+*/
+		
+		
+		Enumeration ports = CommPortIdentifier.getPortIdentifiers();
+		CommPortIdentifier port = null, arduino = null;
+		
+		SerialPort ser = null;
+		InputStream inSt = null;
+		
+		while (ports.hasMoreElements()) {
+			
+			port = (CommPortIdentifier)ports.nextElement();
+			
+			System.out.println(port.getName());
+			
+			if (port.getName().equals("/dev/arduino")) {
+				arduino = port;
+			}
+			
+		}
+		
+		System.out.println(arduino.getName());
+		
+		try{
+			ser = (SerialPort) arduino.open("cal_sta_server", 2000);
+		} catch (PortInUseException e) {System.out.print(e);}
+		
+		try {
+		    inSt = ser.getInputStream();
+		} catch (IOException e) {System.out.print(e);}
+		
+		try {
+		    ser.setSerialPortParams(19200, SerialPort.DATABITS_8, 
+						   SerialPort.STOPBITS_1, 
+						   SerialPort.PARITY_NONE);
+		} catch (UnsupportedCommOperationException e) {}
+		
+		while (true) {
+			
+			try {
+				if (inSt.available() > 0) {
+					System.out.print((char)inSt.read());
+				}
+			} catch (IOException e) {System.out.print(e);}
+			
+		}
+		
+	}
+
+}
