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

Problems creating a C# wrapper for the nrf51-pc-ble-driver

Using the include files and .dll file from www.nordicsemi.com/.../nRF51822 -> "DOWNLOADS" -> "nRF51-BLE-Driver-Win" I have created a C# wrapper for the driver. I works so far as that I can discover devices and create a C# version of the "advertise" example project. Yay!

I am also able to connect to a device but when I get the reply from a primary service discovery there seems to be a disagreement between the ble_gattc_evt_prim_srvc_disc_rsp_t structure used when building the .hex in the archive and the one found in the include folder. The event id indicates that it is a BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP (0x30/48) but when I try to decode the struct something looks wrong. 'count' of services is indicated to be 28273 which I don't think is correct...! The two bytes coming after the count field is the value 2 when read as an uint16 (little endian) which seems closer to the truth but still not correct (there are 3 services). It seems like more than just a padding issue as the values are not just nulls.

The peripheral device is an existing proprietary device which is working fine. Discovering the device using Master Control Panel gives the expected results.

The two files attached are:

Are there any plans for a .NET wrapper from Nordic? Python is not an option.

/Claus

  • Hi, thanks for using devzone.

    If you get strange values like count 28273 it indicates that some invalid data has been read. However I wouldn't suspect the driver or firmware to begin with as these have proven to work with C, Python and NodeJS.

    In the log you have an array listing raw event data. How did you assemble that list? Since the events contains pointers some of the data will be stored elsewhere in memory, outside of the memory sequence of the ble_event struct.

    Another problem can be if data pointers from the event are stored instead of copying the event data. This will cause problem when the event goes out of scope and ble_driver frees the event memory.

    Without seeing the code it's hard to be specific about it. Would it be possible for you to share the code?

    To answer your last question: there are no current plans from Nordic to create .NET wrappers.

  • The array is the raw values received in the callback registered in the call to sd_rpc_evt_handler_set() during setup. The same principles are used in the failing event handler as in the working event handlers. According to the structs in ble_gap.h and ble_gattc.h all structs in question are nested i.e. not pointers and so it should be possible to simple print the array as done.

    The code is purely internal and we do not wish to publish it (not currently anyways) so I will send you a PM with it.

    /Claus

  • Any chance you can provide that wrapper? I was trying to accomplish a similar task but I don't wan to reinvent the wheel. Thanks.

  • Any progress on a C# wrapper, I don't want to use python 2.7 and .NET / C# is a natural for windows pc nowadays

Related