Honeywell Dolphin 9500 (Pocket PC 2003) C# 事件处理冲突?
环境
- Windows XP x32 Visual Studio 2005 标准版
- Honeywell Dolphin 9500 运行 Windows Mobile 2003 (Pocket PC 2003)
- 配有内置条形码扫描仪和黑白摄像头
- 使用位于 此处。
- .NET Compact Framework 1.0 SP3 和 .NET Framework 1.1
- 使用 VC#
目标
我正在尝试创建一个应用程序,允许个人扫描条形码,然后捕获图像。这些事情不应该同时发生。用户应该能够仔细检查条形码扫描,然后转到处理图像捕获的应用程序部分。
问题
行号引用了下面代码部分的friendpaste 链接中的代码。
有两个事件处理程序:一个用于来自条形码扫描仪控件的解码事件,另一个用于通过 KeyDown 事件调用图像捕获控件。解码控件有自己的事件/处理程序 DecodeEventHandler 和一个带有枚举的触发键集(lns 201 和 202)。然而,图像控件则不然。其文档指出 Form 应具有 KeyDown 事件处理程序(ln 120)和触发键枚举(ln 178)。运行应用程序后(没有 SelectedIndexChanged [ln 76] 事件处理程序),条形码扫描仪工作得很好,但切换到选项卡(或表单,因为我也尝试过单独的表单),使用图像捕获控件和按下设备上的触发键(在本例中为“扫描”)会使手持设备表现得像仍在扫描条形码(红灯亮起,显示绿色瞄准灯,遇到条形码时发出蜂鸣声),而不是使用时通常显示的行为图像控制(无灯光,或像闪光灯一样的白光)。
我尝试过的事情
- 重要:如果我从应用程序中删除解码控件,则图像控件可以工作。如果我构建一个仅包含图像控件的单独应用程序,它就可以工作。
- 我在第 210 行放置了一个断点,发现 KeyDown 事件永远不会被命中。此时,我尝试以某种方式隔离事件处理程序或控件,因此我为选项卡控件引入了 SelectedIndexChanged 事件处理程序,并在切换到具有适当控件的选项卡后,我尝试删除事件处理程序。我能够删除 DecodeEvent 处理程序,但仍然无法访问我编写的 KeyDown 事件处理程序委托。
- 霍尼韦尔 SDK 中的解码和图像控件都有“断开连接”事件(引用文档)“与扫描引擎断开连接”。因此,我尝试根据要切换到的选项卡断开并重新连接控件,但也没有成功。
- 我还在某处读到,如果表单失去焦点,表单事件有时可能会被中断。因此,我实现了 Form.LostControl 事件/处理程序并放入 this.Focus() 以将焦点返回到表单,但无济于事。
- 我遇到过很多人建议 KeyPreview = true 并在表单级别处理/委托事件。 .NET Compact Framework 版本 1 似乎没有实现此功能,因为我的 Form 对象没有 KeyPreview 成员。
- 在 TriggerKey 枚举中(第 202 行的示例),有一个设备上 Enter 键的枚举。我尝试将其连接到图像控件,并扫描到解码器控件,但仍然无法命中 KeyDown 事件。
代码
http://friendpaste.com/355cQOCghvPkE5YR29lthO
我将代码发布为friendpaste链接,因为它有点长(~230行)。让我知道我是否应该将其包含在这里。
需要更多信息吗?
询问吧,我会尽力而为!
我本来会标记这款 Honeywell Dolphin 9500,但我是新用户。
Environment
- Windows XP x32 Visual Studio 2005 Standard Edition
- Honeywell Dolphin 9500 running Windows Mobile 2003 (Pocket PC 2003)
- With built in Barcode scanner and B&W camera
- Using their SDK located here.
- .NET Compact Framework 1.0 SP3 and .NET Framework 1.1
- Using VC#
Goal
I am attempting to create an application that allows an individual to scan a barcode and then capture an image. These things should not happen simultaneously. The user should be able to double check the barcode scan, then move onto the portion of the application that handles image capturing.
Problem
Line numbers are referencing my code in the friendpaste link in the Code section below.
I have two event handlers in place: one for the decode event from the barcode scanner control, and one to invoke the image capture control via a KeyDown event. The decode control has its own event/handler DecodeEventHandler and a trigger key set with an enum (lns 201 and 202). The image control, however, does not. Its documentation states that the Form should have a KeyDown event handler (ln 120) and the trigger key enum (ln 178). Upon running the application (without the SelectedIndexChanged [ln 76] event handler in place), the barcode scanner works great, but switching over to the tab (or Form, as I have tried separate forms as well), with the image capture control and hitting the Trigger Key on the device (SCAN in this case) causes the handheld to act like it's still scanning a barcode (red lights come on, green aim light is show, beeps when encounters a barcode) instead of the behavior normally displayed when using the image control (no lights, or white lights like a flash).
Things I have Tried
- IMPORTANT: If I remove the decode control from the application, the image control works. If I build a separate application with only the image control, it works.
- I put a break point at line 210 and found out the KeyDown event is never getting hit. At this point I tried to somehow segregate the event handlers or controls so I introduced the SelectedIndexChanged event handler for my tab control and upon switching to the tab with the appropriate control, I tried removing event handlers. I was able to remove the DecodeEvent handler but was still unable to hit the KeyDown event handler delegate I wrote.
- Both the decode and image controls from Honeywell's SDK have "Disconnect" events which (to quote the documentation) "Disconnect from the scan engine". So I tried disconnecting and reconnecting controls based on which tab I was switching to but was unsuccessful in this as well.
- I also read somewhere that Form events can sometimes be disrupted if the Form loses focus. So I implemented the Form.LostControl event/handler and put in this.Focus() to return focus to the form but to no avail.
- I have run across multiple people suggesting KeyPreview = true and handling/delegating the events at the form level. It appears the .NET Compact Framework version 1 does not implement this as my Form objects have no KeyPreview member.
- Within the TriggerKey enum (example at line 202) there is an enum for the Enter key on the device. I tried wiring that up to the image control, and scan up to the decoder control but was still unable to hit the KeyDown event.
Code
http://friendpaste.com/355cQOCghvPkE5YR29lthO
I posted the code as a friendpaste link because it's somewhat long (~230 lines). Let me know if I should just include it here.
Need additional information?
Ask away and I'll do my best!
I would have tagged this Honeywell Dolphin 9500 but I am a new user.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您无法访问
KeyDown
处理程序的原因是,用于TabControl1_IndexChanged
的处理程序是一个System.EventHandler
,它是KeyDown
的通用形式。尝试执行类似的操作,看看它是否捕获
KeyDown
The reason that I think you can't get to the
KeyDown
handler is that the one that is for theTabControl1_IndexChanged
is aSystem.EventHandler
which is a generic form of theKeyDown
.Try doing something like this and see if it is catching the
KeyDown
这有点麻烦,但我认为它会起作用。设置
AllKeys( true );
。这应该确保您的应用程序捕获任何键盘按下操作。AllKeys P/Invoke 签名: http://blogs.msdn.com/b/mikefrancis/archive/2009/03/28/porting-gapi-keys-to-wm-6-1-and-6 -5.aspx
常规 AllKeys 信息:http://windowsteamblog.com/windows_phone/b/windowsphone/archive/2009/07/14/just -say-no-to-gapi-what-you-need-to-know-about-allkeys-and-input-management.aspx
听起来解码控件正在吞噬您需要的消息。您可以尝试联系 HHP 开发人员支持。如果他们有在线开发者支持论坛也可能有效。作为一个测试,如果您开始注释第 192-202 行,会发生什么?其中一行是否会导致您的 keydown 事件停止工作?
-PaulH
编辑
imageControl 和decodeControl 都接受
TriggerKey
参数。听起来他们希望自己处理按键事件。试试这个:一次只实例化其中一个,具体取决于您所在的选项卡。一起删除
Form1_KeyDown
处理代码(包括 AllKeys)。看看是否有效。或者,您仍然可以终止您的
Form1_KeyDown
处理程序,但保持两个控件原样,并在tabControl1_SelectedIndexChanged
处理程序中执行此操作:现在只有其中一个会监视扫描按钮取决于您所在的选项卡。
This is a bit of a hack, but I think it will work. Set
AllKeys( true );
. That should ensure that your application captures any keypad press.AllKeys P/Invoke signature: http://blogs.msdn.com/b/mikefrancis/archive/2009/03/28/porting-gapi-keys-to-wm-6-1-and-6-5.aspx
General AllKeys information: http://windowsteamblog.com/windows_phone/b/windowsphone/archive/2009/07/14/just-say-no-to-gapi-what-you-need-to-know-about-allkeys-and-input-management.aspx
It sounds like the decode control is swallowing the message you need. You could try contacting HHP developer support. If they have an online developer support forum that may work too. As a test, what happens if you start commenting out lines 192-202? Does one of those lines cause your keydown event to stop working?
-PaulH
Edit
The imageControl and decodeControl both accept a
TriggerKey
parameter. That sounds like they expect to be doing the keypress event handling themselves.Try this: only have one of those instantiated at a time depending on what tab you're on. Get rid of the
Form1_KeyDown
handling code all together (including the AllKeys). See if that works.Alternately, you can still kill your
Form1_KeyDown
handler, but keep both controls just like they are and do this in yourtabControl1_SelectedIndexChanged
handler instead:Now only one of them will be watching the scan button depending on what tab you're on.
我发现如果我将 TriggerKey 更改为 TK_ENTER(triggerkey 枚举中的另一个值),我可以与图像控件交互,没有任何问题。现在我只需要找到一种方法来捕获 Enter 按键,以防止它做任何奇怪的事情。
感谢您的帮助!
I found that if I change the TriggerKey to TK_ENTER (another value in the triggerkey enum), I can interact with the image control without any issues. Now I just need to find a way to capture that Enter key press to keep it from doing anything weird.
Thanks for all the help!