如何禁止 FTDI .NET DLL 在未安装驱动程序时提醒用户
我有一个使用 FTDI 的 FTD2XX.DLL 的 C# 应用程序。该应用程序用于多代单一产品并抽象物理硬件。有 FTDI 和 HID 实施。
该应用程序会搜索适当的 FTDI 和 HID 设备,但如果用户具有 HID 生成,则可能不存在 FTDI 驱动程序。
现在先把背景放在一边。当我实例化 FTDI 类时,我得到一个模式,不是由我的代码生成的,关于未找到 FTDI 驱动程序,并询问用户是否安装了驱动程序。我尝试将其包装在 TRY/CATCH 块中,但没有引发异常。
1:有没有办法在尝试实例化 FTDI 类之前确定是否安装了 FTDI 驱动程序?
2:如果没有,有没有办法禁止FTDI dll在发生这种情况时向用户发出警报?
I have a C# application that's using the FTD2XX.DLL from FTDI. This application is used for multiple generations of a single product and abstracts the physical hardware. There's an FTDI and a HID implementation.
The application searches for both appropriate FTDI and HID devices, though it's likely that no FTDI drivers exist if the user has the HID generation.
Background aside now. When I instantiate the FTDI class I get a modal, not generated by my code about not finding the FTDI driver and asks the user if the drivers are installed. I tried wrapping this in a TRY/CATCH block but no exception is thrown.
1: Is there a way to determine if the FTDI drivers are installed before trying to instantiate the FTDI class?
2: If not, is there a way to prohibit the FTDI dll from alerting the user when this happens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我有完全相同的要求 - 在我的例子中,我枚举标准串行端口列表,并将其附加到任何附加 FTDI 设备的列表中。如果未安装驱动程序,那么我希望不要出现这些模式对话框。
我想出的一种快速但肮脏的方法是检查 c:\windows\system32(或安装 Windows 的任何位置)中的文件 FTD2XX.DLL。该文件的存在基本上意味着驱动程序已安装。
I have the exact same requirements - in my case I'm enumerating the list of standard serial ports and appending this with the list of any attached FTDI devices. If the driver isn't installed, then I'd like to not have those modal dialog boxes appear.
One quick and dirty way I've figured out to do this is to check for the file FTD2XX.DLL being in c:\windows\system32 (or wherever windows is installed). The existence of this file basically means the driver is installed.
另一种方式:
Another way:
听起来好像您正在将 FTD2XX.DLL 与您的应用程序捆绑在一起。
您不应该这样做,您应该使用 FTDI 驱动程序安装到 Windows 系统目录中的最新 DLL。如果您的应用程序目录中有旧版本的 DLL,并且用户有较新的驱动程序(可能由其他一些基于 FTDI 的设备安装),您可能会遇到各种麻烦。
作为奖励,这可以解决大多数情况下的问题:如果系统上未安装 FTD2XX.DLL,您将在尝试 p/invoke 时遇到异常,您可以捕获该异常。
但是,为了完美避免该错误,您需要执行与 FTD2XX.DLL 内部相同的检查(因为 DLL 显然可以存在于系统上而无需任何驱动程序)。例如,检查驱动程序是否列在注册表中的
HKLM\System\CurrentControlSet\services
下将是比您现有的检查更可靠的检查。仍然不确定它是否等同于 FTDI 自己的检查。It sounds as though you are bundling FTD2XX.DLL with your application.
You shouldn't do this, you should use the latest DLL installed into the Windows system directory by the FTDI driver. If you have an old version of the DLL in your app directory, and the user has newer drivers (possibly installed by some other FTDI-based device), you could have all kinds of trouble.
As a bonus, this solves your problem in most cases: If FTD2XX.DLL isn't installed on the system, you'll get an exception trying to p/invoke, which you can catch.
To avoid the error perfectly, however, you'll need to do the same check that the FTD2XX.DLL does internally (since the DLL obviously can exist on the system without any driver). For example, checking whether the driver is listed in the registry under
HKLM\System\CurrentControlSet\services
would be a more robust check than the one you have. Still not sure if it's equivalent to FTDI's own check.我重写了导致错误的 FTDI 库:它是由构造函数中的 MessageBox.Show 引起的。我已将其替换为正常的异常抛出。
有关重新设计的包装器和代码,请参阅我的博客:
连接到 Silverlight 中的 FTDI 设备5 RC
I rewrote the FTDI library that was causing the error: it was caused by a MessageBox.Show in the constructor. I have replaced this with a normal Exception throw.
See my blog for the re-engineered wrapper and code:
connecting to FTDI devices in Silverlight 5 RC