How to: Listen to the MSR / Scanner devices
Further reading
Microsoft Dynamics AX 2012 for Developers [AX 2012] SDK Download
Tutorial
AX Dynamics Retail allows partners to add custom froms that can listen to OPOS MSR or scanner dervice those are claimed by POS. In Form OnLoad event subscribe to the MSR/Scanner events:
using [Link]; protected override void OnLoad(EventArgs e) { if (![Link]) { IPeripherals peripherals = [Link]; [Link] += new ScannerMessageEventHandler(Scanner_Event); [Link](); [Link] += new MSRMessageEventHandler(MSR_Event); [Link](); } [Link](e); }
Add event handler methods:
private void Scanner_Event(IScanInfo scanInfo) { if (scanInfo) != null && ) { } } private void MSR_MSRMessageEvent(ICardInfo cardInfo) { if (cardInfo != null && ) { ... } }
In form OnClosed event unsubscribe to the events:
protected override void OnFormClosed(FormClosedEventArgs e) { if (![Link]) { IPeripherals peripherals = [Link]; [Link](); [Link] -= new MSRMessageEventHandler(MSR_Event); [Link](); [Link] -= new ScannerMessageEventHandler(Scanner_Event); } [Link](e); } }
Notes: 1. Form has to handle keyboard wedge MSR and Scanner events by them self. 2. Code sample assumed that Application instance is accesbile to the form.