Skip to content

Commit

Permalink
fix(CSerialPortUnixBase): fixed #80 unix read undefinite wait when sy…
Browse files Browse the repository at this point in the history
…nc mode
  • Loading branch information
itas109 committed Dec 24, 2023
1 parent 7ac4dcf commit cd5480b
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/SerialPortUnixBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ int CSerialPortUnixBase::uartSet(int fd, int baudRate, itas109::Parity parity, i

// 设置等待时间和最小接受字符
options.c_cc[VTIME] = 0; // 可以在select中设置
options.c_cc[VMIN] = 1; // 最少读取一个字符
options.c_cc[VMIN] = 0; // read function will undefinite wait when no read data

// 如果发生数据溢出,只接受数据,但是不进行读操作
tcflush(fd, TCIFLUSH);
Expand Down Expand Up @@ -407,13 +407,20 @@ bool CSerialPortUnixBase::openPort()
}
else
{
m_isThreadRunning = true;
bRet = startThreadMonitor();
if (m_operateMode == itas109::/*OperateMode::*/ AsynchronousOperate)
{
m_isThreadRunning = true;
bRet = startThreadMonitor();

if (!bRet)
if (!bRet)
{
m_isThreadRunning = false;
m_lastError = itas109::/*SerialPortError::*/ ErrorInner;
}
}
else
{
m_isThreadRunning = false;
m_lastError = itas109::/*SerialPortError::*/ ErrorInner;
bRet = true;
}
}
}
Expand Down

0 comments on commit cd5480b

Please sign in to comment.