Class JTModel

java.lang.Object
  extended byjava.util.Observable
      extended byJTModel

public class JTModel
extends java.util.Observable

JTModel - holds the JTerm connection details and response.

 SerialPort - serial connections for Java
 Copyright (C) 2005  Martin C Gregorie
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 

Contact Martin Gregorie at martin@gregorie.org.
Read the GNU General Public License.


Field Summary
 java.lang.String MSDOS
           
 java.lang.String OS9
           
 java.lang.String UNIX
           
 
Constructor Summary
JTModel(JTerm theApp, java.lang.String progName, int debug)
          The only constructor.
 
Method Summary
 void closePort()
          Stop polling the server.
 int connectServer(java.lang.String host, int port)
          Open a connection to spd, the SerialPort server.
 void disconnectServer()
          Close the server connection and mark as inactive.
 java.lang.String getError()
          Return the error description.
 java.lang.String getHostname()
          Return the TCP/IP hostname of the server.
 java.lang.String getOSList()
          Return the operating system list, used to identify the target operating system.
 java.lang.String getPortList()
          Return the serial port list.
 java.lang.String getPortName()
          Return the serial port name.
 int getPortNumber()
          Return the server's TCP/IP port number.
 java.lang.String getPortParameters()
          Return the serial port parameters.
 java.lang.String getResponse()
          Retrieve any data received from the serial connection.
 int getTabSpace()
          Return the (target operating system dependent) tab spacing.
 java.lang.String getTitle()
          Return the frame title.
 boolean isConnectedToPort()
          Returns true if a serial connection is open.
 boolean isConnectedToServer()
          Returns true if the server connection is open.
 boolean isErrorCondition()
          Check whether an error has ocurred.
 boolean isOSSelected()
          Check whether an operating system has been selected.
 boolean isResponse()
          Check whether new data has been received from the serial port.
 void keyTyped(char c)
          Accept a single character input by the keyboard.
 int openPort(java.lang.String port)
          Cause spd to open the specified serial port.
 void scanForData()
          Poll the server for data.
 void serialError()
          Trap and report SerialPort errors.
 void setOSName(java.lang.String name)
          Store the OS name.
 int setPortParameters(java.lang.String params)
          Store the serial port parameters.
 void startReader()
          Create and start a thread to poll the server for input.
 void updateCompleted()
          Clear the changed flag.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNIX

public final java.lang.String UNIX

OS9

public final java.lang.String OS9

MSDOS

public final java.lang.String MSDOS
Constructor Detail

JTModel

public JTModel(JTerm theApp,
               java.lang.String progName,
               int debug)
The only constructor. It initialises the model by setting defaulting the server host and port to localhost:16001. It marks the the connection as inactive and itself as changed.

Method Detail

connectServer

public int connectServer(java.lang.String host,
                         int port)
Open a connection to spd, the SerialPort server. Store server connection details in the model as plain text, save the final state code and mark the model as changed. Return true if the connection attempt fails.


disconnectServer

public void disconnectServer()
Close the server connection and mark as inactive.


openPort

public int openPort(java.lang.String port)
Cause spd to open the specified serial port. Store port details in the model as plain text, save the final state code and mark the model as changed. Returns a non-zero value if the connection attempt fails.


closePort

public void closePort()
Stop polling the server. Close the port and mark as inactive.


getError

public java.lang.String getError()
Return the error description.


getHostname

public java.lang.String getHostname()
Return the TCP/IP hostname of the server.


getOSList

public java.lang.String getOSList()
Return the operating system list, used to identify the target operating system.


getPortList

public java.lang.String getPortList()
Return the serial port list.


getPortName

public java.lang.String getPortName()
Return the serial port name.


getPortNumber

public int getPortNumber()
Return the server's TCP/IP port number.


getPortParameters

public java.lang.String getPortParameters()
Return the serial port parameters.


getResponse

public java.lang.String getResponse()
Retrieve any data received from the serial connection.


getTabSpace

public int getTabSpace()
Return the (target operating system dependent) tab spacing.


getTitle

public java.lang.String getTitle()
Return the frame title.


isConnectedToServer

public boolean isConnectedToServer()
Returns true if the server connection is open.


isConnectedToPort

public boolean isConnectedToPort()
Returns true if a serial connection is open.


isErrorCondition

public boolean isErrorCondition()
Check whether an error has ocurred.


isResponse

public boolean isResponse()
Check whether new data has been received from the serial port.


isOSSelected

public boolean isOSSelected()
Check whether an operating system has been selected.


keyTyped

public void keyTyped(char c)

Accept a single character input by the keyboard. Pass it to the server and restart the timer so that the next scan interval is short because input is expected.

NOTE: This function puts an error message on the screen if there is no serial connection open.


scanForData

public void scanForData()

Poll the server for data. If any is available it is appended to the receive buffer, the reader thread is prepared to accept more data and screen updating is triggered.

Returns true if and data was received.


serialError

public void serialError()
Trap and report SerialPort errors.


setOSName

public void setOSName(java.lang.String name)
Store the OS name.


setPortParameters

public int setPortParameters(java.lang.String params)
Store the serial port parameters.


startReader

public void startReader()

Create and start a thread to poll the server for input.

The Timer is initially set to its minimum interval so that restarting it when a key has been typed will get a fast response. Its delay time is immediately reset to the maximum interval so the server will be polled slowly until data is transferred.


updateCompleted

public void updateCompleted()
Clear the changed flag.