hyperion.ng/libsrc/hyperion/device/LedRs232Device.cpp
T. van der Zwan c787241747 Moved all device to seperate directory
Added 'sedu' device based on RS232 device


Former-commit-id: 918cbde65a4a14f532c2e08e104745715c3fdd37
2013-11-05 16:18:04 +00:00

63 lines
997 B
C++

// STL includes
#include <cstring>
#include <cstdio>
#include <iostream>
// Local Hyperion includes
#include "LedRs232Device.h"
LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned baudrate) :
mDeviceName(outputDevice),
mBaudRate_Hz(baudrate),
_rs232Port()
{
// empty
}
LedRs232Device::~LedRs232Device()
{
if (_rs232Port.isOpen())
{
_rs232Port.close();
}
}
int LedRs232Device::open()
{
try
{
_rs232Port.setPort(mDeviceName);
_rs232Port.setBaudrate(mBaudRate_Hz);
_rs232Port.open();
}
catch (const std::exception& e)
{
std::cerr << "Unable to open RS232 device (" << e.what() << ")" << std::endl;
return -1;
}
return 0;
}
int LedRs232Device::writeBytes(const unsigned size, const uint8_t * data)
{
if (!_rs232Port.isOpen())
{
return -1;
}
try
{
_rs232Port.write(data, size);
}
catch (const std::exception& e)
{
std::cerr << "Unable to write to RS232 device (" << e.what() << ")" << std::endl;
return -1;
}
return 0;
}