From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

LabVIEW Bluetooth Low Energy Driver development using Universal Windows Platform (UWP)

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Hardware

  • RF|Wireless

    Software

  • LabVIEW

    Driver

  • NI RF Device Drivers

    Operating System

  • Windows

    Programming Language

  • .NET
  • C Sharp
  • LabVIEW G

Code and Documents

Attachment

Description

This example demonstrate on how to use the windows 10 BLE native library to communicate with BLE devices (Smart watch, bulb or any device which support BLE). Developed the DLL to interact with windows 10 BLE library in C# platform and integrated the dll into LabVIEW by using .Net constructor node.

 

Here demonstrates usage of the Bluetooth Generic Attribute (GATT) Client APIs for Universal Windows Platform (UWP), along with sample code for common GATT client tasks:

  • Query for nearby devices
  • Connect to device
  • Enumerate the supported services and characteristics of the device
  • Read and write to a characteristic
  • Subscribe for notifications when characteristic value change

 

 

 

How to Use

Following are the methods available in BLE library:

 

Methods:

  1. BLE_Initialize.vi - Initialize the DLL
  2. BLE_StartWatcher.vi - listening advertisement of near by BLE devices
  3. BLE_Get_WatcherResponse.vi - Gets the manufacture data, BLE address from BLE advertisement
  4. BLE_Get_WatcherReceivedData.vi - Decodes the watcher response
  5. BLE_StopWatcher.vi - Stop getting advertisement from near by BLE devices
  6. BLE_Request_Connect.vi - Initiates the connection to BLE device and returns with response of connection status and GATT Services list from BLE device
  7. BLE_Get_ServicesUUIDs_Property.vi - Gets the GATT service UUIDs and Property UUIDS from BLE device
  8. BLE_Notify.vi - Initiate the BLE notification of UUIDs from BLE device
  9. BLE_Notify_Listener.vi - Gets the notification of UUIDs from BLE device
  10. BLE_Read_Characteristic.vi - Reads the UUIDs of BLE device
  11. BLE_Read_CharacteristicArray.vi - Reads the array of UUIDs of BLE device
  12. BLE_Request_ServiceUUIDs.vi - Get the Service UUIDs
  13. BLE_Write.vi - Write the UUIDs of BLE device
  14. BLE_Write_Without_Response.vi - Write the without response UUIDs of BLE device and not return response

Additional Information

When setting the debug logs to true, C# library created the BLE log files under C drive

 

Development Environment:

LabVIEW 2020 32 Bit

OS: Win 10 64 bit

 

Added the Example code in HLD where user has to change the BLE address before run. The BLE address can be get after running the watcher.

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Bharathi|CLA
Member
Member
on

Bharathi-CLD_0-1602592649778.png

 

Screen shot of BLE device communication using windows UWP library. I have used my smart watch to communicate by using LabVIEW and C# library

 

yokohama_turkey
Member
Member
on

 

Great!
I was waiting for this.
I was able to capture my heart rate monitor with this example.
Thank you Bharathi-CLD.😆

HRM.png

FMonteiro
Member
Member
on

FMonteiro_1-1605617959917.png

Hi, I´m trying to use the write function using:

0000fff2-0000-1000-8000-00805f9b34fb as UUID.

Converting the command string (F0;) to byte array, but I don´t know how to extract the response.

FMonteiro_2-1605618504968.png

 

 

tcie
Member
Member
on

hi, suddenly I started to get "Object reference not set to an instance of an object." error. even using simple code:

tcie_0-1611235374970.png

and now it works again, can it be antivirus?

 

tcie
Member
Member
on

in order to receive the data stream from the BLE device using Notify you have to remove for loop and wait from BLE_Notify_Listener.vi and control it from your app. Also it's good to remove key from the Gatt_Characteristic_NotifyValue after read so you don't read same value over and over.

example: config notify using BLE_Notify.vi, get Gatt_Characteristic_NotifyValue, check if it contains key - new packet of data, if no write "NO DATA/FAILURE" if yes read data and remove it from Gatt_Characteristic_NotifyValue so it's not read multiple times

tcie_0-1611568117566.png

 

tcie
Member
Member
on

I got "Object reference not set to an instance of an object." error agian

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P8XnSAK&l=en-CH

Bharathi|CLA
Member
Member
on

Hello,

 

Pls. let me know are you still getting Object reference not set to an instance of an object error. And let me know if you need any inputs on the driver.

 

Thanks

Bharathi T

tcie
Member
Member
on

the issue appeared again and tips from the link above do not work...

just tried on LV2021 SP1 32 and 64 bit

Could you please share source code of the library too?

 

tcie
Member
Member
on

debug info:

Log : 28.01.2021 20:29:12 ,ConnectBLE method called with address:123456789
Log : 28.01.2021 20:29:12 ,Waiting for BLE to connect with address:123456789
Log : 28.01.2021 20:29:12 ,Exception in ConnectBLE method:Object reference not set to an instance of an object.

 

vs debug without error:

Log : 26.01.2021 13:49:56 ,BLE_LIB method called
Log : 26.01.2021 13:49:56 ,ConnectBLE method called with address:123456789
Log : 26.01.2021 13:49:56 ,Waiting for BLE to connect with address:123456789
Log : 26.01.2021 13:49:56 ,Received the BLE Reference
Log : 26.01.2021 13:49:56 ,Connected with address:123456789
Log : 26.01.2021 13:50:04 ,ConnectBLE method pairstatus:Device unreachable

steve_morris
Member
Member
on

