Subversion Repositories Programming Utils

Compare Revisions

Ignore whitespace Rev 96 → Rev 97

/trunk/JavaSerial/src/com/rm5248/serial/NIOSerialPort.java
1,118 → 1,28
package com.rm5248.serial;
 
import java.io.IOException;
import java.nio.channels.ByteChannel;
 
/**
* An implementation of a serial port that uses NIO.
* Note that this <b>DOES NOT</b> automatically listen for changes in
* the serial line state.
*
* @author rm5248
*
*/
public class NIOSerialPort extends SerialPort {
/* The channel that we read/write */
private SerialByteChannel byteChannel;
 
protected NIOSerialPort(String portName, BaudRate rate, DataBits data,
public NIOSerialPort(String portName, BaudRate rate, DataBits data,
StopBits stop, Parity parity, FlowControl flow)
throws NoSuchPortException, NotASerialPortException {
super(portName, rate, data, stop, parity, flow);
// TODO Auto-generated constructor stub
byteChannel = new SerialByteChannel( handle, this );
}
 
@Override
public void setBaudRate(BaudRate rate) {
// TODO Auto-generated method stub
public ByteChannel getByteChannel(){
return byteChannel;
}
 
@Override
public void close() {
// TODO Auto-generated method stub
}
 
@Override
public boolean isClosed() {
// TODO Auto-generated method stub
return false;
}
 
@Override
public void setStopBits(StopBits stop) {
// TODO Auto-generated method stub
}
 
@Override
public void setDataSize(DataBits data) {
// TODO Auto-generated method stub
}
 
@Override
public void setParity(Parity parity) {
// TODO Auto-generated method stub
}
 
@Override
public SerialLineState getSerialLineState() throws IOException {
// TODO Auto-generated method stub
return null;
}
 
@Override
public void setSerialLineState(SerialLineState state) {
// TODO Auto-generated method stub
}
 
@Override
public BaudRate getBaudRate() {
// TODO Auto-generated method stub
return null;
}
 
@Override
public DataBits getDataBits() {
// TODO Auto-generated method stub
return null;
}
 
@Override
public StopBits getStopBits() {
// TODO Auto-generated method stub
return null;
}
 
@Override
public Parity getParity() {
// TODO Auto-generated method stub
return null;
}
 
@Override
public FlowControl getFlowControl() {
// TODO Auto-generated method stub
return null;
}
 
@Override
public void setFlowControl(FlowControl flow) {
// TODO Auto-generated method stub
}
 
@Override
public void setSerialChangeListener(SerialChangeListener listen) {
// TODO Auto-generated method stub
}
 
@Override
public String getPortName() {
// TODO Auto-generated method stub
return null;
}
 
}
/trunk/JavaSerial/src/com/rm5248/serial/IOSerialPort.java
1,7 → 1,6
package com.rm5248.serial;
 
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
 
277,8 → 276,11
if( serialListen != null ){
serialListen.doStop();
}
synchronized( serialListenSync ){
serialListenSync.notify();
if( serialListenSync != null ){
synchronized( serialListenSync ){
serialListenSync.notify();
}
}
}
 
308,7 → 310,7
serialListen.doStop();
}
 
if( listen != null ){
if( listen != null && !ignoringControlLines ){
serialListen = new SerialStateListener( listen );
new Thread( serialListen, "SerialListen" ).start();
}
/trunk/JavaSerial/src/com/rm5248/serial/SerialByteChannel.java
0,0 → 1,54
package com.rm5248.serial;
 
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
 
/**
* An implementation of the ByteChannel interface for use with serial ports.
*
* @author rm5248
*
*/
class SerialByteChannel implements ByteChannel {
@SuppressWarnings("unused")
private int handle;
private SerialPort parent;
SerialByteChannel( int handle, SerialPort parent ){
this.handle = handle;
this.parent = parent;
}
 
@Override
public int read(ByteBuffer arg0) throws IOException {
// TODO Auto-generated method stub
System.out.println( "remaining: " + arg0.remaining() );
return 0;
}
 
@Override
public void close() throws IOException {
// You must close the SerialPort, not the channel.
}
 
@Override
public boolean isOpen() {
return parent.closed;
}
 
@Override
public int write(ByteBuffer arg0) throws IOException {
// TODO Auto-generated method stub
byte[] bb = new byte[ arg0.remaining() ];
System.out.println( "arg0 pos: " + arg0.position() );
System.out.println( "arg0 remain: " + arg0.remaining() );
arg0.get( bb, arg0.position(), arg0.remaining() );
System.out.println( "bb size: " + bb.length );
return 0;
}
 
}