Release exclusive access to serial port on close
After ending program execution and closing the opened serial port, the serial port could not be opened again because it is busy. After some investigation, this could be tracked down to the exclusive access to the serial port which is being set in Open(...).
To fix this, the serial port must be released from exclusive access in Close():
// Release the serial port from exclusive access.
if (mExclusiveAccess)
{
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-vararg)
if(call_with_retry(ioctl, this->mFileDescriptor, TIOCNXCL) == -1)
{
err_msg += ", ";
err_msg += std::strerror(errno);
}
}
As an additional configuration option, I've added the exclusive flag that allows to specify whether to require exclusive access to the serial port or not.
Hi @labradon , nice work. Apologies for the delay in review. I'll get a chance to run the unit tests on my hardware setup later this week.
@crayzeewulf , any concerns?
@crayzeewulf , any concerns?
(Thanks, @labradon) Looks good overall @mcsauder . I would like to run some tests this week before merging too. Please give me a couple of days and I will report back with my test results.
Hi @crayzeewulf . Existing unit tests continue to pass, but they were not capturing this particular case on my hardware on the master branch either. The PR seems good to me, but I'd defer to your experience here.
@labradon , can you reproduce the failure with the unit tests, or is there a unit test we can add to catch this case?