数据实时显示
我正在设计一个应用程序来收集我的车辆数据并将其显示在应用程序上。我试图找出我的软件的最佳架构是什么。我计划在我的 gui (QPainter) 中使用 Qt,并且我有自定义硬件来收集来自传感器的数据。我原本认为硬件 I/O 将驻留在在自己的线程中渲染图形的应用程序中,但现在我认为最好将所有硬件 I/O 通信放在一个单独的进程中并在两个进程之间进行通信使用某些 IPC 协议进行处理(不确定是哪一种)。
你们建议我做什么。这也是我第一次编写多进程应用程序。
I am designing an application to collect my vehicles data and display it on an application. I'm trying to figure out what the best archtitecure of my software would be. I plan on using Qt for my gui (QPainter) and I have custom hardware that collects the data from sensors. I was thinking that the hardware I/O would reside in the application that renders the graphics in its own thread, but now I am thinking it might be better to put all the Hardware I/O comm in a seperate process and communicate between the two processes with some IPC protocol (not sure which one).
What do you guys recommend me doing. This would also be my first time writing a multi-process application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这样的事情我已经写过数百遍了。到目前为止,最好的解决方案是将专用硬件分成两个线程或任务:
这两个线程相互协作以维护一致的信号量-受保护的共享变量空间。第二个线程在锁定共享空间之前完成所有解析等工作,复制所需的任何内容,然后解锁。目标是将锁定间隔限制为尽可能短的时间。通常,将所有共享变量排列到一个结构中并使用批量
memcpy()
是很实用的,即使只有少数成员感兴趣。这种交互越简单越好。UI 包含的
其他架构也是可能的,但每当我看到它们时,它们都已经变成了巨大的补丁,以解决同步和计时问题。
I have written such things hundreds of times. By far, the best solution is to split the dedicated hardware into two threads or tasks:
These two threads cooperate with each other to maintain a consistent, semaphore-protected shared variable space. The second thread does all its parsing and whatnot before locking the shared space, makes a copy of whatever it needs, and unlocks. The goal is to limit the locking interval to as short a time as possible. Oftentimes, it is practical to arrange all the shared variables into a single structure, and use a bulk
memcpy()
, even if only a few members are of interest. The simpler this interaction, the better.The UI contains
Other architectures are possible, but whenever I've seen them, they have devolved into huge steaming masses of patches to work around synchronization and timing issues.