我应该保持串行端口连接打开吗?
我正在使用串行通信,我想知道是否应该保持串行端口打开?
我正在创建一个命令队列,一次只会运行一个命令。我应该创建一个 SerialPort 并在每个命令中打开/关闭它,还是应该有另一个类来保持端口打开并从命令中调用?或者这真的很重要吗?
I am working with serial communication and I'm wondering whether I should keep the SerialPort open or not?
I'm creating a queue of commands and only one will be running at a time. Should I create a SerialPort and open/close it in each command, or should I have another class which holds the port open and is called from the commands? Or does it really matter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
保持打开状态。没有必要花费打开和关闭它的开销。
Keep it open. No point to have the overhead of opening and closing it.
除了 C. Ross 的回答之外,保持它打开可以防止其他任何东西打开串行端口并在以后阻止您。我建议保持开放。
In addition to C. Ross's answer, keeping it open will prevent anything else from opening the SerialPort and blocking you later. I would suggest keeping it open.