BakeoutController  0.1
A Controller for the Omicron vacuum chamber
TDKLambdaPowerSupply.java
1 package devices;
2 
5 
6 import java.io.IOException;
7 
11 public class TDKLambdaPowerSupply extends RS232Device implements PowerSupply {
15  private final int deviceAddress;
16 
32  String deviceName, PortCommunicator portCommunicator, int
33  deviceAddress
34  ) throws IOException {
35  super(deviceName, portCommunicator);
36  this.deviceAddress = deviceAddress;
37  this.startDevice();
38  }
39 
43  @Override public String getName(){
44  return deviceName;
45  }
46 
50  @Override public int getDeviceAddress(){
51  return this.deviceAddress;
52  }
53 
58  @Override public Double getVoltage() throws IOException {
59  return this.writeWithDoubleResponse(GET_VOLTAGE_COMMAND);
60  }
61 
67  @Override public void setVoltage(double newVoltage) throws IOException {
68  String commandToWrite = String.format(
70  );
71  this.writeWithOKResponse(commandToWrite);
72  }
73 
78  @Override public void reset() throws IOException {
79  this.writeWithOKResponse(RESET_COMMAND);
80  }
81 
88  @Override public Double getCurrent() throws IOException {
89  return this.writeWithDoubleResponse(GET_CURRENT_COMMAND);
90  }
91 
96  @Override public void setCurrent(double newCurrent) throws IOException {
97  String commandToWrite = String.format(
99  );
100 
101  this.writeWithOKResponse(commandToWrite);
102  }
103 
109  @Override public void outputOff() throws IOException {
110  String commandToWrite = String.format(
112  );
113 
114  this.writeWithOKResponse(commandToWrite);
115  }
116 
122  @Override public void outputOn() throws IOException {
123  String command = String.format(
125  );
126 
127  this.writeWithOKResponse(command);
128  }
129 
137  private void startDevice() throws IOException {
138  String commandToWrite = String.format(GET_ADDRESS_COMMAND,
139  deviceAddress);
140 
141  this.writeWithOKResponse(commandToWrite);
142  }
143 
154  private Double writeWithDoubleResponse(String commandToWrite) throws
155  IOException {
156  this.write(commandToWrite);
157  String response = this.read();
158 
159  return Double.parseDouble(response);
160  }
161 
167  private void writeWithOKResponse(String commandToWrite) throws
168  IOException {
169  this.write(commandToWrite);
170  String response = this.read();
171 
172  if (!response.equals(PowerSupply.OK_RESPONSE)){
173  throw new ResponseNotOKException("Did not receive response of " +
174  String.format("%s", PowerSupply.OK_RESPONSE));
175  }
176  }
177 }
void setVoltage(double newVoltage)
void setCurrent(double newCurrent)
TDKLambdaPowerSupply(String deviceName, PortCommunicator portCommunicator, int deviceAddress)
Git Repo