ComHalfDuplex Class
半双工工作模式的串口 More...
Inherits: | AbstractComm |
Public Functions
Q_INVOKABLE | ComHalfDuplex() |
~ComHalfDuplex() | |
int | blockTime() const |
void | setBlockTime(int blockTime) |
- 4 public functions inherited from AbstractComm
Additional Inherited Members
- 1 property inherited from AbstractComm
- 5 public slots inherited from AbstractComm
- 5 signals inherited from AbstractComm
- 2 protected functions inherited from AbstractComm
- 1 protected slot inherited from AbstractComm
Detailed Description
\author
BriFuture \date
2018.04.27
半双工工作模式的串口
解决上位机发送指令和下位机发送数据同时发生时产生冲突导致 乱码的问题,解决冲突的主要原理是使用 waitForReadyRead 方法 对串口进行阻塞式读取,超时后即认为当前串口未被下位机占用, 此时上位机可以发送指令。 (显然,用 readyRead 信号的异步方式也是可以完成相同的任务的, 只是当想清楚这点时,已经写好了这个类,并且重新构建了 UI-Protocol -Com 之间的结构,因此并未改动 ComFullDuplex 中的代码)
This class is made to solve the problem that occurs when master computer(PC) send instruction into serial port while slave computer send data into serial port and they conflict with each other. The problem is now solved by using the blocking api waitForReadyRead to read the serial port. If blocking api triggers timeout event, it will send the command waiting to be send into serial port. (Obviously it can be replaced with non-blocking api which is driven by readyRead signal, but before it occurs to me that the non-blocking idea can also be used to solve the data conflict problem, I have finished this class and re-implement the structure of UI-Protocol-Com, So I didn't change the code in ComFullDuplex)
Member Function Documentation
Q_INVOKABLE ComHalfDuplex::ComHalfDuplex()
Default constructs an instance of ComHalfDuplex.
ComHalfDuplex::~ComHalfDuplex()
Destroys the instance of ComHalfDuplex.
int ComHalfDuplex::blockTime() const
返回阻塞的等待时间
See also setBlockTime().
void ComHalfDuplex::setBlockTime(int blockTime)
设置阻塞时的等待时间
See also blockTime().