我正在尝试打开一个串行端口,以便我可以使用下面的标准 CreateFile() 代码从设备接收 Uart 数据;
HANDLE hComm; // Handle to the Serial port
char ComPortName[] = "COM4"; // Name of the Serial port(May Change) to be opened,
/*---------------------------------- Opening the Serial Port -------------------------------------------*/
hComm = CreateFile(ComPortName, // Name of the Port to be Opened
GENERIC_READ | GENERIC_WRITE, // Read/Write Access
0, // No Sharing, ports cant be shared
NULL, // No Security
OPEN_EXISTING, // Open existing port only
0, // Non Overlapped I/O
NULL); // Null for Comm Devices
if (hComm == INVALID_HANDLE_VALUE)
printf("\n Error! - Port %s can't be opened\n", ComPortName);
else
printf("\n Port %s Opened\n ", ComPortName);
然而,每次它返回一个无效的句柄。恐怕我有点新手,但我对此进行了很好的研究,但我看不出有什么原因?!我已经按照另一篇文章的建议尝试了“COM4:”,并且"\\\\.\\COM4"
(尽管我知道这应该只对 com 端口 10 及以上有效),但仍然没有乐趣!该端口肯定在那里,因为我可以使用 Teraterm 和 RealTerm 很好地连接和接收数据,而且它也不是已经在使用的情况。
我在带有 Boot Camp 的 Mac 上使用 Windows 10,想知道这是否是个问题?我在一个线程中读到,如果 Windows 没有被正确激活,则会出现问题,但它有点模糊。
任何建议将不胜感激,在此先感谢。