ikayaki.squid
Class Degausser

java.lang.Object
  extended by ikayaki.squid.Degausser
All Implemented Interfaces:
SerialIOListener, EventListener

public class Degausser
extends Object
implements SerialIOListener

Offers an interface for controlling the degausser (demagnetizer). Because the data link is implemented in the degausser by a single board computer running a small basic program, the response time of the degausser to commands is slow. This class will make sure that commands are not sent faster than the device can handle.

Author:
Aki Korpua

Field Summary
private  int degausserDelay
          1-9 seconds default delay 1 second
private  int degausserRamp
          (3, 5, 7, 9) default 3
private  boolean demagnetizing
           
private  double maximumField
           
private  Stack<String> messageBuffer
          buffer for incoming messages, readed when needed.
private  double minimumField
           
private  int pollTimeout
           
private  SynchronousQueue<String> queue
          Synchronous queue for waiting result message from degausser
protected  SerialIO serialIO
          COM port for communication.
private  boolean waitingForMessage
           
 
Constructor Summary
Degausser()
          Creates a new degausser interface.
 
Method Summary
protected  void blockingWrite(String command)
           
 boolean demagnetizeY(double amp)
          Performs full sequence to demagnetize Y (and X) coil with the given amplitude.
 boolean demagnetizeZ(double amp)
          Performs full sequence to demagnetize Z coil with the given amplitude.
protected  void executeRampCycle()
          Performs Ramp up and down.
protected  void executeRampDown()
          Brings Ramp down.
protected  void executeRampUp()
          Performs Ramp up.
 int getAmplitude()
          Sends amplitude query to degausser and returns answer.
 char getCoil()
          Sends coil query to degausser and returns answer.
 int getDelay()
          Sends delay query to degausser and returns answer.
 int getRamp()
          Sends ramp query to degausser and returns answer.
 char getRampStatus()
          Sends status query to degausser and returns answer.
 boolean isDemagnetizing()
           
 boolean isOK()
          Checks if connection is ok.
 void serialIOEvent(SerialIOEvent event)
          Propagates serial port message event.
protected  void setAmplitude(double amplitude)
          Sets amplitude to ramp, range 1.0 to maximumField.
protected  void setCoil(char coil)
          Sets coil X,Y,Z.
 void updateSettings()
          Checks which settings have changed and updates the degausser interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messageBuffer

private Stack<String> messageBuffer
buffer for incoming messages, readed when needed.


queue

private SynchronousQueue<String> queue
Synchronous queue for waiting result message from degausser


pollTimeout

private int pollTimeout

serialIO

protected SerialIO serialIO
COM port for communication.


degausserDelay

private int degausserDelay
1-9 seconds default delay 1 second


degausserRamp

private int degausserRamp
(3, 5, 7, 9) default 3


waitingForMessage

private boolean waitingForMessage

minimumField

private double minimumField

maximumField

private double maximumField

demagnetizing

private boolean demagnetizing
Constructor Detail

Degausser

public Degausser()
          throws SerialIOException
Creates a new degausser interface. Opens connection to degausser COM port (if not open yet) and reads settings from the Setting class.

Throws:
SerialIOException
Method Detail

updateSettings

public void updateSettings()
Checks which settings have changed and updates the degausser interface. This method will be called by the Squid class.


setCoil

protected void setCoil(char coil)
Sets coil X,Y,Z.

Parameters:
coil - coil to set on.

setAmplitude

protected void setAmplitude(double amplitude)
Sets amplitude to ramp, range 1.0 to maximumField. A value of 1.0 will actually be rounded to 1.1 which is the actual minimum amplitude of the degausser.

Parameters:
amplitude - amplitude to demag.
Throws:
IllegalArgumentException - if the amplitude is not in the allowed range.

executeRampUp

protected void executeRampUp()
Performs Ramp up. If this is used, make sure you Ramp down in less than 10 seconds because it can damage coil


executeRampDown

protected void executeRampDown()
Brings Ramp down.


executeRampCycle

protected void executeRampCycle()
Performs Ramp up and down.


blockingWrite

protected void blockingWrite(String command)
                      throws SerialIOException
Throws:
SerialIOException

demagnetizeZ

public boolean demagnetizeZ(double amp)
Performs full sequence to demagnetize Z coil with the given amplitude. Blocking method.

Parameters:
amp - amplitude to demag.
Returns:
true if process was sended succesfully, otherwise false.

demagnetizeY

public boolean demagnetizeY(double amp)
Performs full sequence to demagnetize Y (and X) coil with the given amplitude. Blocking method.

Parameters:
amp - amplitude to demag.
Returns:
true if process was sended succesfully, otherwise false.

isDemagnetizing

public boolean isDemagnetizing()

getRampStatus

public char getRampStatus()
Sends status query to degausser and returns answer. Blocking.

Returns:
Z=Zero, T=Tracking, ?=Unknown

getRamp

public int getRamp()
Sends ramp query to degausser and returns answer. Blocking.

Returns:
3, 5, 7 or 9

getDelay

public int getDelay()
Sends delay query to degausser and returns answer. Blocking.

Returns:
1 to 9 as seconds

getCoil

public char getCoil()
Sends coil query to degausser and returns answer. Blocking.

Returns:
X=X Axis, Y=Y Axis, Z=Z Axis, ?=Unknown

getAmplitude

public int getAmplitude()
Sends amplitude query to degausser and returns answer. Blocking.

Returns:
0 to 3000

isOK

public boolean isOK()
Checks if connection is ok.

Returns:
true if ok.

serialIOEvent

public void serialIOEvent(SerialIOEvent event)
Description copied from interface: SerialIOListener
Propagates serial port message event.

Specified by:
serialIOEvent in interface SerialIOListener
Parameters:
event - the event that happened.