<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Write 6-Bytes data using pc-ble-driver-py with nRF52840 Dongle</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/92636/write-6-bytes-data-using-pc-ble-driver-py-with-nrf52840-dongle</link><description>Hi, 
 I am a very beginner in Python and BLE. I would like to use a nRF52840 Dongle to connect to a Bluetooth Device, send 6-Bytes data in the 1401 section and also perform DFU. I tried to use nRF Connect Desktop and they are workable as below. Now, I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 13 Oct 2022 07:48:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/92636/write-6-bytes-data-using-pc-ble-driver-py-with-nrf52840-dongle" /><item><title>RE: Write 6-Bytes data using pc-ble-driver-py with nRF52840 Dongle</title><link>https://devzone.nordicsemi.com/thread/390562?ContentTypeID=1</link><pubDate>Thu, 13 Oct 2022 07:48:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c2f85cee-c0cb-49c8-ab38-af987ce1d22f</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;The loop should only enter if you have not set the COM port in the arguments:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;if len(sys.argv) == 3:
    serial_port = sys.argv[2]
else:
    descs = BLEDriver.enum_serial_ports()
    choices = [&amp;quot;{}: {}&amp;quot;.format(d.port, d.serial_number) for d in descs]
    choice = item_choose(choices)
    serial_port = descs[choice].port&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The default should be for instance: &amp;quot;application_name NRF52 COM10&amp;quot;. Did you also specify connectivity IC identifier?&lt;/p&gt;
&lt;p&gt;These inputs are not required parts of the application, they are only included to make the code support multiple chips and allow the user to select from a list of available COM ports. You can also hardcode this in your application, or find your own way to input the choice. This is not Nordic-specific code, but only standard Python.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write 6-Bytes data using pc-ble-driver-py with nRF52840 Dongle</title><link>https://devzone.nordicsemi.com/thread/390559?ContentTypeID=1</link><pubDate>Thu, 13 Oct 2022 07:31:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:043a58bf-847c-49cf-8dfd-69893ad49541</guid><dc:creator>Teoh Wei Jian</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have specified the serial com port in the command line argument, but still when I run the script, I am stuck in the while loop.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write 6-Bytes data using pc-ble-driver-py with nRF52840 Dongle</title><link>https://devzone.nordicsemi.com/thread/390558?ContentTypeID=1</link><pubDate>Thu, 13 Oct 2022 07:27:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c272c73-1e70-4c43-a844-4f7ae61ca528</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The application needs to know which serial port the connected connectivity chip is available at (the nRF5x board). You can pass this to the application as a command line argument, but if this is not provided, the application will list the available interfaces and let you choose the correct one by inputting a number.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write 6-Bytes data using pc-ble-driver-py with nRF52840 Dongle</title><link>https://devzone.nordicsemi.com/thread/390420?ContentTypeID=1</link><pubDate>Wed, 12 Oct 2022 11:26:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94986762-ae76-4467-b215-85b2b145e1fe</guid><dc:creator>Teoh Wei Jian</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;J&amp;oslash;rgen,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I tried to modify from this example&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/59885/custom-128bit-uuid-operations-write-and-read-in-pc-ble-driver-py/243652#243652"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/59885/custom-128bit-uuid-operations-write-and-read-in-pc-ble-driver-py/243652#243652&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="python"&gt;#
# Copyright (c) 2016 Nordic Semiconductor ASA
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
#   1. Redistributions of source code must retain the above copyright notice, this
#   list of conditions and the following disclaimer.
#
#   2. Redistributions in binary form must reproduce the above copyright notice, this
#   list of conditions and the following disclaimer in the documentation and/or
#   other materials provided with the distribution.
#
#   3. Neither the name of Nordic Semiconductor ASA nor the names of other
#   contributors to this software may be used to endorse or promote products
#   derived from this software without specific prior written permission.
#
#   4. This software must only be used in or with a processor manufactured by Nordic
#   Semiconductor ASA, or in or with a processor manufactured by a third party that
#   is used in combination with a processor manufactured by Nordic Semiconductor.
#
#   5. Any software provided in binary or object form under this license must not be
#   reverse engineered, decompiled, modified and/or disassembled.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &amp;quot;AS IS&amp;quot; AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

