BakeoutController-Basic  0.1
A Controller for the Omicron vacuum chamber
DeviceSetupController.java
1 package ui.controllers;
2 
4 import gnu.io.PortInUseException;
5 import gnu.io.UnsupportedCommOperationException;
6 import javafx.collections.ObservableList;
7 import javafx.fxml.FXML;
8 import javafx.scene.control.ComboBox;
9 import javafx.scene.paint.Color;
10 import javafx.scene.text.Text;
11 import kernel.Kernel;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17 import org.springframework.beans.factory.annotation.Autowired;
18 import ui.Controller;
19 
20 import java.io.IOException;
21 import java.util.List;
22 
27 @Controller
28 public class DeviceSetupController {
29 
33  private static final Logger log = LoggerFactory.getLogger(
34  DeviceSetupController.class);
35 
39  @Autowired private Kernel kernel;
40 
44  @FXML private ComboBox<String> tdkPortSelector;
45 
50  @FXML private ComboBox<String> pvciPortSelector;
51 
55  @FXML private Text statusReportField;
56 
60  @FXML public void initialize(){
61  initializePortList();
62  }
63 
68  @FXML public void handleGoButtonClicked(){
69  configurePowerSupply();
70  configurePressureGauge();
71  }
72 
76  public Kernel getKernel(){
77  return kernel;
78  }
79 
83  public void setKernel(Kernel kernel){
84  this.kernel = kernel;
85  }
86 
90  private void initializePortList(){
91  ObservableList<String> portsInBox = tdkPortSelector.getItems();
92  ObservableList<String> portsInPVCiSelector = pvciPortSelector
93  .getItems();
94 
95  CommPortReporter reporter = kernel.getCommPortReporter();
96 
97  List<String> serialPortNames = reporter.getSerialPortNames();
98 
99  portsInBox.addAll(serialPortNames);
100  portsInPVCiSelector.addAll(serialPortNames);
101 
102  tdkPortSelector.getSelectionModel().select(0);
103  pvciPortSelector.getSelectionModel().select(0);
104  }
105 
109  private void configurePowerSupply(){
110  String portName = tdkPortSelector.getSelectionModel().getSelectedItem();
111 
112  TDKLambdaPowerSupplyFactory factory = kernel.getPowerSupplyFactory();
113  factory.setPortName(portName);
114 
115  try {
116  factory.makePowerSupply();
117  } catch (IOException error){
118  handleIOException();
119  } catch (UnsupportedCommOperationException error){
120  handleUnsupportedCommException();
121  } catch (PortInUseException error){
122  handlePortInUseException();
123  } catch (DeviceAlreadyCreatedException error){
124  handleDeviceAlreadyCreatedException();
125  }
126  }
127 
131  private void handleIOException(){
132  writeErrorMessage(
133  "Port was opened, but unable to establish device I/O",
134  "io-exception-message"
135  );
136  }
137 
142  private void handleUnsupportedCommException(){
143  writeErrorMessage(
144  "Unable to set parameters to establish serial port " +
145  "connection",
146  "comm-operation-exception-message"
147  );
148  }
149 
153  private void handlePortInUseException(){
154  writeErrorMessage(
155  "Unable to acquire port. Port is already in use.",
156  "port-in-use-exception-message"
157  );
158  }
159 
167  private void writeErrorMessage(String text, String fieldId){
168  statusReportField.setText(text);
169  statusReportField.setFill(Color.RED);
170  statusReportField.setId(fieldId);
171  }
172 
178  private void handleDeviceAlreadyCreatedException(){
179  statusReportField.setText(
180  "Attempted to create power supply twice"
181  );
182  statusReportField.setId(
183  "device-created-exception-message"
184  );
185  }
186 
190  private void configurePressureGauge(){
191  String portName = pvciPortSelector.getSelectionModel()
192  .getSelectedItem();
193 
194  PVCiPressureGaugeFactory factory = kernel.getPressureGaugeFactory();
195 
196  factory.setPortName(portName);
197  factory.setAddress(2);
198 
199  try {
200  factory.makePressureGauge();
201  } catch (IOException error){
202  handlePVCiIOException(error);
203  }
204  }
205 
211  private void handlePVCiIOException(Throwable error){
212  log.error("Setup thew exception", error);
213  writeErrorMessage(
214  "Unable to establish communication with Pressure Gauge",
215  "pvci-io-exception-message"
216  );
217  }
218 }
List< String > getSerialPortNames()
Git Repo