示例#1
0
        /// <summary>
        /// Register a callback listening function to be called when a listening event (e.g. data is received with Tellstick Duo) occurs
        /// </summary>
        /// <param name="listeningFunc">Callback function to be called</param>
        /// <param name="obj">Context object that will be echoed back when function is called. Only the object when the first function is registered will be used. Set to null if not used.</param>
        /// <returns>Callback event id</returns>
        public unsafe int tdRegisterRawDeviceEvent(RawListeningCallbackFunction listeningFunc, Object obj)
        {
            int returnValue = 0;

            if (rawListenerList.Count == 0)
            {
                //first added, register with dll too
                //only the context object of the first event will be registered
                UnmanagedImport.RawListeningDelegate listeningFunctionDelegate = new UnmanagedImport.RawListeningDelegate(rawListeningFunction);

                registeredRawListenerFunctionId = UnmanagedImport.tdRegisterRawDeviceEvent(listeningFunctionDelegate, (void *)null);
                GC.Collect();
                callbackFunctionReferenceList.Add(registeredRawListenerFunctionId, listeningFunctionDelegate);
            }
            ++lastEventID;
            returnValue = lastEventID;
            RawEventFunctionContext rawEventFuncContext = new RawEventFunctionContext();

            rawEventFuncContext.rawCallbackFunc = listeningFunc;
            rawEventFuncContext.context         = obj;
            rawEventFuncContext.callbackId      = returnValue;
            rawListenerList.Add(returnValue, rawEventFuncContext);
            return(returnValue);
        }