BakeoutController-Basic  0.1
A Controller for the Omicron vacuum chamber
Classes | Public Member Functions | List of all members
kernel.modbus.ModBusConnectionManager Class Reference
Inheritance diagram for kernel.modbus.ModBusConnectionManager:
Inheritance graph
[legend]
Collaboration diagram for kernel.modbus.ModBusConnectionManager:
Collaboration graph
[legend]

Public Member Functions

ModbusPortConfiguration getPortConfiguration ()
 
void setPortConfiguration (ModbusPortConfiguration portConfiguration)
 
Boolean isPortOpen ()
 
void close ()
 
ModbusTransaction getTransactionForRequest (ModbusRequest request) throws WrappedModbusException, IllegalStateException
 
Float parseFloatFromResponse (ModbusMessage response) throws ClassCastException, IOException
 
String parseStringFromResponse (ModbusMessage response) throws ClassCastException, IOException
 

Detailed Description

Manages connections to an RS232 port using MODBUS

Definition at line 24 of file ModBusConnectionManager.java.

Member Function Documentation

void kernel.modbus.ModBusConnectionManager.close ( )

Closes the port and removes the shutdown thread

Implements kernel.modbus.ModbusConnector.

Definition at line 88 of file ModBusConnectionManager.java.

88  {
89  connection.close();
90  removeShutdownThread();
91  }
ModbusPortConfiguration kernel.modbus.ModBusConnectionManager.getPortConfiguration ( )
Returns
The RS232 port config

Implements kernel.modbus.ModbusConnector.

Definition at line 56 of file ModBusConnectionManager.java.

56  {
57  return this.desiredPortConfiguration;
58  }
ModbusTransaction kernel.modbus.ModBusConnectionManager.getTransactionForRequest ( ModbusRequest  request) throws WrappedModbusException, IllegalStateException
Parameters
requestA transaction which, when executed, will retrieve the value at a particular set of registers in the MODBUS device
Returns
The transaction
Exceptions
WrappedModbusExceptionIf the connection cannot be opened.
IllegalStateExceptionIf assertions like the device having a connection, and having a port configuration, fail.

Implements kernel.modbus.ModbusConnector.

Definition at line 103 of file ModBusConnectionManager.java.

104  {
105 
106  log.debug(
107  "Creating transaction for request {}", request.getHexMessage()
108  );
109 
110  if (!isPortOpen()){
111  log.debug("Port {} is not open. Opening now", this);
112  openConnection();
113  log.debug("Port {} successfully opened", this);
114  } else {
115  log.debug("Port {} is open, using for connection", this);
116  }
117  connection.setTimeout(recieveTimeOut);
118 
119  ModbusSerialTransaction transaction = new ModbusSerialTransaction();
120  transaction.setSerialConnection(connection);
121  transaction.setRequest(request);
122  transaction.setRetries(numberOfRetries);
123 
124  return transaction;
125  }
Boolean kernel.modbus.ModBusConnectionManager.isPortOpen ( )
Returns
Boolean#TRUE if the port is open, otherwise Boolean#FALSE. If the connection is null, it is assumed that the connection is not open.

Implements kernel.modbus.ModbusConnector.

Definition at line 76 of file ModBusConnectionManager.java.

76  {
77  if (connection == null){
78  return Boolean.FALSE;
79  } else {
80  return connection.isOpen();
81  }
82  }
Float kernel.modbus.ModBusConnectionManager.parseFloatFromResponse ( ModbusMessage  response) throws ClassCastException, IOException

Helper method to retrieve a float from a MODBUS response.

Parameters
responseThe response to be parsed
Returns
The 32-bit IEEE floating point number contained in the response
Exceptions
ClassCastExceptionIf the message cannot be cast to a response
IOExceptionIf the message cannot be read

Implements kernel.modbus.ModbusConnector.

Definition at line 136 of file ModBusConnectionManager.java.

137  {
138  ModbusResponse inputRegistersResponse = (ModbusResponse) response;
139  ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
140  DataOutput writer = new DataOutputStream(byteBuffer);
141  log.debug(
142  "Received response {}. Parsing to float",
143  inputRegistersResponse.toString()
144  );
145 
146  inputRegistersResponse.writeData(writer);
147 
148  byte[] dataToRead = processByteArray(byteBuffer.toByteArray());
149 
150  DataInput reader = new DataInputStream(
151  new ByteArrayInputStream(dataToRead)
152  );
153 
154  return reader.readFloat();
155 
156  }
String kernel.modbus.ModBusConnectionManager.parseStringFromResponse ( ModbusMessage  response) throws ClassCastException, IOException

Retrieve a string from the data package of the retrieved response

Parameters
responseThe response from which a string must be retrieved
Returns
The string from the data package of the response
Exceptions
ClassCastExceptionIf the ModbusMessage cannot be cast to a ModbusResponse. This cast is required so that the method ModbusResponse#writeData(DataOutput) can be used to extract the response data package
IOExceptionif a string cannot be parsed from the response

Implements kernel.modbus.ModbusConnector.

Definition at line 169 of file ModBusConnectionManager.java.

170  {
171  ModbusResponse inputRegistersResponse = (ModbusResponse) response;
172 
173  ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
174  DataOutput writer = new DataOutputStream(byteBuffer);
175  log.debug(
176  "Received response {}. Parsing to string",
177  inputRegistersResponse.toString()
178  );
179 
180  inputRegistersResponse.writeData(writer);
181 
182  DataInput reader = new DataInputStream(
183  new ByteArrayInputStream(byteBuffer.toByteArray())
184  );
185 
186  return reader.readLine();
187  }
void kernel.modbus.ModBusConnectionManager.setPortConfiguration ( ModbusPortConfiguration  portConfiguration)
Parameters
portConfigurationThe desired port configuration

Implements kernel.modbus.ModbusConnector.

Definition at line 64 of file ModBusConnectionManager.java.

66  {
67  desiredPortConfiguration = portConfiguration;
68  }

The documentation for this class was generated from the following file:
Git Repo