1

I am creating an ActiveX control for a hardware (card swiper) device. I have understanding of ActiveX development and working, but I am little stuck with my specific scenario. Device SKD (dll files) have method to activate swiper/chip reader in order to be in listening state. Assume the following:

SDK sdk = new SDK();
sdk.RegisterCallback(GlobalCallback);
sdk.ActivateSwiper();

public void GlobalCallback(op, .., ..)
{
   switch(op) {
     case Swiped:
       readCardData();
       break;
     case TransactionData:
       readData();
       break;
     //. . . . 
}

Above code is just for example. SDK has a global callback method for any event triggered through device (eg, card swiped, ICC seated, etc). If the SDK is being used in WPF/WinForm app, it is super easy get it working. But in my case, I must need to handle the raised event in javascript on my web page.

So, I have exposed a method in ActiveX to turn on the device, which works perfect:

[Guid("4794D615-BE51-4a1e-B1BA-453F6E9337C4")]
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IComEvents))]
public class MyComObject : IComObject
{
   [ComVisible(true)]
   public string ActivateDevice()
   {
      SDK sdk = new SDK();
      sdk.RegisterCallback(GlobalCallback);
      string resultCode = sdk.ActivateSwiper();
      return resultCode;
   }
   //. .  <other code> . . .
}

and use it in webpage as:

<object id="myComComponent" name="myComComponent" classid="clsid:4794D615-BE51-4a1e-B1BA-453F6E9337C4"></object>
<script language="javascript" type="text/javascript">
      var returnCode = myComComponent.ActivateDevice(); //or by creating ActiveXObject
</script

I have also got the idea about how to handle events using ActiveX on webpage. I learnt it from HERE. But the event is handled by calling the exposed method to raise event. And in my case, when card is swiped, the call will go to GlobalCallback() method.

Questioins:

  • Is there any workaround, I can implement handler in my scenario, to make it usable on javascript?
  • I am thinking of something like PropertyChanged event, bound to a string property, which holds the derived card data. and the handlers returns this property value. Is there any workaround possible like this? I need little help with this.

I am thinking this as:

 public static string CARD_DATA;
 public void GlobalCallback(op, .., ..)
 {
    switch(op) {
      case Swiped:
        CARD_DATA = readCardData();
        //and CARD_DATA is bound to property-changed event, and its handler returns its value.
        //other code

Is this even possible? If so, What to be exposed? and How to use it? as this property will be changed internally, when card is swiped, and case Swiped: is executed. Is there any workaround?

Other Info:

  • Web App is MVC 4 famework based
  • Device is The Augusta (IDTech). (they don't have actieX/plugin for web)
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Zeeshan
  • 2,884
  • 3
  • 28
  • 47

0 Answers0