打开和关闭com端口

发布于 2024-09-14 19:47:50 字数 149 浏览 3 评论 0原文

我有一个使用继电器控制器开门的小应用程序。如果有人进来,我必须一直打开和关闭 COM 端口。早上,当很多人聚集在一起时,控制器响应非常慢,我需要快速解决这个问题。

我的问题是,如果我一直保持打开状态,我会遇到内存问题吗?如果应用程序崩溃并重新启动,是否会打开端口回收?

I have a small application to open the door using a relay controller. I have to open and close the COM port all time if someone comes in. In the morning, when lots of people come together controller responds very slow and i need to solve this problem fast.

My question is, will i run in to memory issues if i keep it open all time time? will open port recycle if application crashes and restart ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把昨日还给我 2024-09-21 19:47:50

我认为你不会遇到内存问题。我编写了一个使用条形码扫描仪的程序,该扫描仪使用 COM 端口来侦听来自扫描仪的事件。我在程序启动时打开它,并保持打开状态,直到程序完全没有问题地关闭。

唯一需要担心的是 COM 端口一次只能由一个对象使用,因此如果您的程序已经打开它并尝试再次打开它,那就是一个问题。

该程序可能会使 COM 端口保持打开状态,因此您最好尝试打开它,如果失败,请尝试关闭它(两个单独的 try...catch 块),然后再次尝试打开它。这很麻烦,但在我的应用程序中,它减少了我必须解决的错误数量。为了安全起见,我只是在每次程序加载时打开/关闭/打开。

I don't think you'll run into memory problems. I wrote a program that uses a bar code scanner that uses a COM port to listen to events from the scanner. I open it when the program launches and keep it open until the program closes with no issues at all.

The only thing to worry about is that the COM port can only be used by one object at a time, so if your program already has it open and tries to open it again, that's a problem.

The program may leave the COM port open, so you're best off to try opening it, and if that fails, try closing it (two separate try...catch blocks) and then try opening it again. It's a hassle, but in my app it turned out to reduce the number of errors I had to troubleshoot. I just open/close/open every time the program loads to be safe.

屋顶上的小猫咪 2024-09-21 19:47:50
  • 保持打开状态没有问题,
  • 如果应用程序死亡,它会关闭 com 端口,

唯一的问题是,有时如果您没有正确关闭 com 端口,它可以使您的应用程序保持活动状态,作为一个处于挥之不去的非死亡状态的进程,从而保持com 端口。

  • no issue with keeping it open
  • it will close the com port if the app dies

only thing is, sometimes if you don't shut down the com port properly it can keep your app alive as a process in a lingering non dying state which keeps the com port.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文