我正在使用 WinLIRC 以及连接到 Windows 7 x64 上串行端口 COM1 的红外接收器。 WinLIRC
被添加到启动文件夹(开始 -> 所有应用程序 -> 启动),因此每次登录时它都会启动。我经常(但并非总是)看到来自 < code>WinLIRC,如果我重试初始化,它会持续一段时间(几分钟),并且在重试几次后,它会正确初始化并正常工作。如果我将其从启动中删除并在任何其他时刻手动启动,它就会正常启动。
我已经下载了 WinLIRC
源代码,并在各处添加了 MessageBox
调用,这样我就可以看到初始化期间发生的情况,并发现 CreateFile
调用失败:
if((hPort=CreateFile(
settings.port,GENERIC_READ | GENERIC_WRITE,
0,0,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0))==INVALID_HANDLE_VALUE)
{
char buffer[256];
sprintf_s(buffer, "CreateFile(%s) failed with %d", settings.port, GetLastError());
MessageBox(NULL, buffer, "debug", MB_OK);
hPort=NULL;
return false;
}
我看到消息框显示“CreateFile(COM1) failed with 5”,根据 此链接。
所以问题是为什么在启动 Windows 后打开 COM 端口会失败并出现此类错误,并在几秒钟或几分钟后正常进行?
更新:COM端口是真实的。
Update2:关于WinLIRC
之前打开串口的其他应用程序。我执行了以下操作:我将 Process Explorer 放入启动文件夹中,以便它启动也登录,然后重新启动。进程资源管理器一启动,我就运行“查找句柄或 Dll”对话框,将“Serial0”输入到输入中,然后单击“搜索”。此时,WinLIRC 已经显示消息框“CreateFile(COM1) failed with 5”。然后我等到进程资源管理器搜索结束,发现什么也没找到,然后尝试重新初始化WinLIRC,但又失败了。所以我建议不是串口被其他应用程序打开的情况。如果有人能提出更好的检查方法,我会很乐意重新检查。
当我在 WinLIRC 运行时在进程资源管理器中搜索“Serial0”时,它会找到 winlirc.exe
进程,因此看起来它是正确的搜索术语。
Update3:关于串口鼠标驱动。它没有在设备管理器中列出,所以我无法在那里禁用它,但是我发现此有关如何禁用的说明sermouse
服务但没有帮助。
更新4:还有一件事我忘了提。仅当我在启动电脑后立即登录时才会发生这种情况。如果我将窗口留在登录屏幕上几分钟并稍后登录,则 WinLIRC 初始化总是不会出现任何问题。
更新5:不幸的是,我无法访问重现此问题的计算机,因此我无法再进行实验。
I'm using WinLIRC with IR receiver connected to serial port COM1 on Windows 7 x64. WinLIRC
is added to Startup folder (Start->All applications->Startup) so it starts every time I log in. Very often (but not all the time) I see initialization error messages from WinLIRC
, which continue for some time (couple of minutes) if I retry initialization, and after some retries it initializes correctly and works fine. If I remove it from Startup and start manually at any other moment it starts without errors.
I've downloaded WinLIRC
sources and added MessageBox
calls here and there so I can see what happens during initialization and found out that CreateFile
call fails:
if((hPort=CreateFile(
settings.port,GENERIC_READ | GENERIC_WRITE,
0,0,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0))==INVALID_HANDLE_VALUE)
{
char buffer[256];
sprintf_s(buffer, "CreateFile(%s) failed with %d", settings.port, GetLastError());
MessageBox(NULL, buffer, "debug", MB_OK);
hPort=NULL;
return false;
}
I see message box saying "CreateFile(COM1) failed with 5", and 5 is an error code for "Access denied" error according to this link.
So the question is why opening COM-port can fail with such error right after booting Windows and proceed normally few seconds or minutes later?
Update: the COM-port is the real one.
Update2: regarding the other application that opens serial port before WinLIRC
. I did the following: I put Process Explorer to the Startup folder so it start on log in also, then rebooted. As soon as process explorer started I ran "Find Handle or Dll" dialog, put "Serial0" to the input and hit "Search". By that moment WinLIRC had already shown message box saying "CreateFile(COM1) failed with 5". Then I waited till the process explorer search ends, seen that it found nothing, then tried to reinitialize WinLIRC and it failed again. So I suggest that it is not the case of serial port being opened by other application. If anyone can suggest a better way to check it, I'll happily recheck.
When I search for "Serial0" in process explorer while WinLIRC is running it finds the winlirc.exe
process, so it looks like it is correct term to search.
Update3: regarding the serial mouse driver. It is not listed in device manager, so I wasn't able to disable it there, however I have found this instructions on how to disable sermouse
service and it didn't help.
Update4: one more thing I forgot to mention. It happens only if I log in soon after booting PC. If I leave windows on log in screen for several minutes and log in later, then WinLIRC initializes without any problems always.
Update5: Unfortunately, I don't have access to the computer that had this problem reproducing, so I can't experiment anymore.
发布评论
评论(2)
初始化端口需要时间。
您的应用程序将在 Windows XP 上运行得非常好。
Windows7的串口是虚拟的。
您可以运行一个小代码并检查一下
使用系统.IO.端口;
这将返回串行端口列表。检查其状态并将其显示在消息框中。
编写此代码并在启动时运行。您将找到根本原因。
It takes time to initialize the port.
Your application will run absolutely fine on windows XP.
Windows7's serial ports are virtual.
You can run a small code and check it out
using System.IO.Ports;
This will return you the list of serial port. Check the status of it and display it on message box.
Make this code and run at startup. You'll get the root cause.
在进入 Windows 串行编程的神奇世界之前,必须访问以下一些链接:)
Windows 串行编程的详细说明:
http://www.codeguru.com/cpp/in/network/serialcommunications/article.php/c5425/Serial-Communication-in-Windows.htm
有点过时了(该网站状态 1999-2003 所以是的,它已经过时了)但绝对有用:
http://www.flounder.com/serial.htm
Here some links one has to visit before plunging into the magic world of serial programming in Windows :)
A detailed explanation of serial programming in Windows:
http://www.codeguru.com/cpp/i-n/network/serialcommunications/article.php/c5425/Serial-Communication-in-Windows.htm
a little bit outdated (the site states 1999-2003 so yes, it's outdated) but absolutely useful:
http://www.flounder.com/serial.htm