MES Barcode Scanning code

So i know this is a VERY old post ha ha but looking to implement this in our plant in Mexico…I am stuck on the "

List<char> _barcode = new List<char>(10);

Is there an assembly reference I need to add? Once the barcode is scanned what is telling MES that the information should be stored as _barcode?

I think what you’re looking for is a using statement. Throw this up at the top with the rest of the using statements. (that’s just an educated guess since you aren’t actually showing us what the error is that your getting of why it’s not working.)

using System.Collections.Generic;
1 Like

Sorry, I didn’t give much information on that post! Appreciate you helping on such an old thread. I want to implement the barcode scan at the MES menu so that they don’t even have to click on start production activity. I added the code to get the hot key working but I think I am missing how the scanned info gets captured. The only error I get while compiling is about the list adaptor like I mentioned above but even if I get past that I don’t think I have anything to capture the barcode scan? What line in the code tells MES that the information scanned is the _barcode value?

I moved this to a new topic.

Can you post the code that you are using so I can understand what you have? There is a lot of code being slung around in that last post, and I’d rather just see what you’re trying to do instead of guessing what you’ve put together.

OK, I parsed through the thread a little more. There’s a key press subscription that’s missing. This thread is about what you do after you already have the barcode. There’s posts about how you set up the key watcher. Let me do a quick search.

This one sort of talks about it.

1 Like

Actually it’s this code here. But it’s missing the subscriber to actually fire that code. I can’t remember if you can make that with the wizard or not.

// Launch Start Activity from hot key
DateTime _lastKeystroke = new DateTime(0);
List<char> _barcode = new List<char>(10);	
LaunchFormOptions lfo = new LaunchFormOptions();

public void MESMenu_KeyPress(object sender, KeyPressEventArgs e)
{
	// Check timing (keystrokes within 100 ms)
	TimeSpan elapsed = (DateTime.Now - _lastKeystroke);
	if (elapsed.TotalMilliseconds > 100)
	_barcode.Clear();

	// Record keystroke and timestamp
	_barcode.Add(e.KeyChar);
	_lastKeystroke = DateTime.Now;

	// Process barcode
	if (e.KeyChar == (char)90 && _barcode.Count > 0)
	{
		string msg = new String(_barcode.ToArray());
		lfo.IsModal = true;
		lfo.ContextValue = msg;
		_barcode.Clear();
		ProcessCaller.LaunchForm(this.oTrans, "SSSM9999", lfo);
		this.oTrans.RefreshLaborData();
	}
}
1 Like

Awesome, thanks Brandon, apologies for the extra work starting the new thread.
So I have the following code right at the MESMenu. The shortcut key is set to J and that works (opening start production activity). The compile I error I am getting is:
Error: CS0246 - line 379 (1054) - The type or namespace name ‘List’ could not be found (are you missing a using directive or an assembly reference?)
The Code I am using is below…I am stuck on what is telling MES that the barcode I scan should be used for the _barcode value…I think I have missed a step somewhere and based on the error I am missing an assembly reference?

// Launch Start Activity from hot key
DateTime _lastKeystroke = new DateTime(0);
List<char> _barcode = new List<char>(10);	
LaunchFormOptions lfo = new LaunchFormOptions();

