访问两个线程内的串行连接状态
我正在尝试设置另一个线程来当前检查所引用对象的状态。
主线程是运行程序并处理串行连接状态的线程。
第二个线程需要访问连接状态以继续从缓冲区发送和接收命令。
这可以吗?
I'm trying to set up another thread that currently checks the status of the object being referenced.
The main thread is what runs the program and also handles the serial connection state.
The second thread needs to access the connection state to continue sending and receiving commands from the buffer.
Is this possible to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然。控制串行设备的线程需要提供一个线程安全的只读属性,该属性会记住它读取的最后一个状态。另一个线程可以随时读取该属性。
这是一个简单的解决方案:
编辑(看到评论后)
Sure. The thread controlling the serial device needs to provide a thread-safe read-only property which remembers the last state that it read. The other thread can than read that propery whenever it would like.
Here's a simple solution:
Edit (after seeing the comments)