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

MasterEmulator.DiscoverPipes Could not discover service of uuid

After connect I try to find a service using MasterEmulator method DiscoverPipes(). I'm using event masterEmulator.LogMessage += OnLogMessage; to print logs. First it write:

232;16:25:09.7820 [ReadPacketQueueThread] Discover pipes
233;16:25:09.8060 [ReadPacketQueueThread] GATT: Discovering all Primary Services of type 0x6E400001B5A3F393E0A9E50E24DCCA9E

But then after 30 seconds it writes:

240;16:25:39.9687 [ReadPacketQueueThread] GATT: Received None - None
241;16:25:39.9847 [ReadPacketQueueThread] Could not discover service of uuid 0x6E400001B5A3F393E0A9E50E24DCCA9E
242;16:25:40.0197 [ReadPacketQueueThread] Discovery of pipe 1 failed

Then of course when I tried to send data using:

masterEmulator.SendData(UartRxPipe, encodedBytes);

I get error:

An unhandled exception of type 'System.Exception' occurred in emulatorlibs.dll
Additional information: Pipe 1 has not been discovered

Why the service is not found??

Parents
  • I did find out the reason. I need to call masterEmulator.DiscoverPipes() in separate thread - like this:

    Task.Factory.StartNew(() =>
        {
            try
            {
                bool success = masterEmulator.DiscoverPipes();
                var openedPipesEnumeration = masterEmulator.OpenAllRemotePipes();
            }
            catch (Exception ex)
            {
                AddToLog(string.Format("Exception in OnConnected: {0}", ex.Message));
            }
        } );
    

    But I still have a questions:

    1. Why this important information (that the method has to be called from new thread) is not in "Master Emulator API documentation". At least not in description of DiscoverPipes method.

    2. I'm new to C# and I do not understand how it works. I understand that calling DiscoverPipes block all in my main thread - but as I do not use GUI I do not care. But how can be blocked masterEmulator instance when it has whole my main thread to work on? In nordic example is written before thread starting: Using a background task in order not to block the event caller. but I do not understand what event caller is blocked. My main thread does not handle any event during DiscoverPipes() running.

Reply
  • I did find out the reason. I need to call masterEmulator.DiscoverPipes() in separate thread - like this:

    Task.Factory.StartNew(() =>
        {
            try
            {
                bool success = masterEmulator.DiscoverPipes();
                var openedPipesEnumeration = masterEmulator.OpenAllRemotePipes();
            }
            catch (Exception ex)
            {
                AddToLog(string.Format("Exception in OnConnected: {0}", ex.Message));
            }
        } );
    

    But I still have a questions:

    1. Why this important information (that the method has to be called from new thread) is not in "Master Emulator API documentation". At least not in description of DiscoverPipes method.

    2. I'm new to C# and I do not understand how it works. I understand that calling DiscoverPipes block all in my main thread - but as I do not use GUI I do not care. But how can be blocked masterEmulator instance when it has whole my main thread to work on? In nordic example is written before thread starting: Using a background task in order not to block the event caller. but I do not understand what event caller is blocked. My main thread does not handle any event during DiscoverPipes() running.

Children
No Data
Related