Honeywell Dolphin 9500 (Pocket PC 2003) C# Event Handling Conflicts?
Asked Answered
C

3

11

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.

Creator answered 16/3, 2011 at 14:18 Comment(0)
C
0

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!

Creator answered 18/3, 2011 at 20:5 Comment(0)
S
1

The reason that I think you can't get to the KeyDown handler is that the one that is for the TabControl1_IndexChanged is a System.EventHandler which is a generic form of the KeyDown.

Try doing something like this and see if it is catching the KeyDown

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
   if (sender is Form1 && e is KeyEventArgs)
   {
       Form1_KeyDown(sender,  (KeyEventArgs) e);
   }
   else
   {
       //Do other stuff
   }

}
Sherard answered 16/3, 2011 at 14:49 Comment(1)
First of all thanks for the reply. However, with or without the SelectedIndexChanged event handler, I cannot hit the KeyDown event handler. That aside, I tried what you said anyway but to no avail. Thanks again though, I did not know that and any learning is good learning! EDIT Let me be more clear: I tried what you said but on the key press, SelectedIndexChanged was not called.Creator
I
1

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 your tabControl1_SelectedIndexChanged handler instead:

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (this.tabControl1.SelectedIndex == 0)
    {
        this.decodeControl1.TriggerKey = HHP.DataCollection.Common.TriggerKeyEnum.TK_ONSCAN;
        this.imageControl1.TriggerKey = null;
    }
    else if (this.tabControl1.SelectedIndex == 1)
    {
        this.decodeControl1.TriggerKey = null;
        this.imageControl1.TriggerKey = TriggerKeyEnum.TK_ONSCAN;
    }
}

Now only one of them will be watching the scan button depending on what tab you're on.

Iridic answered 16/3, 2011 at 15:35 Comment(4)
I apologize in advance for my lack of experience, but how do I use the P/Invoke signature or how do I allow my application access to the AllKeys function?Creator
I don't know why you would apologize for that. This is a developer help forum, after all. MSDN has a tutorial on calling Win32 APIs from managed code (P/Invoke) here: msdn.microsoft.com/en-us/magazine/cc164123.aspxIridic
Well that certainly got my application capturing the KeyDown event! However, my issue is slanted in the other direction now. The KeyDown event takes precedence over the DecodeEvent. This in and of itself is not an issue except that the KeyDown event requires the EventArgs to be of type KeyEventArgs to call it and the DecodeEvent needs the second parameter to be of type DecodeEventArgs which I can't cast from KeyEventArgs. This means I can't delegate out the task of Decoding as I cannot properly call my DecodeEvent handler function (line 148). Ideas?Creator
While both controls accept a TriggerKey, only the decode control actually does its own event/key handling. The image control, based on the documentation and sample programs, requires the consumer to wire up a KeyDown event handler. Also, if I set TriggerKey to anything other than TK_ONSCAN or TK_ENTER, the control (decode control) fails to unregister the hotkey and the application crashes saying "Hotkey not unregistered". There is even a TK_NONE in the TriggerKey enumerator and that fails with the same error. The control is not coded properly to accept this kind of behavior apparently.Creator
C
0

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!

Creator answered 18/3, 2011 at 20:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.