Forums > Java

Rxtx – serial object alternative

July 10, 2008 | 12:45 pm

not being happy with the serial object im trying a java alternative.
i found http://www.rxtx.org/, a java comm object for serialparallel ports.
i am having problems with the calling the readSerial thread.

import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

import java.io.IOException;
import java.io.InputStream;

import com.cycling74.max.*;

public class Rxtx extends MaxObject
{

public Rxtx()
{
super();
}

public void open(){
try{
post("connect…");
(new Rxtx()).connect("COM4");

} catch ( Exception e )
{
e.printStackTrace();
}
}

public void listPorts()
{
java.util.Enumeration portEnum =
CommPortIdentifier.getPortIdentifiers();
while ( portEnum.hasMoreElements() )
{
CommPortIdentifier portIdentifier = (CommPortIdentifier)
portEnum.nextElement();
post(portIdentifier.getName() );
}
}

void connect ( String portName ) throws Exception
{
CommPortIdentifier portIdentifier =
CommPortIdentifier.getPortIdentifier(portName);
if ( portIdentifier.isCurrentlyOwned() )
{
post("Error: Port is currently in use");
}
else
{
CommPort commPort =
portIdentifier.open(this.getClass().getName(),2000);

if ( commPort instanceof SerialPort )
{
SerialPort serialPort = (SerialPort) commPort;

serialPort.setSerialPortParams(57600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);

InputStream in = serialPort.getInputStream();

(new Thread(new SerialReader(in))).start();

}
else
{
post("Error: Only serial ports are handled by this
example.");
}
}
}

/** */
public class SerialReader implements Runnable
{
InputStream in;

public SerialReader ( InputStream in )
{
this.in = in;
}

public void run ()
{
byte[] buffer = new byte[1024];
int len = -1;
try
{
while ( ( len = this.in.read(buffer)) > -1 )
{
outlet(0,new String(buffer,0,len));
}
}
catch ( IOException e )
{
e.printStackTrace();
}
}
}

}


December 9, 2008 | 1:57 am

Hi Yair,
Did you ever make any progress on this?
Thanks,
David


November 11, 2009 | 7:50 pm

I think I may have RXTX working in MaxMSP in widndows at least. You need to copy the rxtxSerial.dll, librxtxSerial.so and librxtxSerial.jnilib into the Max 5.0/support/

I get the following dumped to the console

Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7

which seems good. I haven’t coded the bit that actually does anything yet, will report success/faliure.


November 7, 2011 | 4:11 pm

Hi crx091081gb, is there anything to report on the rxtx port to max? I am in need of this and don’t want to reinvent the wheel.

artelse


Viewing 4 posts - 1 through 4 (of 4 total)