Hi,

I am using the library and am able to pair with my device and get the available UUIDs.  I can read the values for the 'standard' UUIDs like device name, serial number, manufacturer.  But when I try to read the custom UUIDs I get ProtocolError.  Any idea how to correct this?

screenshot.jpg

FMonteiro
Member
Member
on

"in order to receive the data stream from the BLE device using Notify you have to remove for loop and wait from BLE_Notify_Listener.vi and control it from your app. Also it's good to remove key from the Gatt_Characteristic_NotifyValue after read so you don't read same value over and over.

example: config notify using BLE_Notify.vi, get Gatt_Characteristic_NotifyValue, check if it contains key - new packet of data, if no write "NO DATA/FAILURE" if yes read data and remove it from Gatt_Characteristic_NotifyValue so it's not read multiple times"

 

Still not working.

FMonteiro_2-1613523191597.png

First i´m using write function sending the command "J;", than your notify process with UUID selected, is that correct?

 

FMonteiro
Member
Member
on

FMonteiro_0-1613523741515.png

LvTech
Member
Member
on

Hi,

 

Can this library be used in tandem with the BLE toolkit using the BLED112 dongle? I have an application built around the BLE Toolkit, but now need a way to connect to a device and set some values in the attribute table. 

 

Thanks,

 

George

Bharathi|CLA
Member
Member
on

BLED112 has its own LabVIEW library APIs to perform read / write.

User002
Not applicable
on

Muhandojen_0-1617877420120.png

Muhandojen_1-1617877444033.png

 

Hi

 

Program is very good. I use this program connected bluefruit32.              Bluefruit32     https://learn.adafruit.com/adafruit-feather-32u4-bluefruit-le

 

As far as I know Notify is data. And bluefruit32 send data every 1000ms.

 

The program always doesn't read Notify.

 

And I use BLE_Notify_Listener.vi. But data is empty.

 

Try BLE_Notify_Listener.vi add 'remove key' but same result.

 

Please help me.

 

Thanks.

regards.

 

 

 

Bharathi|CLA
Member
Member
on

Hi,

 

We need to register for notification using 'NotifyCharacteristicUUIDValue (BLE_Notify.vi)'. Once you register for this notification, then the new value gets retrived using BLE_Notify_Listener.vi. We have option to see the notification value in the BLE log as well. You may need to add logic to check whether the values are notified for every 1000msec.

SmithGPI
Member
Member
on

I have a customer that has created a beacon using the Silicone Labs BLE Blue Gecko.  The beacon is non-connectable - undirected.  The devices show up under the watcher scan, but since the devices are not connectable I cannot pair with them to retrieve data.  If I use a sniffer, I can see the raw data string with GAP data types 0x09 and 0x16.  Is there a way to access the raw data from a beacon using UWP?

djac91
Member
Member
on

How to monitor connection status?

-----------------------------------------------------------------------------------------------------------------------------
Waiting For the inner calling 🙂


leapBenjamin
Member
Member
on

We are developing a Sensor, that has to send quite some data to the LabView GUI which I am currently developing. In order not to handle too many "packets", the Characteristics is larger than the "standard" max 20 byte payload. But I cannot get more than 20 bytes out via the API, the rest is just ignored apparently. Can I do something to set-up this functionality?

caleris491
Member
Member
on

Hi, thanks for the library.

 

I am using it to connect to an Arduino MKR Wifi 1010 and I noticed that disconnecting does nothing, in fact the arduino detects the disconnection 3 seconds after the program closed. Using the disconnection methods DisConnect_BLE_ByAddress and DisConnect_BLE changes nothing.

Is there a proper way to disconnect the devices ?

 

Thanks.

CRE
Member
Member
on

Hi,

 

this library is very nice to use. Thanks for that.

But not all bytes are coming during data read. It seems also to me that 20bytes is the limit.

Can you change that or share the code for the dll here or on github?

 

Best regards

Ansonngoo84
Member
Member
on

Ansonngoo84_0-1635417140431.png

 

Hi, I´m trying to use the write function using:

0000fff2-0000-1000-8000-00805f9b34fb as UUID.

Converting the command string (F0;) to byte array, but I don´t know how to extract the response.

Ansonngoo84_1-1635417139825.png

 

 

mikoborn
Member
Member
on

Hello you all,

 

the photo attached of the invoke node belongs to the Notify_listener.vi. As the key I tried connecting either one of the UUIDs that have "notify" as a property. However "ContainsKey" is false for both cases. I am somwhat lost on what to do/try next. Is there any way to view what keys are acceptet for the "ContainsKey" function? Any advice would be welcome.

Unbenannt1.png

 

 

 

Unbenannt.PNG

m2ochi
Member
Member
on

Hi,

 

Thank you for providing such a wonderful library.
Is it possible to use indicate instead of notify in this library? Or is it possible to write directly to CCCD?

 

Best regards.

WillHill
Member
Member
on

Hi you all,

Thanks and congratulations to the developer for this very usefull library !

My problem is that I need to obtain the adittional data on 2nd advertising from a peripheral in my application.

Is there any way to send a Scan Request and then receive the Scan Response ?

 

thank in advanced !!

 

Best Regards.

 

Vijey123
Member
Member
on

Hello, 

 

I have a critical issue. I need to pair a cluster that displays a pair key to connect with it. The pass key has to be entered in the Labview. I am using BLE_Notify _Listener.vi to send it to the cluster. Is there any specific format to send the key along with UUID?

 

Any leads would be appreciated.

 

Regards,

Vijey.