upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
HWXPXX Class Reference

UPM API for the Veris HWXPXX Hardware Protocol Humidity and Temperature Sensor. More...

Detailed Description

This module implements support for the Veris HWXPHTX Hardware Protocol Humidity and Temperature Sensor family. It uses MODBUS over an RS485 interface. You must have libmodbus v3.1.2 (or greater) installed to compile and use this driver.

This module was developed using libmodbus 3.1.2, and the HWXPHTX. This sensor supports humidity, and optionally, temperature, slider switch, and override switch reporting. The HWXPHTX used to develop this driver did not include the optional slider or override switches, however support for them is provided.

It was developed using an RS232->RS485 inteface. You cannot use the built in MCU TTL UART pins for accessing this device – you must use a full serial RS232->RS485 interface connected via USB.

string defaultDev = "/dev/ttyUSB0";
// if an argument was specified, use it as the device instead
if (argc > 1)
defaultDev = string(argv[1]);
cout << "Using device " << defaultDev << endl;
cout << "Initializing..." << endl;
// Instantiate an HWXPXX instance, using MODBUS slave address 3, and
// default comm parameters (19200, 8, N, 2)
upm::HWXPXX *sensor = new upm::HWXPXX(defaultDev, 3);
// output the Slave ID (manufacturer, model, serno)
cout << "Slave ID: " << sensor->getSlaveID() << endl;
// stored temperature and humidity offsets
cout << "Temperature Offset: " << sensor->getTemperatureOffset()
<< endl;
cout << "Humidity Offset: " << sensor->getHumidityOffset()
<< endl;
cout << endl;
// update and print available values every second
while (shouldRun)
{
// update our values from the sensor
sensor->update();
// we show both C and F for temperature
cout << "Temperature: " << sensor->getTemperature()
<< " C / " << sensor->getTemperature(true) << " F"
<< endl;
cout << "Humidity: " << sensor->getHumidity()
<< " %" << endl;
cout << "Slider: " << sensor->getSlider() << " %" << endl;
cout << "Override Switch Status: " << sensor->getOverrideSwitchStatus()
<< endl;
cout << endl;
sleep(1);
}
cout << "Exiting..." << endl;
delete sensor;

Public Types

enum  INPUT_REGS_T { INPUT_HUMIDITY = 0x0000, INPUT_TEMPERATURE = 0x0001, INPUT_SLIDER = 0x0002 }
 
enum  COIL_REGS_T { COIL_TEMP_SCALE = 0x0000, COIL_OVERRIDE = 0x0001 }
 
enum  HOLDING_REGS_T { HOLDING_TEMP_OFFSET = 0x0000, HOLDING_HUM_OFFSET = 0x0001 }
 

Public Member Functions

 HWXPXX (std::string device, int address, int baud=19200, int bits=8, char parity='N', int stopBits=2)
 
 ~HWXPXX ()
 
void update ()
 
float getTemperature (bool fahrenheit=false)
 
float getHumidity ()
 
int getSlider ()
 
bool getOverrideSwitchStatus ()
 
void clearOverrideSwitch ()
 
int getTemperatureOffset ()
 
int getHumidityOffset ()
 
void setTemperatureOffset (int offset)
 
void setHumidityOffset (int offset)
 
void setTemperatureScale (bool fahrenheit)
 
std::string getSlaveID ()
 
void setSlaveAddress (int addr)
 
void setDebug (bool enable)
 

Protected Member Functions

int readInputRegs (INPUT_REGS_T reg, int len, uint16_t *buf)
 
uint16_t readInputReg (INPUT_REGS_T reg)
 
int readCoils (COIL_REGS_T reg, int numBits, uint8_t *buf)
 
bool readCoil (COIL_REGS_T reg)
 
void writeCoil (COIL_REGS_T reg, bool val)
 
int readHoldingRegs (HOLDING_REGS_T reg, int len, uint16_t *buf)
 
uint16_t readHoldingReg (HOLDING_REGS_T reg)
 
void writeHoldingReg (HOLDING_REGS_T reg, int value)
 

Protected Attributes

modbus_t * m_mbContext
 
bool m_isCelcius
 

Constructor & Destructor Documentation

