我有一个Delphi桌面应用程序,它使用TComport2010来执行USB / COM通信。这个应用程序,从USB设备读取coords X,Y并在Windows桌面模拟鼠标上戳。一切正常,除非尝试移动OSK的窗口(在屏幕键盘上),此问题已通过管理员权限或清单上的uiAccess = true
运行的应用程序修复,请参阅此处的讨论:OSK access problem
在上面的帖子中建议的以下解决方案,我可以在OSK上戳鼠标事件。
但是,当使用跟随清单运行应用程序时,TComport2010无法在comport上编写,该清单只有请求uiAccess = true
,而不是超级用户权限。
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="true"/>
</requestedPrivileges>
应用程序编译时显示建议,在程序文件目录上发出指示并运行,但是,在这种情况下,comport失败,无法写...如果我以管理员身份运行上下文菜单运行应用程序,那么一切正常,OSK pokes和com端口读/写。 该应用程序需要某种权限来访问COM设备?或者可能与TComport的注册表访问有关? 完整的清单在这里:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
type="win32"
name="pendrv.exe"
version="2.0.0.2552"
processorArchitecture="*" />
<description>Fixed Up App</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
publicKeyToken="6595b64144ccf1df"
language="*"
processorArchitecture="*"/>
</dependentAssembly>
</dependency>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!--This Id value indicates the application supports Windows 7 functionality-->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
<!--This Id value indicates the application supports Windows 8 functionality-->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
<!--This Id value indicates the application supports Windows 8.1 functionality-->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
</application>
</compatibility>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<applicationRequestMinimum>
<PermissionSet ID="FullTrust" Unrestricted="true" />
<defaultAssemblyRequest permissionSetReference="FullTrust" />
</applicationRequestMinimum>
<requestedPrivileges>
<!-- this access OSK but tcomport fails -->
<requestedExecutionLevel level="asInvoker" uiAccess="true"/>
<!-- in this case all works fine, but popup superuser request, that I want to avoid -->
<requestedExecutionLevel level="requireAdministrator" uiAccess="true"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
嗯,问题是为什么TcomPort不能仅使用uiAccess = true
使用清单,如下所示:
<requestedExecutionLevel level="asInvoker" uiAccess="true"/>
我正在运行app signated并在程序文件文件夹中。
失败的delhpi代码是对comport上的writestr的调用,当使用asinvoker和uiaccess = true运行应用程序时失败,当使用管理员权限运行时它运行正常,如果我将应用程序放在没有清单和任何权限的情况下文件夹所有的com工作也可以。相关的delphi代码如下:
com组件不会上升设备发出的任何消息,我确定设备每30秒发送一次msg,但onrxchar事件永远不会上升,写入函数会被调用但不确定msg是否真的发送给设备。一般来说,似乎windows阻止设备和delphi组件之间的通信运行与asinvoker和uiaccess = true。如果我使用管理员权限运行,相同的代码可以正常运行。
我把tcomport的代码放在pastebin上,因为这里有大小限制,代码链接是:
在将一些日志消息写入备忘录字段后,我在从外部USB设备接收一些数据时跟踪TComport事件的正常cicle。
这是正常读/接收数据操作的循环:(作为管理员运行)
TCOMLOG:-----CreateHandle OK-----
TCOMLOG:_WriteStrWrapper:<read_ch>=9
TCOMLOG:Thread.DispathComMsg
TCOMLOG:Thread.DoEvents
TCOMLOG:DoTxEmpty
TCOMLOG:Thread.execute
TCOMLOG:Thread.DispathComMsg
TCOMLOG:Thread.DoEvents
TCOMLOG:CallRxChar
TCOMLOG:DoRxChar call
TCOMLOG:ReadStr called
TCOMLOG:ReadAsync called
TCOMLOG:ReadAsync passed
TCOMLOG:ReadStr finished
TCOMLOG:Thread.execute
TCOMLOG:Thread.DispathComMsg
TCOMLOG:Thread.DoEvents
TCOMLOG:CallRxChar
TCOMLOG:DoRxChar call
TCOMLOG:ReadStr called
TCOMLOG:ReadAsync called
TCOMLOG:ReadAsync passed
TCOMLOG:ReadStr finished
TCOMLOG:Thread.execute
TCOMLOG:Thread.DispathComMsg
TCOMLOG:Thread.DoEvents
TCOMLOG:CallRxChar
TCOMLOG:DoRxChar call
TCOMLOG:ReadStr called
TCOMLOG:ReadAsync called
TCOMLOG:ReadAsync passed
TCOMLOG:ReadStr finished
TCOMLOG:Thread.execute
...
这是我在windows的同一个程序文件文件夹中运行只有uiAccess = true和asInvoker级别的应用程序时的循环:
TCOMLOG:-----CreateHandle OK-----
TCOMLOG:_WriteStrWrapper:<read_ch>=9
TCOMLOG:Thread.DispathComMsg
TCOMLOG:Thread.DoEvents
TCOMLOG:DoTxEmpty
TCOMLOG:Thread.execute
TCOMLOG:Thread.DispathComMsg
TCOMLOG:Thread.DoEvents
TCOMLOG:CallRxChar
TCOMLOG:DoRxChar call
TCOMLOG:ReadStr called
TCOMLOG:ReadAsync called
TCOMLOG:ReadAsync passed
TCOMLOG:ReadStr
日志在ReadStr上停止,似乎thread.execute冻结了什么,也许是因为不知道原因APP没有从windows接收usb事件..