Writing SBIO backend in Python

Dear community,

all of the example I've found about writing SBIO backends using C.

Even if C is the most commonly used language in embedded development, we're facing some users that don't have big C expertise but have a good knowledge of Python.

For sure we can call SBIO C libraries from Python, but I'm wondering if you already have some example or, even better, Python binding to handle communication with sbengine

Kind Regards and TIA

Andrea

0

Comments

4 comments
  • Official comment

    Hi Andrea,

    What Corey mentions is the recommended approach today and from time to time we work with customers who want to use Python with Storyboard for various reasons.

    It is of course possible to create a Python extension which wraps our SBIO library.  I have been working on a prototype implementation which uses Python 3.7 and dictionary objects to represent Storyboard IO events.

    The primary objective for this was to enable users to do rapid prototyping of 'back-end' applications for Storyboard applications and is particularly useful for create test scripts using Python.

    It is a work in progress and not yet ready for official release however below is the readme file in its' current state:

    python_sbio_readme.txt

    Here is a simple example of a test script which sends and receives events (it uses the same channel to send and receive as a loopback test):

    receive_event_simple.py

    There is still work to do on this wrapper library however if it is useful to you then I can share what I have currently on an unsupported basis and welcome your feedback and suggestions. In my experiments I used this on a Raspberry Pi 4 for convenience.

    I would like to make this available through our public Github repository once it has been tested more effectively and ready for release.

    I'll reach out to you separately to discuss next steps.

    Regards,

    Garry

  • Hi Andrea,

    I have worked with Python on several projects and while I've considered generating bindings for optimization purposes, it may be unnecessary for most use cases.  You can use the iogen command line utility (provided with Storyboard Engine, in the same bin/ directory as sbengine) to generate any IO event you need.  By writing a Python wrapper class (assembling events kind of like you would an SQL statement, then executing the iogen command) around this utility, which provides an interface appropriate to your project, I think you might find that works well enough.  You lose the convenience of using the autogenerated header file, but it is not necessary to use this in order to communicate with your application over SBIO.

    If optimization is a concern (ie. you expect a lot of events), then writing Python bindings might be a bit better approach than this, but ultimately will still incur a heavy cost vs generating your IO activity purely in C.  If you have Python devs and implementation convenience is your goal, the above suggestion should get you going in a few minutes.  Let me know if you'd benefit from a quick example script.

    0
  • Dear Corey,

    thanks for you fast feedback!

    I'll suggest using iogen to our users. If you have any code example to share here, I think it may be useful for others too (this is the first and only hit in this community when searching "python" keyword ;-) )

    Kind Regards,

    Andrea

    0
  • Hi Andrea,

    I have used the Storyboard API from within python using the the ctypes module to directly use the greio library from Crank.
    The only drawback is that you need a shared library for that. So hopefully at some point, crank can provide the shared library by default.

    If there is any interest, I can provide my code and an example of how I use it.

    Regards, Martin

    0

Please sign in to leave a comment.

Didn't find what you were looking for?

New post