Epicor 10 ERP: Building a More Powerful Epicor Barcode Handling Customization

Frequently, “barcode support” in the applications that we use means filling in screen fields one by one and, maybe if you are lucky, some auto-tabbing to get from field to field. But what do you do when you want an Epicor barcode that, when detected, performs actions that don’t directly correspond to filling in screen fields? For example, if I were in MES and wanted a single scan that would detect if I am clocked in and (1) if not, clock me put me on my default shift, and leave the terminal ready for the next employee or (2) if I am already clocked in, bring up the selected employee screen. This, my friends, is what this article is all about.

So first things first, most barcode scanners nowadays are what they called “keyboard wedge” scanners - meaning that when you scan, it replicates a user punching in keystrokes to the screen. Where this is generally a million times better than the past incarnations of COM port scanners, it does introduce a new challenge of knowing what the user is just typing in Epicor versus what the barcode scanner is doing. To this end, dealing with these keyboard wedge scanners in an application means coming up with some special prefixes and suffixes that differentiate the input. For this article, we are going to assume that barcodes start and end with a percent sign (%), but it could genuinely be any character with simple revisions. Anything inside of those percent signs is then up to our programs to define the supported logic. We have typically adopted a logic where the first character following the percent sign is a control character telling us what kind of barcode we are dealing with (i.e. ‘1’ means employee clock in, ‘2’ means employee clock out, ‘3’ means start indirect, etc.) and the data elements following that are separated by dollar signs (i.e., job, assembly, operation).

When you have your barcode schema sorted out, now it is up to implementing this within your customization. We do this by activating a form-level keystroke listener so that the user doesn’t need to be any any specific field for the scans to work. Here is how it works:

  1. Define 2 variables that we will need to keep track of the barcode and whether we are currently reading a barcode at the top of the customization:

      private static bool listener = false;
      private static string barCodeInput = "";
  2. Define a text box somewhere on the customization, making it as inconspicuous as possible. It won’t be there to read any barcodes, rather it is present simply to move the focus into when a barcode is being received to avoid potentially be sending text into a standard Epicor field (which might give you grief). Note the GUID.

  3. In InitializeCustomCode() add a KeyPress even listener for the form you are on. In my case here, MESMenu:

    this.MESMenu.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MESMenu_KeyPress);
  4. Then make sure you tear it down in DestroyCustomCode():

    this.MESMenu.KeyPress -= new System.Windows.Forms.KeyPressEventHandler(this.MESMenu_KeyPress);
  5. Now define that keypress function we are wiring up here (in our case, MESMenu_KeyPress:

  private void MESMenu_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs args)
  {
    if (args.KeyChar.ToString().Equals("%") && string.IsNullOrEmpty(barCodeInput) && listener == false)
    {
      // redirect focus so key entries don't activate buttons
      EpiTextBox epiTextBox1 = (EpiTextBox)csm.GetNativeControlReference("614426cf-324b-46ec-a759-1a8050b5af6f");
      epiTextBox1.Focus(); 
      listener = true;    
    } else if (!args.KeyChar.ToString().Equals("%") && listener == true) {
      barCodeInput = barCodeInput + args.KeyChar.ToString();    
    } else if (args.KeyChar.ToString().Equals("%") && listener == true) {
      listener = false;      
      this.PerformBarCodeAction(barCodeInput);
      barCodeInput = "";    
    }  
  } 

So as you can see here, we start the first time we see the % character by sending focus to our dummy text field and turning on our “listener” variable. From there, the next keystroke and all keystrokes until another % is received are built onto the barCodeInput variable. When that last % is detected, we turn the listener off and pass the full barcode strong we have received into the handler function (in our case PerformBarCodeAction) and clear out the barCodeInput variable.

I hope this helps somebody out there! As always, leave us a comment if you get stuck, or if this helped you out. Also, keep us in mind if you want to have us help out with any of your Epicor ERP barcoding projects. Happy coding!