如何实例化打开的串行连接

发布于 2024-10-06 17:02:39 字数 233 浏览 0 评论 0原文

我需要获取一个已经打开的串行端口连接(例如,连接到设备的 COM1)并询问其波特率、奇偶校验位、停止位等。

那么,有没有一种方法可以获取操作系统的所有打开的串行连接并实例化它们,例如:

SerialPort myTestSP = "Windows.SerialPorts[1]";
int myTestBR = myTestSP.BaudRate;

感谢您的宝贵时间!

I need to take an already opened serial port connection (for example, COM1 connected to a device) and ask its baudrate, parity bit, stop bit, etc.

So, is there a way to take all the opened serial connections of the OS and instantiate them, like:

SerialPort myTestSP = "Windows.SerialPorts[1]";
int myTestBR = myTestSP.BaudRate;

Thanks for your time!

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

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

发布评论

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

评论(1

我很OK 2024-10-13 17:02:39

没有受支持的方法可以执行此操作。您无法打开已打开的设备(串行端口不允许共享)。

Portmon 等程序通过在串行端口堆栈中注入设备驱动程序来工作,并且即使如此,我也很确定它必须在端口关闭时执行此操作。

用 C# 编写这样的驱动程序是不可能的。

There isn't a supported way to do this. You can't open a device that's already open (serial ports do not allow sharing).

Programs such as Portmon work by injecting a device driver in the serial port's stack, and even then I'm pretty sure it has to do it while the port is closed.

It's not possible to write such a driver in C#.

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