Subversion Repositories Programming Utils

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

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;
        }

}