Codemotion 2013 Madrid - Modern OOP embedded development with .NET Micro Framework

829 views

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
829
On SlideShare
0
From Embeds
0
Number of Embeds
211
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Codemotion 2013 Madrid - Modern OOP embedded development with .NET Micro Framework

  1. 1. Lorenzo Maiorfi Modern OOP embedded development with .NET Micro Framework maiorfi@innovactive.it – www.innovactive.it www.tinyclr.it
  2. 2. What does «embedded development» actually mean? Lorenzo Maiorfi maiorfi@innovactive.it – www.innovactive.it www.tinyclr.it • Small Hardware components… • Microcontrollers (microprocessor cores driving electrical analog/digital peripherals) • • • small (about 1 square cm) cheap (€1-10 each) low-power (about 50-100 uA per MHz) • External boards/modules/IC • • running specific tasks (i.e. sensors, actuators) bound via some communication channel (network, serial port, CAN, I2C, SPI, etc)
  3. 3. What does «embedded development» actually mean? Lorenzo Maiorfi maiorfi@innovactive.it – www.innovactive.it www.tinyclr.it • …running small software «modules» • Native firmware • • • • Hard to write/debug/maintain Vendor/platform specific (not portable) Uses «old» languages/paradigms (C, assembler, core registers access, memory-based actions, etc) Managed firmware • • • • Easy to write/debug/maintain Portable Uses OOP/OOD concepts Abstracts both «machine model» and interactions with other «actors» of whole solution
  4. 4. Introducing .NET Micro Framework Lorenzo Maiorfi maiorfi@innovactive.it – www.innovactive.it www.tinyclr.it An open-source platform (runtime/libraries , toolchain and IDE) that excels in: • Productivity – Visual Studio IDE, C#/VB.NET compilers, debugger and emulator make up the most productive suite on the embedded market • Reliability – managed runtime keeps under control all application layers • Portability – could be ported to all known technologies, at this time covers most microcontrollers whose core is based on 32 bit ARM™ • Support – open-source under Apache 2.0 license, contains many community-provided resources
  5. 5. How to write applications with .NET Micro Framework Lorenzo Maiorfi maiorfi@innovactive.it – www.innovactive.it www.tinyclr.it 1. Developer writes code by mean of high-level languages such as C# or VB.NET 2. Compiler generates one or more «assemblies» 3. Assemblies binary images are stored in device flash (i.e. non-volatile) memory 4. Once reset, device runs a bootloader, that on its turn fires managed runtime (TinyCLR) 5. TinyCLR loads both framework and «user» assemblies, and soon after it runs entry-point method, i.e. the «Main()»
  6. 6. Demo #1 – Getting Started Lorenzo Maiorfi DEMO Hello,world (with 3 different patterns) white led button
  7. 7. OOP/OOD with .NET Micro Framework Lorenzo Maiorfi maiorfi@innovactive.it – www.innovactive.it www.tinyclr.it • OOP/OOD is very suitable for embedded development, since it naturally maps physical objects to software models, by mean of classes, objects and interfaces • Encapsulation allows for better component isolation (black-box model) • Inheritance allows for better code reuse when using several «variants/flavors» of same component • Polymorphism allows for a better way to connect objects, by mean of «outlet» abstraction, i.e. interfaces
  8. 8. OOP/OOD with .NET Micro Framework Lorenzo Maiorfi maiorfi@innovactive.it – www.innovactive.it www.tinyclr.it We’re going to apply this paradigm on a simple “devicedriver” for a small integrated-circuit (IC): MCP3201 ADC 1. Do some “lab” (quick & dirty demos, test SPIcommunication with a scope, etc) 2. Encapsulate functionalities into a class 3. Add features (such as async events in our case) via inheritance 4. Extract “Interfaces” (i.e. abstract behavior) 5. Re-implement Interfaces differently
  9. 9. Demo #2 – OOP/OOD Demo Lorenzo Maiorfi DEMO ADC Driver This is a POT to change voltage + This is MCP3201!
  10. 10. IoT/M2M as the killer app for .NET Micro Framework Lorenzo Maiorfi maiorfi@innovactive.it – www.innovactive.it www.tinyclr.it .NET Micro Framework killer applications are IoT/M2M systems, since: • It has a rich TCP/IP network stack • There are many libraries implementing both IoT protocols (first and foremost HTTP REST, both client and server) and M2M protocols (primarily MQTT & CoAP) • There are many libraries that allow for «bridging» across other technologies, such as ZigBee, Bluetooth, BLE, vendor-specific 2.4GHz/433MHz radio modules (we’re developing Z-Wave stack, too) • OOP features are great for building systems made of devices that interact in an abstract way!
  11. 11. IoT/M2M with mqtt & node-red Lorenzo Maiorfi maiorfi@innovactive.it – www.innovactive.it www.tinyclr.it • Mqtt is a lightweight pub/sub protocol whose primary focus is communication in IoT/M2M applications • Mqtt client libs are available for all platforms/languages • Node-Red is an open software (based on Node.js) whose purpose is to design and run “flows” • Flows are made of “nodes” targeted to specific functions • Among built-in nodes: tcp-in/out, udp-in/out, httpin/out, mqtt-in/out, twitter, mail, files, mongodb, etc. • Many “logic” node blocks (function, template, switch) • You can write (and debug, via node-inspector) your own nodes, too!
  12. 12. Demo #3 – IoT/M2M Demo Lorenzo Maiorfi APIs Node-Red http “javascript” Remote #1 mqtt Mqtt Broker Remote #2 mqtt mqtt Radio Bridge radio websockets Robot
  13. 13. Thank you! Lorenzo Maiorfi maiorfi@innovactive.it – www.innovactive.it - @innovactive Tech Blog: www.tinyclr.it - @tinyclr

×