5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory;
8 import java.io.IOException;
9 import java.util.concurrent.locks.Lock;
10 import java.util.concurrent.locks.ReentrantLock;
22 private static final Lock portCommunicatorLock =
new ReentrantLock();
27 private static final Logger log = LoggerFactory.getLogger(
34 private final int deviceAddress;
52 )
throws IOException {
53 super(portCommunicator);
54 this.deviceAddress = deviceAddress;
62 return this.deviceAddress;
69 @Override
public Double
getVoltage() throws IOException {
78 return this.writeWithDoubleResponse(GET_MEASURED_VOLTAGE_COMMAND);
86 @Override
public void setVoltage(
double newVoltage)
throws IOException {
87 String commandToWrite = String.format(
90 this.writeWithOKResponse(commandToWrite);
97 @Override
public void reset() throws IOException {
115 @Override
public void setCurrent(
double newCurrent)
throws IOException {
116 String commandToWrite = String.format(
120 this.writeWithOKResponse(commandToWrite);
129 String commandToWrite = String.format(
133 this.writeWithOKResponse(commandToWrite);
141 @Override
public void outputOn() throws IOException {
142 String command = String.format(
146 this.writeWithOKResponse(command);
156 private void startDevice()
throws IOException {
160 this.writeWithOKResponse(commandToWrite);
173 private Double writeWithDoubleResponse(String commandToWrite)
throws 175 portCommunicatorLock.lock();
177 this.write(commandToWrite);
178 log.debug(
"Writing command {} to power supply.", commandToWrite);
179 String response = this.read();
180 log.debug(
"Received response {} from power supply", response);
182 portCommunicatorLock.unlock();
184 return Double.parseDouble(response);
192 private void writeWithOKResponse(String commandToWrite)
throws 194 portCommunicatorLock.lock();
196 this.write(commandToWrite);
199 "Writing command %s to power supply",
203 String response = this.read();
206 "Received response %s from power supply",
216 portCommunicatorLock.unlock();
String SET_VOLTAGE_COMMAND
void setVoltage(double newVoltage)
void setCurrent(double newCurrent)
String GET_CURRENT_COMMAND
String SET_CURRENT_COMMAND
String SET_OUTPUT_COMMAND
String GET_VOLTAGE_COMMAND
String GET_ADDRESS_COMMAND
Double getMeasuredVoltage()
TDKLambdaPowerSupply(PortCommunicator portCommunicator, int deviceAddress)