This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Master Emulator exception when calling RequestData causes

Sometimes when the method RequestData is called after receiving a notify on the characteristic, the Master Emulator seems to hang for a set amount of time before throwing the exception listed below. I do not know what is causing this, or what I can do to help this not to occur other than waiting a set amount of time after a notify occurs to call the RequestData method on the characteristic. I do have two characteristic definitions for one characteristic so I can receive a notification on the characteristic and perform a long read on the same characteristic (In case this is the issue).

Is there a way to set this timeout to be a shorter time so the program will not hang on this method call, so the program can recover much quicker than it currently is.

IronPython.Runtime.Exceptions.PythonException: RequestData failed. Procedure returned False
   at DLRCachedCode._requestDataShared$217(Closure , PythonFunction $function, Object self, Object pipeNumber, Object readCharacteristic_Function, Object readDescriptor_Function)
   at IronPython.Runtime.FunctionCaller`4.Call4(CallSite site, CodeContext context, Object func, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
   at IronPython.Runtime.FunctionCaller`4.Call4(CallSite site, CodeContext context, Object func, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at IronPython.Runtime.Method.MethodBinding`3.SelfTarget(CallSite site, CodeContext context, Object target, T0 arg0, T1 arg1, T2 arg2)
   at DLRCachedCode.RequestLongData$221(Closure , PythonFunction $function, Object self, Object pipeNumber)
   at IronPython.Runtime.FunctionCaller`2.Call2(CallSite site, CodeContext context, Object func, T0 arg0, T1 arg1)
   at CallSite.Target(Closure , CallSite , Object , Int32 )
   at _Scripting_(Object[] , Int32 )
   at Nordicsemi.MasterEmulator.RequestLongData(Int32 pipeNumber)
   at nRFUart.nRFUartController.OnDataReceived(Object sender, PipeDataEventArgs arguments) 

These are the set parameters for the BLE connection.

        connectionParams.ConnectionIntervalMs = 7.5;
        connectionParams.SlaveLatency = 2;
        connectionParams.ScanIntervalMs = 250;
        connectionParams.ScanWindowMs = 200;
  • Hi,

    This issue might occur if you do a call back to the API directly from the OnDataReceived() event. If the event is not allowed to finish, it will block processing of new incomming packets. I would suggest that you try calling RequestLongData() from another thread. Please have a look at how this is done in the other MasterEmulator examples, for instance as nRF Uart below:

    void OnConnectionUpdateRequest(object sender, ConnectionUpdateRequestEventArgs arguments)
    {
    	Task.Factory.StartNew(() =>
    	{
    		masterEmulator.SendConnectionUpdateResponse(arguments.Identifier,
    			ConnectionUpdateResponse.Accepted);
    		BtConnectionParameters updateParams = new BtConnectionParameters();
    		updateParams.ConnectionIntervalMs = arguments.ConnectionIntervalMinMs;
    		updateParams.SupervisionTimeoutMs = arguments.ConnectionSupervisionTimeoutMs;
    		updateParams.SlaveLatency = arguments.SlaveLatency;
    		masterEmulator.UpdateConnectionParameters(updateParams);
    	});
    } 
    

    A new worker thread is started using Task.Factory.StartNew(), to avoid blocking.

    Best regards,

    Jørgen

  • Thank you. That solved the problem I was seeing. I was calling RequestLongData from the event OnDataReceived.

Related