FoxPro and .NET Interop
SubscribeToEvents with Non-standard Prefix
Gravatar is a globally recognized avatar based on your email address. SubscribeToEvents with Non-standard Prefix
  Mark Kanim
  All
  Nov 13, 2021 @ 09:13am

Hello Rick

My goal is to connect with a bluetooth RFID reader to gather reader data.

The below code runs without error, but 'handle' events don't fire.

Is there a limitation to SubscribetoEvents lcPrefix? (default 'On', but I am passing 'handle')

I have a VB compiled demo.exe program that uses the same .DLLs and runs well.

Thanks Mark


wwDotnetBridge Version   : 7.4.0.0
.NET Version (official)  : 4.0.30319.42000
.NET Version (simplified): 4.7.2
.NET Version (Release)   : 528372

** debugs removed for readability

DO wwdotnetbridge
InitializeDotnetVersion("V4") 
loBridge = GetwwDotnetBridge()

loBridge.loadassembly("Nconnect.dll")

cBTMac=[00:19:01:71:53:5C]

** Create oReader
loxInstance = lobridge.InvokeStaticMethod("Nconnect.RfidFactory","getInstance")
nIry		= loBridge.GetEnumValue("Nconnect.ReaderMake.Irys_bluetooth")
loxReader	= loxInstance.GetRfidreader(nIry,cBTMac)
loxWriter	= loxInstance.GetRfidwriter(nIry,cBTMac)

** Create oListener
loxListener	= loBridge.CreateInstance("Nconnect.RfidEventListenerImpl")

** Register Listener with Reader Callback
loxReader.RegisterListener(loxListener)

** setup callback Subscription
loxNConHandler = CREATEOBJECT("NConEventHandler")
loxSubscription = loBridge.SubscribeToEvents(loxListener, loxNConHandler, "handle" )

DOEVENTS

loxReader.Connect() && reader beeps to indicate connection
loxReader.Link()    && reader lights begin flashing red when BT reader hovers over tags

WAIT WINDOW
loxSubscription.Unsubscribe()
loxReader.DisRead()
loxReader.DisConnect()

RETURN

DEFINE CLASS NConEventHandler AS CUSTOM

	FUNCTION handleData(tagData,antennaID,scanDistance,hostName)
		SET STEP ON
	ENDFUNC

	FUNCTION handleError( cerror)
		SET STEP ON
	ENDFUNC

	FUNCTION handleReaderEvent( cevent )
		SET STEP ON
	ENDFUNC

	FUNCTION handleWriteStatus( cwrite )
		SET STEP ON
	ENDFUNC

ENDDEFINE

``
namespace Nconnect
{
    using System;
    public class RfidEventListenerImpl : AbstractRfidEventListener
    {
        public RfidEventListenerImpl()
        {
            base..ctor();
            return;
        }
        public override void handleData(string tagData, int antennaID, int scanDistance, string hostName)
        {
            Console.WriteLine("Read Tag:" + tagData);
            return;
        }
        public override void handleError(string error)
        {
            throw new NotImplementedException();
        }
        public override unsafe void handleReaderEvent(ReaderEvent readerEvent)
        {
            Console.WriteLine("Reader Event:" + &readerEvent.ToString());
            return;
        }
        public override unsafe void handleWriteStatus(bool writeStatus)
        {
            Console.WriteLine("Write status:" + &writeStatus.ToString());
            return;
        }
    }
}
Gravatar is a globally recognized avatar based on your email address. re: SubscribeToEvents with Non-standard Prefix
  Rick Strahl
  Mark Kanim
  Nov 14, 2021 @ 01:16am

To be honest I don't remember exactly how this works, beyond what's in the documentation. It's been a while and I have to look at the code to remember. The idea though is that you have to specify the name of the event handlers - generally exported event handlers are named OnXXX so if you're are handleXXX then that should be right.

I'll take a look tomorrow.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: SubscribeToEvents with Non-standard Prefix
  Mark Kanim
  Rick Strahl
  Nov 14, 2021 @ 02:49pm

Some new information; I decided to load the Demo.exe and CreateInstance on the RfidEventListener found there, and to my surprise, it sort of worked:


loBridge.loadassembly("IrysLink.exe")
loxListener	= loBridge.CreateInstance("Irys_Link.RfidEventListener")
loxNConHandler = CREATEOBJECT("NConEventHandler")
loxSubscription = loBridge.SubscribeToEvents(loxListener, loxNConHandler, "handle" )
DO EVENTS


Now at the WAIT WINDOW, after the DOEVENTS, I wait as long as I want, and then press the "begin scanning" button on the RFID reader, and immediately triggers an error, indicating to me that the Callback events are firing.

So, I think don't bother checking the lcPrefix at all. The SubscribeToEvents with lcPrefix 'handle' seems to work as designed.

By the way, I have been using your toolkit for many years with great success.

The message board and online help have saved hours of frustration.

Thanks

Mark

Gravatar is a globally recognized avatar based on your email address. re: SubscribeToEvents with Non-standard Prefix
  Rick Strahl
  Mark Kanim
  Nov 14, 2021 @ 03:53pm

The important thing to remember is that these object need to stay in scope. They need to be PUBLIC or attached to some object in your application that sticks around. Otherwise the object goes away and the events can't call back - or try to and fail.

+++ Rick ---

© 1996-2021