import sys
import time
import logging
from queue import Queue, Empty
from pc_ble_driver_py.observers import *

global config, BLEDriver, BLEAdvData, BLEEvtID, BLEAdapter, BLEEnableParams, BLEGapTimeoutSrc, BLEUUID, BLEUUIDBase, BLEConfigCommon, BLEConfig, BLEConfigConnGatt, BLEGapScanParams
from pc_ble_driver_py import config

config.__conn_ic_id__ = &amp;quot;NRF52&amp;quot;
# noinspection PyUnresolvedReferences
from pc_ble_driver_py.ble_driver import (
	BLEDriver,
	BLEAdvData,
	BLEEvtID,
	BLEEnableParams,
	BLEGapTimeoutSrc,
	BLEUUID,
	BLEUUIDBase,
	BLEGapScanParams,
	BLEConfigCommon,
	BLEConfig,
	BLEConfigConnGatt,
)

# noinspection PyUnresolvedReferences
from pc_ble_driver_py.ble_adapter import BLEAdapter

global nrf_sd_ble_api_ver
nrf_sd_ble_api_ver = config.sd_api_ver_get()

TARGET_DEV_NAME = &amp;quot;BLE&amp;quot;
CONNECTIONS = 1
CFG_TAG = 1


def init(conn_ic_id):
    # noinspection PyGlobalUndefined
    global config, BLEDriver, BLEAdvData, BLEEvtID, BLEAdapter, BLEEnableParams, BLEGapTimeoutSrc, BLEUUID, BLEUUIDBase, BLEConfigCommon, BLEConfig, BLEConfigConnGatt, BLEGapScanParams
    from pc_ble_driver_py import config

    config.__conn_ic_id__ = conn_ic_id
    # noinspection PyUnresolvedReferences
    from pc_ble_driver_py.ble_driver import (
        BLEDriver,
        BLEAdvData,
        BLEEvtID,
        BLEEnableParams,
        BLEGapTimeoutSrc,
        BLEUUID,
		BLEUUIDBase,
        BLEGapScanParams,
        BLEConfigCommon,
        BLEConfig,
        BLEConfigConnGatt,
    )

    # noinspection PyUnresolvedReferences
    from pc_ble_driver_py.ble_adapter import BLEAdapter

    global nrf_sd_ble_api_ver
    nrf_sd_ble_api_ver = config.sd_api_ver_get()


