 1Content-type: application/x-Unknown; charset=UTF8package nmc.sidekick;

import javax.comm.SerialPort;
import javax.comm.CommPortIdentifier;
import java.io.InputStream;
import java.io.OutputStream;

public class DebugMessage {
	private int level;
	private  static int outDevice;
	public  static final int NO_DEBUG=0;
	public static final int SYSTEM_OUT=1;
	public static final int SERIAL=1;
	private static SerialPort serialPort;
	private static OutputStream os;
	private static CommPortIdentifier commPortId;
	
public static void setSerialDevice(String dev){

	serialPort = null;
	try {
	    System.out.println("opening port: " + dev);
                commPortId = CommPortIdentifier.getPortIdentifier(dev);
                serialPort = (SerialPort)commPortId.open(dev, 0);
	    serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
	    serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
                System.out.println("port config: "+serialPort.getBaudRate()+" "+serialPort.getParity()+" "+serialPort.getDataBits()+" "+serialPort.getStopBits());
                os = serialPort.getOutputStream();
    } catch (javax.comm.PortInUseException e) {
        System.err.println("Could not open port " + dev + " (already in use), exception: " + e);
        return;
    } catch (javax.comm.NoSuchPortException e2) {
        System.err.println("javax.comm.NoSuchPortException on '"+ dev + "', exception: " + e2);
        return;
    }catch(javax.comm.UnsupportedCommOperationException e3){
        System.err.println("javax.comm.UnsupportedCommOperationException on '"+ dev + "', exception: " + e3);        
        return;	
    }catch(java.io.IOException e4){
        System.err.println("java.io.IOException on '"+ dev + "', exception: " + e4);        
        return;
    }	
}
public static void println(String s){
	switch(outDevice){
		case NO_DEBUG:
		break;
		case SYSTEM_OUT:
		System.out.println(s);
		break;
		default:
		break;
	}// end switch
}
public static void println(Exception e){
	switch(outDevice){
		case NO_DEBUG:
		break;
		case SYSTEM_OUT:
		System.out.println(e);
		break;
		default:
		break;
	}// end switch
}
public static void print(String s){
	switch(outDevice){
		case NO_DEBUG:
		break;
		case SYSTEM_OUT:
		System.out.print(s);
		break;
		default:
		break;
	}// end switch
}
public static void print(Exception e){
	switch(outDevice){
		case NO_DEBUG:
		break;
		case SYSTEM_OUT:
		System.out.print(e);
		break;
		default:
		break;
	}// end switch
}

public static void setOutDevice(int dev){
outDevice=dev;
}
}// end class DebugMessage