// ComPort.java
//
// Copyright (C) 1998 Henrik Bjorkman. This is free software you 
// may use, copy and distribute this program freely. But you
// must do it on your own risk. No responsibilities taken and
// all rights reserved.
//
// This class is an interface between a java program and a serial 
// port. It an abstract class so that one program can be used with 
// or without the Java comm API.
//
//
// Credits
//
// SUNs jdk 1.1.7 was used when developing this program.
//
//
// History
// 1998-06-19 Created by Henrik Bjorkman
//
// 2000-06-13
// Changed package name to chartplotter_package.
// Henrik
//

package chartplotter_package;
import java.io.*;

public abstract class ComPort
{
  static final int API=1;
  static final int PROCESS=2;
  static final int SEARCH=3;


  static void error(String s)
  {
    System.err.println("ChartThread: " + s);
    System.exit(0);
  }

  static ComPort startCommunication(int comMethod, String portName)
  {
    ComPort comPort=null;

    switch(comMethod)
    {
      case API : comPort=new ComPortAPI(portName);break;
      case PROCESS : comPort=new ComPortProcess(portName);break;
      case SEARCH : 
      {
        try
        {
          comPort=new ComPortAPI(portName);
        }
        catch (NoClassDefFoundError e) 
        {
          comPort=new ComPortProcess(portName);
        }
        break;
      }
      default : break;
    }

    if (comPort==null) {error("No communication method selected or found.");}
    return(comPort);
  }

  /*public abstract ComPort(String portName);*/
  abstract public String readLine();
  abstract public void serialClose();
}



