This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Progress from ble_dfu.py

I need to automate updating the bootloader and radio for an nRF51 in a production setting with a VB.NET windows application. I'm able to call dfu/main.py with the code below and it starts to execute ble_dfu.py.

    mEngine = Python.CreateEngine()
    mScope = mEngine.CreateScope
    mSource = mEngine.CreateScriptSourceFromFile(sourceFile, System.Text.Encoding.ASCII, Microsoft.Scripting.SourceCodeKind.Statements)
    mcCode = mSource.Compile()

I have two questions:

  1. How do I monitor the progress of the update process? I see that there are calls to ble_dfu.Progress, but how do I get at that from the .NET side?
  2. The update process usually gets stuck with a "Waiting for packet receipt notification" message, which sounds like the host didn't get a receipt from the nRF51. Is there another configuration setting that needs to be done?
  • Do you have a solution to put the softdevice and DFU in before you can use your program ? Would you be interested in a parallel programming the nRF51 like this one instead. It combines all 3 part together an program multiple board at once.

    Parallel gang Flashing nRF51 with IDAPnRFProg (see blog site for more info) Results bellow showing on OS X. Windows version is available.

    $./IDAPnRFProg s110_nrf51822_7.1.0_softdevice.hex Blinky_ble.hex dfu_sdk7.hex
    
    IDAPnRFProg version 0.0
    Copyright 2015, I-SYST inc. All rights reserved
    
    Found IDAP-Link - S/N : 0000000000001
    Found IDAP-Link - S/N : 0000000000002
    IDAP-Link-0000000000001 : nRF51 detected : nRF51822-QFAA R1
    IDAP-Link-0000000000001 : Flash size = 262144, Ram size = 16384
    IDAP-Link-0000000000002 : nRF51 detected : nRF51822-QFAA R2
    IDAP-Link-0000000000002 : Flash size = 262144, Ram size = 16384
    
    IDAP-Link found : 2
    
    IDAP-Link-0000000000001 : Erase Flash
    IDAP-Link-0000000000002 : Erase Flash
    IDAP-Link-0000000000001 : Blank checking...
    IDAP-Link-0000000000002 : Blank checking...
    IDAP-Link-0000000000001 : Programming...
    IDAP-Link-0000000000002 : Programming...
    IDAP-Link-0000000000001 : Verifying...
    IDAP-Link-0000000000002 : Verifying...
    IDAP-Link-0000000000002 : Flashing succeeded
    IDAP-Link-0000000000001 : Flashing succeeded
    
    Flashed 2 nRF51 devices, Total 524288 bytes in 38.032001 sec, rate = 13.462347 KB/s
    
  • These devices have already been welded shut, so there is no JTAG access. It MUST be via OTA.

  • In your VB .NET code you can create a function that will be called from the python script that takes the same arguments as the BleDfu.ProgressChanged() function in ble_dfu.py. This can be something like this:

    Public Class ProgChangeVB
        Public Function ProgressChanged(ByVal percent As Integer, ByVal message As String, ByVal finished As Boolean) As Integer
            Console.WriteLine(String.Format("{0} {1}, Finished: {2}", message, percent, finished))
            Return percent
        End Function
    End Class
    

    This function will print the messages to console.

    Then you have to add a reference to your VB .NET assembly in python, and create a class that inherits the VB class. Also create an instance of the new Progress() class.

    In main.py add:

    import clr
    clr.AddReference('YourApplication')
    from YourApplication import ProgChangeVB
    
    class Progress(ProgChangeVB):
        pass
    
    vbprogress = Progress()
    

    After the ble_dfu = BleDfu(...) instantiation in main(), you can assign all calls to BleDfu.ProgressChanged() to the new function you created above:

    ble_dfu.ProgressChanged = vbprogress.ProgressChanged
    

    To test it, simply try this:

    ble_dfu.ProgressChanged(0, "Test, test, test", True)
    

    If you want to only see the progress information in the console and write all the other prints from the python code to a file. You can add this to your VB.NET main function:

    Dim fs As System.IO.FileStream
    fs = New System.IO.FileStream("c:\\temp\\ipy.log", System.IO.FileMode.Create)
    mEngine.Runtime.IO.SetOutput(fs, System.Text.Encoding.ASCII)
    
Related