public void MESMenu_KeyPress(object sender, KeyPressEventArgs e)
{
	// Check timing (keystrokes within 100 ms)
	TimeSpan elapsed = (DateTime.Now - _lastKeystroke);
	if (elapsed.TotalMilliseconds > 100)
	_barcode.Clear();

	// Record keystroke and timestamp
	_barcode.Add(e.KeyChar);
	_lastKeystroke = DateTime.Now;

	// Process barcode
	if (e.KeyChar == (char)106 && _barcode.Count > 0)
	{
		string msg = new String(_barcode.ToArray());
		lfo.IsModal = true;
		lfo.ContextValue = msg;
		_barcode.Clear();
		ProcessCaller.LaunchForm(this.oTrans, "SSSM9999", lfo);
		this.oTrans.RefreshLaborData();
	}

Did you add the using statement up for for System.Collections.Generic?

1 Like

I just added it…and now it compiles…excellent. Ok I will add the rest of the code to the “Start Production Activity” form and keep my fingers crossed.

Thanks Brandon, appreciate your time on this!

1 Like

Ok so everything seems to work/compile after added the code into “Start Production Activity” but when I scan the barcode from the MES screen, I get “Exception has been thrown by the target of an invocation”. I doubled checked the barcode is being read correctly (scanned into word) and that isn’t the issue. It is launching the form but I don’t think the values are being captured in the scan correctly…

Application Error

Exception caught in: mscorlib

Error Detail 
============
Message: Exception has been thrown by the target of an invocation.
Inner Exception Message: Index was outside the bounds of the array.
Program: CommonLanguageRuntimeLibrary
Method: InvokeMethod

Client Stack Trace 
==================
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Ice.Lib.Customization.CustomScriptMethodInvoker.InvokeScriptMethod(MethodInfo scriptMethod, Object[] parameters)
   at Ice.Lib.Customization.CustomScriptMethodInvoker.InvokeCustomFormLoadIfExists(String methodName, Object sender, EventArgs e)
   at Ice.Lib.Customization.CustomScriptManager.<>c__DisplayClass104_0.<OnCustomCodeFormLoad>b__0()
   at Ice.Lib.Customization.CustomScriptManager.TryActionShowExceptionBoxOrLogVerificationErrorIfException(Action action, String exceptionBoxTitle)

Inner Exception 
===============
Index was outside the bounds of the array.



   at Script.StartProdForm_Load(Object sender, EventArgs args)

Run it in debug mode (you’ll need visual studio) and see where it’s failing.

Ok thanks Brandon. I have Visual Studio, but have never debugged any customs using it ha ha Looks like I will learn something new today! Thanks

In developer mode, there is a checkbox for “Debug in visual studio” in the bottom corner. Check that box before you open the form and it should open visual studio and start debug mode.

1 Like

Not having a good day here…I don’t seem to see that option? I am in the customization window but I don’t see that checkbox?

You don’t see this?

Ok so I was looking in the wrong spot…rookie move…however, it seems that while the checkbox is there its disabled…I have Visual Studio installed but perhaps a setting I need to change? Sorry for the hassle on this

I was worried about that. There are some registry settings that can get messed up and I always need help to fix it.

So let’s just skip that.
I think the error is happening on the menu that you are opening. What code to you have there to receive the Lfo options?

Edit: does it work if you change the default code to C#?

1 Like

I used the same code that was in the original thread:

// Pull barcode in from MESMenu
private void StartProdForm_Load(object sender, EventArgs e)
{
	if(StartProdForm.LaunchFormOptions != null)
	{
		object barcodeObj = StartProdForm.LaunchFormOptions.ContextValue;
		// Convert barcode (object to string)
		string barcode = barcodeObj.ToString();
		// Split barcode into parts
		var items = barcode.Split('-');
		string job = items[1];
		string asm = items[2];
		string opr = items[3];
		// Transfer data to fields
		var view = ((EpiDataView)(this.oTrans.EpiDataViews["Start"]));
		if(view.Row>=0)
		{
			// Fill Job Number
			view.dataView[view.Row].BeginEdit();
			view.dataView[view.Row]["JobNum"]=job;
			view.dataView[view.Row].EndEdit();
			// Fill Assembly Sequence
			view.dataView[view.Row].BeginEdit();
			view.dataView[view.Row]["AssemblySeq"]=asm;
			view.dataView[view.Row].EndEdit();
			// Fill Operation Sequence
			view.dataView[view.Row].BeginEdit();
			view.dataView[view.Row]["OprSeq"]=opr;
			view.dataView[view.Row].EndEdit();
			// Close form
			if (oTrans.Update())
			{
				StartProdForm.Close();
			}
		}
	}
}

What’s the text of your barcode look like? It’s skipping the first part ( [0] ) and getting the second third and fourth parts of the split string. If you don’t have something in all 4 places, you’ll get that null reference error.