jmce - 1_02

jmce.sim.serial
Class PolledSerial

java.lang.Object
  extended by jmce.sim.AbstractHardware
      extended by jmce.sim.AbstractPeripheral
          extended by jmce.sim.Device<java.lang.Integer>
              extended by jmce.sim.Serial
                  extended by jmce.sim.serial.PolledSerial
All Implemented Interfaces:
java.lang.Runnable, Console, DeviceConsumer<java.lang.Integer>, Hardware, Peripheral
Direct Known Subclasses:
RXTX, TCPSocket

public abstract class PolledSerial
extends Serial
implements java.lang.Runnable, DeviceConsumer<java.lang.Integer>

Abstract base class for serial polled device.

This base class is used for all Serial implemented in polling mode. One thread is created for each port and the sub class must implements only the method relative to the connection of the port. When connected automatically thru Input/Output stream this class delivery the data to and from the device.

Version:
1.02
Author:
Mario Viara

Field Summary
protected  boolean connected
           
protected  java.io.InputStream is
          Input stream
protected  java.io.OutputStream os
          Output stream
protected  long rcvd
           
protected  long sent
           
 
Fields inherited from class jmce.sim.AbstractPeripheral
cpu
 
Constructor Summary
PolledSerial()
           
 
Method Summary
protected  void close()
          Close the input and output stream and set the connection to false.
protected abstract  void connect()
          Implemented by sub class.
 void consume(java.lang.Integer c)
          Receive data from the input device if the device is connected the data are delivery to the output stream.
protected  void delay(int delay)
          Wait for the specified number of ms.
 void init(Hardware parent)
          Initialize the hardware.
 void run()
          Thread to handle the connection and the input stream.
 
Methods inherited from class jmce.sim.Serial
print, println, println, putchar
 
Methods inherited from class jmce.sim.Device
addInputConsumer, addInputProducer, addOutputConsumer, addOutputProducer, getConnected, read, readOutput, readyRead, readyReadOutput, readyWrite, removeInputConsumer, removeOutputConsumer, setConnected, write, writeInput
 
Methods inherited from class jmce.sim.AbstractPeripheral
idle, registerCPU, setIdle, setLive
 
Methods inherited from class jmce.sim.AbstractHardware
addHardware, createFrame, destroy, getHardware, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareForName, getHardwareInstances, getHardwareTree, getName, getParent, initSwing, removeHardware, removeHardware, reset, setHardware, setHardware, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jmce.sim.Hardware
addHardware, destroy, getHardware, getHardware, getHardware, getHardware, getHardwareCount, getHardwareInstances, getHardwareTree, getName, getParent, initSwing, removeHardware, removeHardware, reset, setHardware, setHardware, setName
 

Field Detail

sent

protected long sent

rcvd

protected long rcvd

connected

protected boolean connected

is

protected java.io.InputStream is
Input stream


os

protected java.io.OutputStream os
Output stream

Constructor Detail

PolledSerial

public PolledSerial()
Method Detail

consume

public void consume(java.lang.Integer c)
             throws SIMException
Receive data from the input device if the device is connected the data are delivery to the output stream.

Specified by:
consume in interface DeviceConsumer<java.lang.Integer>
Throws:
SIMException

init

public void init(Hardware parent)
          throws SIMException
Description copied from interface: Hardware
Initialize the hardware. This method must be called before any use of the interface. Only set ... / get ... method are allowed to be called before the intialization.

Specified by:
init in interface Hardware
Overrides:
init in class AbstractHardware
Parameters:
parent - Parent of this hardware.
Throws:
SIMException

delay

protected void delay(int delay)
Wait for the specified number of ms. Ignore any exception


close

protected void close()
Close the input and output stream and set the connection to false. All exception are ignored.


run

public final void run()
Thread to handle the connection and the input stream.

Specified by:
run in interface java.lang.Runnable

connect

protected abstract void connect()
                         throws java.lang.Exception
Implemented by sub class.

Must set the stream to the appropriated value and set connected true.

Throws:
java.lang.Exception

jmce - 1_02