class HRCollector(BLEDriverObserver, BLEAdapterObserver):

    NUS_BASE_UUID   = BLEUUIDBase([0x0041], 0x02) # 0x02 is the type BLE_UUID_TYPE_VENDOR_BEGIN 
    NUS_RX_UUID = BLEUUID(0x1041, NUS_BASE_UUID)
    NUS_TX_UUID = BLEUUID(0x3041, NUS_BASE_UUID)

    def __init__(self, adapter):
        super(HRCollector, self).__init__()
        self.adapter = adapter
        self.conn_q = Queue()
        self.adapter.observer_register(self)
        self.adapter.driver.observer_register(self)
        self.adapter.default_mtu = 250
		
        

    def open(self):
        self.adapter.driver.open()
        if config.__conn_ic_id__ == &amp;quot;NRF51&amp;quot;:
            self.adapter.driver.ble_enable(
                BLEEnableParams(
                    vs_uuid_count=10,
                    service_changed=0,
                    periph_conn_count=0,
                    central_conn_count=1,
                    central_sec_count=0,
                )
            )
        elif config.__conn_ic_id__ == &amp;quot;NRF52&amp;quot;:
            gatt_cfg = BLEConfigConnGatt()
            gatt_cfg.att_mtu = self.adapter.default_mtu
            gatt_cfg.tag = CFG_TAG
            self.adapter.driver.ble_cfg_set(BLEConfig.conn_gatt, gatt_cfg)

            self.adapter.driver.ble_enable()

        self.adapter.driver.ble_vs_uuid_add(HRCollector.NUS_BASE_UUID)

    def close(self):
        self.adapter.driver.close()

    def connect_and_discover(self):
        scan_duration = 180
        params = BLEGapScanParams(interval_ms=200, window_ms=150, timeout_s=scan_duration)

        self.adapter.driver.ble_gap_scan_start(scan_params=params)

        try:
            new_conn = self.conn_q.get(timeout=scan_duration)
            self.adapter.service_discovery(new_conn)

            self.adapter.enable_notification(new_conn, HRCollector.NUS_TX_UUID)
            return new_conn
        except Empty:
            print(f&amp;quot;No heart rate collector advertising with name {TARGET_DEV_NAME} found.&amp;quot;)
            return None

    def on_gap_evt_connected(
        self, ble_driver, conn_handle, peer_addr, role, conn_params
    ):
        print(&amp;quot;New connection: {}&amp;quot;.format(conn_handle))
        self.conn_q.put(conn_handle)

    def on_gap_evt_disconnected(self, ble_driver, conn_handle, reason):
        print(&amp;quot;Disconnected: {} {}&amp;quot;.format(conn_handle, reason))

    def on_gap_evt_adv_report(
        self, ble_driver, conn_handle, peer_addr, rssi, adv_type, adv_data
    ):
        if BLEAdvData.Types.complete_local_name in adv_data.records:
            dev_name_list = adv_data.records[BLEAdvData.Types.complete_local_name]

        elif BLEAdvData.Types.short_local_name in adv_data.records:
            dev_name_list = adv_data.records[BLEAdvData.Types.short_local_name]

        else:
            return

        dev_name = &amp;quot;&amp;quot;.join(chr(e) for e in dev_name_list)
        address_string = &amp;quot;&amp;quot;.join(&amp;quot;{0:02X}&amp;quot;.format(b) for b in peer_addr.addr)
        print(
            &amp;quot;Received advertisment report, address: 0x{}, device_name: {}&amp;quot;.format(
                address_string, dev_name
            )
        )

        if dev_name == TARGET_DEV_NAME:
            self.adapter.connect(peer_addr, tag=CFG_TAG)

    def on_notification(self, ble_adapter, conn_handle, uuid, data):
        if len(data) &amp;gt; 32:
            data = &amp;quot;({}...)&amp;quot;.format(data[0:10])
        print(&amp;quot;Connection: {}, {} = {}&amp;quot;.format(conn_handle, uuid, data))
        print(&amp;quot;NUS_RX: &amp;quot; + &amp;#39;&amp;#39;.join(map(chr,data)))


def main(selected_serial_port):
    print(&amp;quot;Serial port used: {}&amp;quot;.format(selected_serial_port))
    driver = BLEDriver(
        serial_port=selected_serial_port, auto_flash=False, baud_rate=1000000, log_severity_level=&amp;quot;info&amp;quot;
    )

    adapter = BLEAdapter(driver)
    collector = HRCollector(adapter)
    collector.open()
    conn = collector.connect_and_discover()

    #if conn is not None:
        #time.sleep(1000)
        #while True:
            #nus_string = input(&amp;quot;NUS string: &amp;quot;).encode()
            #adapter.write_req(conn, HRCollector.NUS_RX_UUID, nus_string + b&amp;#39;\n&amp;#39;)
    nus_string = [0x05, 0x00, 0x30, 0x01, 0x01, 0x00, 0x00]
    adapter.write_req(conn, HRCollector.NUS_RX_UUID, nus_string + b&amp;#39;\n&amp;#39;)
    collector.close()


def item_choose(item_list):
    for i, it in enumerate(item_list):
        print(&amp;quot;\t{} : {}&amp;quot;.format(i, it))
    print(&amp;quot; &amp;quot;)

    while True:
        try:
            choice = int(input(&amp;quot;Enter your choice: &amp;quot;))
            if (choice &amp;gt;= 0) and (choice &amp;lt; len(item_list)):
                break
        except Exception:
            pass
        print(&amp;quot;\tTry again...&amp;quot;)
    return choice


if __name__ == &amp;quot;__main__&amp;quot;:
    logging.basicConfig(
        level=&amp;quot;DEBUG&amp;quot;,
        format=&amp;quot;%(asctime)s [%(thread)d/%(threadName)s] %(message)s&amp;quot;,
    )
    serial_port = None
    if len(sys.argv) &amp;lt; 2:
        print(&amp;quot;Please specify connectivity IC identifier (NRF51, NRF52)&amp;quot;)
        exit(1)
    init(sys.argv[1])
    if len(sys.argv) == 3:
        serial_port = sys.argv[2]
    else:
        descs = BLEDriver.enum_serial_ports()
        choices = [&amp;quot;{}: {}&amp;quot;.format(d.port, d.serial_number) for d in descs]
        choice = item_choose(choices)
        serial_port = descs[choice].port
    main(serial_port)
    quit()
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I don&amp;#39;t understand the choice refer to.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="python"&gt; while True:
        try:
            choice = int(input(&amp;quot;Enter your choice: &amp;quot;))
            if (choice &amp;gt;= 0) and (choice &amp;lt; len(item_list)):
                break
        except Exception:
            pass
        print(&amp;quot;\tTry again...&amp;quot;)
    return choice&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write 6-Bytes data using pc-ble-driver-py with nRF52840 Dongle</title><link>https://devzone.nordicsemi.com/thread/389739?ContentTypeID=1</link><pubDate>Fri, 07 Oct 2022 04:03:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb614b4a-62c5-420a-b173-c0a448b47ad9</guid><dc:creator>Teoh Wei Jian</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;J&amp;oslash;rgen,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am trying for #1.&lt;/p&gt;
&lt;p&gt;1401 is the characteristics of the BLE Device. The purpose is to write a 7-bytes value to the unit.&lt;/p&gt;
&lt;p&gt;I have modified the script from the NUS example. I attached my script below. When I run the script I am able to connect with my BLE Device. But I am not sure where to input the 7-bytes value for the 1401 characteristics.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;import sys
import time
import logging
from queue import Queue, Empty
from pc_ble_driver_py.observers import *

global config, BLEDriver, BLEAdvData, BLEEvtID, BLEAdapter, BLEEnableParams, BLEGapTimeoutSrc, BLEUUID, BLEUUIDBase, BLEConfigCommon, BLEConfig, BLEConfigConnGatt, BLEGapScanParams
from pc_ble_driver_py import config

config.__conn_ic_id__ = &amp;quot;NRF52&amp;quot;
# noinspection PyUnresolvedReferences
from pc_ble_driver_py.ble_driver import (
	BLEDriver,
	BLEAdvData,
	BLEEvtID,
	BLEEnableParams,
	BLEGapTimeoutSrc,
	BLEUUID,
	BLEUUIDBase,
	BLEGapScanParams,
	BLEConfigCommon,
	BLEConfig,
	BLEConfigConnGatt,
)

# noinspection PyUnresolvedReferences
from pc_ble_driver_py.ble_adapter import BLEAdapter

global nrf_sd_ble_api_ver
nrf_sd_ble_api_ver = config.sd_api_ver_get()

TARGET_DEV_NAME = &amp;quot;BLE&amp;quot;
CONNECTIONS = 1
CFG_TAG = 1


def init(conn_ic_id):
    # noinspection PyGlobalUndefined
    global config, BLEDriver, BLEAdvData, BLEEvtID, BLEAdapter, BLEEnableParams, BLEGapTimeoutSrc, BLEUUID, BLEUUIDBase, BLEConfigCommon, BLEConfig, BLEConfigConnGatt, BLEGapScanParams
    from pc_ble_driver_py import config

    config.__conn_ic_id__ = conn_ic_id
    # noinspection PyUnresolvedReferences
    from pc_ble_driver_py.ble_driver import (
        BLEDriver,
        BLEAdvData,
        BLEEvtID,
        BLEEnableParams,
        BLEGapTimeoutSrc,
        BLEUUID,
	BLEUUIDBase,
        BLEGapScanParams,
        BLEConfigCommon,
        BLEConfig,
        BLEConfigConnGatt,
    )

    # noinspection PyUnresolvedReferences
    from pc_ble_driver_py.ble_adapter import BLEAdapter

    global nrf_sd_ble_api_ver
    nrf_sd_ble_api_ver = config.sd_api_ver_get()


class HRCollector(BLEDriverObserver, BLEAdapterObserver):

    NUS_BASE_UUID   = BLEUUIDBase([0x0041], 0x02) # 0x02 is the type BLE_UUID_TYPE_VENDOR_BEGIN 
    NUS_RX_UUID = BLEUUID(0x1041, NUS_BASE_UUID)
    NUS_TX_UUID = BLEUUID(0x3041, NUS_BASE_UUID)

    def __init__(self, adapter):
        super(HRCollector, self).__init__()
        self.adapter = adapter
        self.conn_q = Queue()
        self.adapter.observer_register(self)
        self.adapter.driver.observer_register(self)
        self.adapter.default_mtu = 250
		
        

    def open(self):
        self.adapter.driver.open()
        if config.__conn_ic_id__ == &amp;quot;NRF51&amp;quot;:
            self.adapter.driver.ble_enable(
                BLEEnableParams(
                    vs_uuid_count=10,
                    service_changed=0,
                    periph_conn_count=0,
                    central_conn_count=1,
                    central_sec_count=0,
                )
            )
        elif config.__conn_ic_id__ == &amp;quot;NRF52&amp;quot;:
            gatt_cfg = BLEConfigConnGatt()
            gatt_cfg.att_mtu = self.adapter.default_mtu
            gatt_cfg.tag = CFG_TAG
            self.adapter.driver.ble_cfg_set(BLEConfig.conn_gatt, gatt_cfg)

            self.adapter.driver.ble_enable()

        self.adapter.driver.ble_vs_uuid_add(HRCollector.NUS_BASE_UUID)

    def close(self):
        self.adapter.driver.close()

    def connect_and_discover(self):
        scan_duration = 180
        params = BLEGapScanParams(interval_ms=200, window_ms=150, timeout_s=scan_duration)

        self.adapter.driver.ble_gap_scan_start(scan_params=params)

        try:
            new_conn = self.conn_q.get(timeout=scan_duration)
            self.adapter.service_discovery(new_conn)

            self.adapter.enable_notification(new_conn, HRCollector.NUS_TX_UUID)
            return new_conn
        except Empty:
            print(f&amp;quot;No heart rate collector advertising with name {TARGET_DEV_NAME} found.&amp;quot;)
            return None

    def on_gap_evt_connected(
        self, ble_driver, conn_handle, peer_addr, role, conn_params
    ):
        print(&amp;quot;New connection: {}&amp;quot;.format(conn_handle))
        self.conn_q.put(conn_handle)

    def on_gap_evt_disconnected(self, ble_driver, conn_handle, reason):
        print(&amp;quot;Disconnected: {} {}&amp;quot;.format(conn_handle, reason))

    def on_gap_evt_adv_report(
        self, ble_driver, conn_handle, peer_addr, rssi, adv_type, adv_data
    ):
        if BLEAdvData.Types.complete_local_name in adv_data.records:
            dev_name_list = adv_data.records[BLEAdvData.Types.complete_local_name]

        elif BLEAdvData.Types.short_local_name in adv_data.records:
            dev_name_list = adv_data.records[BLEAdvData.Types.short_local_name]

        else:
            return

        dev_name = &amp;quot;&amp;quot;.join(chr(e) for e in dev_name_list)
        address_string = &amp;quot;&amp;quot;.join(&amp;quot;{0:02X}&amp;quot;.format(b) for b in peer_addr.addr)
        print(
            &amp;quot;Received advertisment report, address: 0x{}, device_name: {}&amp;quot;.format(
                address_string, dev_name
            )
        )

        if dev_name == TARGET_DEV_NAME:
            self.adapter.connect(peer_addr, tag=CFG_TAG)

    def on_notification(self, ble_adapter, conn_handle, uuid, data):
        if len(data) &amp;gt; 32:
            data = &amp;quot;({}...)&amp;quot;.format(data[0:10])
        print(&amp;quot;Connection: {}, {} = {}&amp;quot;.format(conn_handle, uuid, data))
        print(&amp;quot;NUS_RX: &amp;quot; + &amp;#39;&amp;#39;.join(map(chr,data)))


def main(selected_serial_port):
    print(&amp;quot;Serial port used: {}&amp;quot;.format(selected_serial_port))
    driver = BLEDriver(
        serial_port=selected_serial_port, auto_flash=False, baud_rate=1000000, log_severity_level=&amp;quot;info&amp;quot;
    )

    adapter = BLEAdapter(driver)
    collector = HRCollector(adapter)
    collector.open()
    conn = collector.connect_and_discover()

    if conn is not None:
        #time.sleep(1000)
        while True:
            nus_string = input(&amp;quot;NUS string: &amp;quot;).encode()
            adapter.write_req(conn, HRCollector.NUS_RX_UUID, nus_string + b&amp;#39;\n&amp;#39;)

    collector.close()


def item_choose(item_list):
    for i, it in enumerate(item_list):
        print(&amp;quot;\t{} : {}&amp;quot;.format(i, it))
    print(&amp;quot; &amp;quot;)

    while True:
        try:
            choice = int(input(&amp;quot;Enter your choice: &amp;quot;))
            if (choice &amp;gt;= 0) and (choice &amp;lt; len(item_list)):
                break
        except Exception:
            pass
        print(&amp;quot;\tTry again...&amp;quot;)
    return choice


if __name__ == &amp;quot;__main__&amp;quot;:
    logging.basicConfig(
        level=&amp;quot;DEBUG&amp;quot;,
        format=&amp;quot;%(asctime)s [%(thread)d/%(threadName)s] %(message)s&amp;quot;,
    )
    serial_port = None
    if len(sys.argv) &amp;lt; 2:
        print(&amp;quot;Please specify connectivity IC identifier (NRF51, NRF52)&amp;quot;)
        exit(1)
    init(sys.argv[1])
    if len(sys.argv) == 3:
        serial_port = sys.argv[2]
    else:
        descs = BLEDriver.enum_serial_ports()
        choices = [&amp;quot;{}: {}&amp;quot;.format(d.port, d.serial_number) for d in descs]
        choice = item_choose(choices)
        serial_port = descs[choice].port
    main(serial_port)
    quit()
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Write 6-Bytes data using pc-ble-driver-py with nRF52840 Dongle</title><link>https://devzone.nordicsemi.com/thread/389654?ContentTypeID=1</link><pubDate>Thu, 06 Oct 2022 13:46:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:588973b1-2130-496c-95a8-176dfc2f7dce</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]1. Send 6 Bytes data in 1401 section.[/quote]
&lt;p&gt;Did you try it out with code similar to the one I posted in the first link? Is section 1401 your own custom service?&lt;/p&gt;
[quote user=""]2. Perform DFU to program product firmware.[/quote]
&lt;p&gt;Our command line DFU tool, nrfutil, is written on top of pc-ble-driver-py. You can have a look at the &lt;a href="https://github.com/NordicSemiconductor/pc-nrfutil/tree/master/nordicsemi/dfu"&gt;source code&lt;/a&gt; to see how to implement DFU in your application.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>