fix serial port device crash (#134)

* fix resourceerror in serialport implemention and  extend error output

* cleanup

* fix json schema

* remove some nerd setting
This commit is contained in:
redPanther 2016-07-20 23:26:47 +02:00 committed by GitHub
parent 230cf9e970
commit fff42f370c
4 changed files with 73 additions and 5 deletions

View File

@ -96,7 +96,7 @@
{
"id" : "default",
"leds" : "*",
"temperatureValues" :
"correctionValues" :
{
"red" : 255,
"green" : 255,

View File

@ -540,6 +540,30 @@
"minimum" : 0.0,
"maximum" : 1.0
},
"unknownFrameCnt" :
{
"type" : "number",
"required" : false,
"minimum" : 0
},
"borderFrameCnt" :
{
"type" : "number",
"required" : false,
"minimum" : 0
},
"maxInconsistentCnt" :
{
"type" : "number",
"required" : false,
"minimum" : 0
},
"blurRemoveCnt" :
{
"type" : "number",
"required" : false,
"minimum" : 0
},
"mode" :
{
"type" : "string",

View File

@ -17,10 +17,50 @@ LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned b
, _blockedForDelay(false)
, _stateChanged(true)
{
connect(&_rs232Port, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(error(QSerialPort::SerialPortError)));
}
void LedRs232Device::error(QSerialPort::SerialPortError error)
{
if ( error != QSerialPort::NoError )
{
switch (error)
{
case QSerialPort::DeviceNotFoundError:
Error(_log, "An error occurred while attempting to open an non-existing device."); break;
case QSerialPort::PermissionError:
Error(_log, "An error occurred while attempting to open an already opened device by another process or a user not having enough permission and credentials to open."); break;
case QSerialPort::OpenError:
Error(_log, "An error occurred while attempting to open an already opened device in this object."); break;
case QSerialPort::NotOpenError:
Error(_log, "This error occurs when an operation is executed that can only be successfully performed if the device is open."); break;
case QSerialPort::ParityError:
Error(_log, "Parity error detected by the hardware while reading data. This value is obsolete. We strongly advise against using it in new code."); break;
case QSerialPort::FramingError:
Error(_log, "Framing error detected by the hardware while reading data. This value is obsolete. We strongly advise against using it in new code."); break;
case QSerialPort::BreakConditionError:
Error(_log, "Break condition detected by the hardware on the input line. This value is obsolete. We strongly advise against using it in new code."); break;
case QSerialPort::WriteError:
Error(_log, "An I/O error occurred while writing the data."); break;
case QSerialPort::ReadError:
Error(_log, "An I/O error occurred while reading the data."); break;
case QSerialPort::ResourceError:
Error(_log, "An I/O error occurred when a resource becomes unavailable, e.g. when the device is unexpectedly removed from the system."); break;
case QSerialPort::UnsupportedOperationError:
Error(_log, "The requested device operation is not supported or prohibited by the running operating system."); break;
case QSerialPort::TimeoutError:
Error(_log, "A timeout error occurred."); break;
default: Error(_log,"An unidentified error occurred. (%d)", error);
}
_rs232Port.clearError();
}
}
LedRs232Device::~LedRs232Device()
{
disconnect(&_rs232Port, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(error(QSerialPort::SerialPortError)));
if (_rs232Port.isOpen())
{
_rs232Port.close();
@ -78,12 +118,16 @@ int LedRs232Device::writeBytes(const unsigned size, const uint8_t * data)
}
_rs232Port.flush();
int result = _rs232Port.write(reinterpret_cast<const char*>(data), size);
_rs232Port.waitForBytesWritten(100);
qint64 result = _rs232Port.write(reinterpret_cast<const char*>(data), size);
if ( result < 0 || result != size)
{
return -1;
}
Debug(_log, "write %d ", result);
_rs232Port.flush();
return (result<0) ? -1 : 0;
return 0;
}

View File

@ -48,7 +48,7 @@ protected:
private slots:
/// Unblock the device after a connection delay
void unblockAfterDelay();
void error(QSerialPort::SerialPortError error);
private:
// tries to open device if not opened
bool tryOpen();