如何实例化打开的串行连接
我需要获取一个已经打开的串行端口连接(例如,连接到设备的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有受支持的方法可以执行此操作。您无法打开已打开的设备(串行端口不允许共享)。
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#.