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

connect to bonded device using Masteremulator C#

Hi all,

I am using a C# application with the masteremulator dll to connect to a nRF51822 with S110 V8.0.0

I can bond with a new device, and communicate with it in a secure way. But I don't know how to reconnect later with this bonded device.

I did not find useful info in the examples.

How can the c# application know whether or not the bond() function has to be called?

Any information or example is welcome.

I use function RestoreBondInformation and GetBondInformation to save and restore the bonding information.

Parents
  • I was having the same issue and go it working in the OnConnected event with the following code, although I have to reseat the dongle some of the time to get it to work.

          Task.Run(() =>
            {
            try
            {
                SecurityParameters securityParams = new SecurityParameters();     
                masterEmulator.DeleteBondInformation();
                isBonded = masterEmulator.Bond(securityParams);
                if (isBonded)
                {
                    s = masterEmulator.GetBondInformation();
                    if (File.Exists(@"C:\temp\bond.txt"))
                    {
                        File.Delete(@"C:\temp\bond.txt");
                    }
                    File.WriteAllText(@"C:\temp\bond.txt", s);
                }
                else
                {
                    if (File.Exists(@"C:\temp\bond.txt"))
                    {
                        masterEmulator.DeleteBondInformation();
                        masterEmulator.RestoreBondInformation(File.ReadAllText(@"C:\temp\bond.txt"));
                        masterEmulator.RefreshKeys();
                    }
                }
                
                DiscoverPipes();
                OpenRemotePipes();
            }
            catch (Exception ex)
            {
                LogErrorMessage(string.Format("Exception in OnConnected: {0}", ex.Message),ex.StackTrace);
            }
            });
    
Reply
  • I was having the same issue and go it working in the OnConnected event with the following code, although I have to reseat the dongle some of the time to get it to work.

          Task.Run(() =>
            {
            try
            {
                SecurityParameters securityParams = new SecurityParameters();     
                masterEmulator.DeleteBondInformation();
                isBonded = masterEmulator.Bond(securityParams);
                if (isBonded)
                {
                    s = masterEmulator.GetBondInformation();
                    if (File.Exists(@"C:\temp\bond.txt"))
                    {
                        File.Delete(@"C:\temp\bond.txt");
                    }
                    File.WriteAllText(@"C:\temp\bond.txt", s);
                }
                else
                {
                    if (File.Exists(@"C:\temp\bond.txt"))
                    {
                        masterEmulator.DeleteBondInformation();
                        masterEmulator.RestoreBondInformation(File.ReadAllText(@"C:\temp\bond.txt"));
                        masterEmulator.RefreshKeys();
                    }
                }
                
                DiscoverPipes();
                OpenRemotePipes();
            }
            catch (Exception ex)
            {
                LogErrorMessage(string.Format("Exception in OnConnected: {0}", ex.Message),ex.StackTrace);
            }
            });
    
Children
Related