package testPack;
import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
public class CommExp
{
SerialPort serialPort;
public CommExp()
{
super();
}
void changeDTR(boolean b)
{
serialPort.setDTR(b);
}
// START OF METHOD connect(String)
void connect ( String portName ) throws Exception
{
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
if ( portIdentifier.isCurrentlyOwned() )
{
System.out.println("Error: Port is currently in use");
}
else
{
CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);
if ( commPort instanceof SerialPort )
{
serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
}
else
{
System.out.println("Error: Only serial ports are handled by this example.");
}
}
}
// END OF METHOD connect(String)
private boolean getDTRStatus()
{
return serialPort.isDTR();
}
public void changeRTS(boolean b)
{
serialPort.setRTS(b);
}
}