如何确定哪个进程正在使用串行端口?

发布于 2024-07-05 07:47:41 字数 292 浏览 6 评论 0原文

我工作的公司生产通过串行端口与计算机通信的硬件。 第三方公司编写与我们的硬件通信的软件。

有时我需要诊断我们的硬件。 但是,当 Windows 启动时,第三方软件应用程序会连接到串行端口,从而阻止任何其他连接。 我不知道该应用程序/服务的名称,并且它并不总是相同的。

有什么方法可以:

  • 查找当前正在使用给定串行端口的应用程序/服务的名称/pid 或
  • 从另一个应用程序窃取串行端口连接。

最好是 vb.net,但我也会采用与语言无关的答案。

The company I work for makes hardware that communicates to the computer though a serial port. Third party companies write software that communicates with our hardware.

There are times when I need to diagnose our hardware. However, a third party software app connects to the serial port when Windows starts up, blocking any other connection. I don't know the name of this application/service and it's not always the same one.

Is there any way to either:

  • Find the name/pid of the app/service that is currently using a given serial port or
  • Steal the serial port connection from another app.

vb.net preferably, but I'll take a language agnostic answer as well.

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

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

发布评论

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

评论(4

倾听心声的旋律 2024-07-12 07:47:41

正如 Rob Walker 所说,您可以使用 进程资源管理器。 大多数时候,输入 Ctrl+F 并搜索“串行”将显示谁打开了串行端口,但我刚刚遇到了一种情况,我的“COM3 " 串口句柄显示为“\Device\VCP0”。 这可能很奇怪,因为它是在带有 USB 转串口连接器的 VirtualBox 下运行的。

如果搜索“serial”和“device\vcp”没有得到任何结果,您可以通过使用已知程序打开串行端口句柄来弄清楚串行端口句柄是如何命名的。 在 Process Explorer 中,通过键入 Ctrl+L 显示下部窗格以及每个进程的打开句柄。 单击用于打开串行端口的进程,然后查看下部窗格以查看哪些句柄看起来可能是串行端口。 您可以在查看时打开和关闭端口,文件句柄应该出现和消失,并以绿色或红色突出显示。 当然,只有当您有多个串行端口或者您尝试诊断的串行端口并不总是被某种神秘进程锁定时,这才有可能。

As Rob Walker said, you can find who's using a serial port using Process Explorer. Most of the time, typing Ctrl+F and searching for "serial" will show you who has a serial port open, but I just ran into a situation where my "COM3" serial port's handle appeared as "\Device\VCP0". It may be strange because it was running under VirtualBox with a USB-to-serial connector.

If searching for "serial" and "device\vcp" don't get you any results, you may be able to figure out how serial port handles are named by opening one with a known program. In Process Explorer, display the lower pane with each process's open handles by typing Ctrl+L. Click on the process that you used to open the serial port and look through the lower pane to see which handles look like they might be a serial port. You can open and close the port while you're looking, and the file handle should appear and disappear, as well as being highlighted in green or red. Of course, this is only possible if you have more than one serial port or the serial port you're trying to diagnose isn't always locked by some mystery process.

审判长 2024-07-12 07:47:41

您还可以使用 SysInternals 中的 进程资源管理器 工具来搜索打开的句柄。 在这种情况下,您可能需要搜索“串行”,因为它使用的设备名称可能无法映射到 com 端口号。 (例如,COM1 在我的系统上是 \Device\Serial0)。

如果您想从另一个应用程序控制串行端口,我认为您需要驱动程序的合作。

You can use the process explorer tool also from SysInternals to search for open handles. In this case you would want to search for 'Serial' since it uses device names that may not map to com port numbers. (e.g. COM1 is \Device\Serial0 on my system).

If you want to take control of the serial port from another app I think you would need co-operation of the driver.

绿萝 2024-07-12 07:47:41

Step1:打开注册表,路径:HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM
找到您的目标 COM 端口句柄名称
通过注册表查找COM端口句柄名称

Step2:打开资源监视器
在任务管理器中打开资源监视器

步骤3:搜索步骤1中的句柄名称
在资源监视器中搜索句柄名称

Step1: open registry, path: HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM
Find your target COM port handle name
find COM port handle name by registry

Step2: Open resource monitor
Open resource monitor in task manager

Step3: search handle name from Step1
Search handle name in resource monitor

雪落纷纷 2024-07-12 07:47:41

Sysinternals 有很多实用程序,我发现对于跟踪非常有用且具有教育意义记录进程正在对系统执行哪些操作。

他们有一个实用程序可以完全满足您的需求,称为 Portmon,并且在页面底部附近提供一些有关其工作原理的信息。 如果实用程序还不够,这些信息和一些常见问题可能会为您提供自己实现它所需的一切。

-亚当

Sysinternals has a slew of utilities I find very useful and educational for tracking down what processes are doing to the system.

They have a utility that does exactly what you need called Portmon, and give some information on how it works near the bottom of the page. That info and a few well-asked questions will probably give you everything you need to implement it yourself if the utility isn't enough.

-Adam

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