HWXPXX ( std::string  device,
int  address,
int  baud = 19200,
int  bits = 8,
char  parity = 'N',
int  stopBits = 2 
)

HWXPXX constructor

Parameters
devicePath to the serial device
addressThe MODBUS slave address
baudThe baudrate of the device. Default: 19200
bitsThe number of bits per byte. Default: 8
parityThe parity of the connection, 'N' for None, 'E' for Even, 'O' for Odd. Default: 'N'
stopBitsThe number of stop bits. Default: 2

Here is the call graph for this function:

~HWXPXX ( )

HWXPXX Destructor

Member Function Documentation

void update ( void  )

Read current values from the sensor and update internal stored values. This method must be called prior to querying any values, such as temperature, humidity, override switch status, or slider switch status.

float getTemperature ( bool  fahrenheit = false)

Get the current temperature. update() must have been called prior to calling this method. If this option was not installed, this method will always return 0C/0F, depending on the scale the device is operating in natively.

Parameters
fahrenheittrue to return the temperature in degrees fahrenheit, false to return the temperature in degrees celcius. The default is false (degrees Celcius).
Returns
The last temperature reading in Celcius or Fahrenheit
float getHumidity ( void  )

Get the current relative humidity. update() must have been called prior to calling this method.

Returns
The last humidity reading
int getSlider ( )

Get the current slider switch position. update() must have been called prior to calling this method. This returns a value between 0-100 corresponding to the position of the slider switch. If this option is not installed, this method will always return 0.

Returns
The last slider switch reading
bool getOverrideSwitchStatus ( )

Get the current override switch status. update() must have been called prior to calling this method. This returns true if the override switch was pressed. Use clearOverrideSwitch() to reset this value to false. If this option is not installed, then this method will always return false. It is not possible to programatically set this value to true - that can only be done by physically pressing the override switch.

Returns
The last overide switch status reading
void clearOverrideSwitch ( )

Clear the override switch status (set it to false). If this option is not installed, then this method will have no effect (the overide switch status will always be false).

int getTemperatureOffset ( )

Return the current temperature offset stored on the device. This is a value between -50 and +50, specified in tenths of a degree in whatever scale (Celcius or Fahrenheit) is in use. This offset is applied to the returned temperature reading by the device.

Returns
The current temperature offset in tenths of a degree
int getHumidityOffset ( )

Return the current humidity offset stored on the device. This is a value between -100 and +100, specified in tenths of a percent. This offset is applied to the returned humidity reading by the device.

Returns
The current humidity offset in tenths of a percent
void setTemperatureOffset ( int  offset)

Set the stored temperature offset on the device. This is a value between -50 and +50, specified in tenths of a degree in what ever scale (Celcius or Fahrenheit) is in use. This offset is applied to the returned temperature reading by the device.

Parameters
offsetOffset in tenths of a degree with a range of -50 to +50
void setHumidityOffset ( int  offset)

Set the stored humidity offset on the device. This is a value between -100 and +100, specified in tenths of a percent. This offset is applied to the returned humidity reading by the device.

Parameters
offsetOffset in tenths of a percent with a range of -100 to +100
void setTemperatureScale ( bool  fahrenheit)

Set the temperature scale used by the device. This driver detects this setting automatically and adjusts itself accordingly, so this is generally never needed. It is used to set the native reporting scale of the temperature either in degrees Celcius or Fahrenheit. Its setting will not affect the operation of getTemperature().

Parameters
fahrenheittrue to set Fahrenheit, false to set Celcius
string getSlaveID ( )

Return a string corresponding the the device's MODBUS slave ID. This includes information such as the manufacturer, device model number and serial number.

Returns
string represnting the MODBUS slave ID
void setSlaveAddress ( int  addr)

Set a new MODBUS slave address. This is useful if you have multiple HWXPXX devices on a single bus. When this method is called, the current temperature scale is re-read so that further update() calls can work correctly.

Parameters
addrThe new slave address to set
void setDebug ( bool  enable)

Enable or disable debugging output. This primarily enables and disables libmodbus debugging output.

Parameters
enabletrue to enable debugging, false otherwise

Here is the caller graph for this function:


The documentation for this class was generated from the following files: