发现在C#中的串行端口 [英] Discover serial ports in C#
问题描述
我正在写通讯通过发送字节到USB端口的应用程序。我想允许用户选择的端口要做到这一点,我用 SerialPort.GetPortNames()
。不幸的是,它返回一个空数组。该方法据说读取注册表数据(HKEY_LOCAL_MACHINE \ HARDWARE \ DEVICEMAP \ SERIALCOMM),但SERIALCOMM目录丢失。当我在Linux上运行的程序,它会列出我的四个USB接口,符合市场预期。我怎样才能修复注册表以不同的方式/发现端口?
I'm writing an application that communicates by sending bytes to the USB port. I'd like to allow the user to choose the port and to do that, I use SerialPort.GetPortNames()
. Unfortunately, it returns an empty array. The method supposedly reads the registry for data (HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM), but the SERIALCOMM directory is missing. When I run the program on Linux, it lists my four USB ports, as expected. How can I fix the registry/discover the ports in a different way?
推荐答案
在 SerialPort.GetPortNames()
是发现串行端口的正确方法。但是,如果你使用的是Windows 7,我认为它可能是与该注册表项此方法列出的权限问题。我发现它在<一个描述这个问题后href="http://social.technet.microsoft.com/Forums/lt-LT/w7itprogeneral/thread/e84cb844-9970-42fd-abac-d5616ec791e2"相对=nofollow> Microsoft.com 。
The SerialPort.GetPortNames()
are the correct method to discover serial ports. But if you are using Windows 7, I think it could be issues with permissions on the registry keys this method lists. I found a post which describe this problem at Microsoft.com.
这篇关于发现在C#中的串行端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!