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

BLE masteremulator.dll - Problem with masteremulator. bond() method

Hi,

I have been experimenting with the master emulator .dll - I started with the HidDemo project which is written in C#. This seems to work perfectly well.

I have rewritten ( translated ?) the demo code into VB.NET ( Visual Studio Express 2010). Everything seems to be ok until I try to call masteremulator.bond(securityparameters). In my version this fails. As far as I can see the security parameters I am sending to the method are the same as those sent by the HidDemo bond function.

I have attached a word document with both sets of code and the securityparameters exposed. I have also attached attached the log that the masteremulator dll has churned out (sorry it is in verbose mode).

I fully expect to find that I am missing something glaringly obvious, but for the moment I can see the wood for the trees! :)

Thanks in advance to anyone who can spot the problem.

Regards

Godric

master_emulator_log.txt

Parents
  • One thing you should be aware of when using the Master Emulator API is that you can not block or call Master Emulator API functions in any of the callback methods you receive. As you can see, the demo applications solve this by using the BeginInvoke construct or similar to do everything in the callbacks in a background thread, for example like this from the ProximityDemo:

    
    this.BeginInvoke((MethodInvoker)delegate()
    {
    	lblConnectedSymbol.BackColor = Color.LightGreen;
    	btnConnectDisconnect.Text = AppText.Disconnect;
    	if (pipeDiscoveryComplete)
    	{
    		grpRight.Enabled = true;
    		pnlRight.BackColor = Color.LightGreen;
    	}
    	isConnected = true;
    });
    
    

    or this from the HidDemo:

    
    /* The connection is up, proceed with Bond and pipe discovery. 
        * Using a background task in order not to block the event caller. */
    Task.Factory.StartNew(() =>
    {
        try
        {
            Bond();
            DiscoverPipes();
            OpenRemotePipes();
            ReadBatteryLevel();
            WriteHidProtocolMode();
            AddToLog("Ready");
        }
        catch (Exception ex)
        {
            LogErrorMessage(string.Format("Exception in OnConnected: {0}", ex.Message),
                ex.StackTrace);
        }
    });
    
    

    If you don't do this, you will get strange errors, for example failure to discover services at all, hangs or possibly just bogus errors returned. I'm afraid I'm not sure how to do similar things in VB, but I assume it's possible.

Reply
  • One thing you should be aware of when using the Master Emulator API is that you can not block or call Master Emulator API functions in any of the callback methods you receive. As you can see, the demo applications solve this by using the BeginInvoke construct or similar to do everything in the callbacks in a background thread, for example like this from the ProximityDemo:

    
    this.BeginInvoke((MethodInvoker)delegate()
    {
    	lblConnectedSymbol.BackColor = Color.LightGreen;
    	btnConnectDisconnect.Text = AppText.Disconnect;
    	if (pipeDiscoveryComplete)
    	{
    		grpRight.Enabled = true;
    		pnlRight.BackColor = Color.LightGreen;
    	}
    	isConnected = true;
    });
    
    

    or this from the HidDemo:

    
    /* The connection is up, proceed with Bond and pipe discovery. 
        * Using a background task in order not to block the event caller. */
    Task.Factory.StartNew(() =>
    {
        try
        {
            Bond();
            DiscoverPipes();
            OpenRemotePipes();
            ReadBatteryLevel();
            WriteHidProtocolMode();
            AddToLog("Ready");
        }
        catch (Exception ex)
        {
            LogErrorMessage(string.Format("Exception in OnConnected: {0}", ex.Message),
                ex.StackTrace);
        }
    });
    
    

    If you don't do this, you will get strange errors, for example failure to discover services at all, hangs or possibly just bogus errors returned. I'm afraid I'm not sure how to do similar things in VB, but I assume it's possible.

Children
No Data
Related