FREEMASTER LITE GETTING STARTED WITH JSON-RPC PROTOCOL FROM SCRIPTING TO VISUAL DASHBOARDS WITH PYTHON AND JAVASCRIPT
←
→
Page content transcription
If your browser does not render page correctly, please read the page content below
FreeMASTER Lite Getting Started with JSON-RPC Protocol From Scripting to Visual Dashboards with Python and JavaScript Iulian Stan Software Engineer, AP System Tools M AY 2 0 2 0 EXTERNAL NXP, THE NXP LOGO AND NXP SECURE CONNECTIONS FOR A SMARTER W ORLD ARE TRADEMARKS OF NXP B.V. ALL OTHER PRODUCT OR SERVICE NAMES ARE THE PROPERTY OF THEIR RES PECTIVE OW NERS. © 2020 NXP B.V.
AGENDA • FreeMASTER 3.0 − FreeMASTER − FreeMASTER Lite • JSON-RPC • FreeMASTER Lite − Package Content − Running the Tool − Configuration File • Coding Examples 1. Python Scripting 2. NodeJS Scripting 3. Web Dashboard EXTERNAL 1
F R E E M AS T E R 3 . 0 FreeMASTER 3rd party Apps Embedded Browser local or remote Native Charts JSON-RPC Clients Target Microcontroller Board UART Communication DLL USB Serial / USB-CDC JSON-RPC Server ActiveX Clients CAN USB to CAN JTAG/SWD ActiveX Server Debug protocols Windows PC EXTERNAL 2
F R E E M AS T E R 3 . 0 FreeMASTER Lite 3rd party Apps local or remote External Web Browser Target Microcontroller Board UART Communication DLL USB Serial / USB-CDC JSON-RPC Clients CAN USB to CAN JSON-RPC Server JTAG/SWD Debug protocols Windows / Linux PC EXTERNAL 3
JSON-RPC Remote Procedure Call encoded as JSON objects Server Client { "jsonrpc": "2.0", App Web Page Script "method": "ReadVariable", "params": ["MyVar"], "id": 1 } Client specifies method name and input arguments to be invoked on the server side EXTERNAL 4
JSON-RPC Remote Procedure Call encoded as JSON objects { "jsonrpc": "2.0", "result": { Server Client "data": "3.14" }, "id": 1 } App Web Page Script Server replies with method invocation returned data (if any), or error code EXTERNAL 5
F R E E M AS T E R L I T E - PAC K A G E C O N T E N T COM LIBRARY & SERVICE APP DOCUMENTED CLIENT LIBRARY READY TO USE EXAMPLES mcbcom.dll freemaster-client.js • Fully compatible with • Vanilla JavaScript library running FreeMASTER desktop application both on front-end and back-end • Same com. plugins on Windows • JSDoc documentation • Ready to use widget-like examples • Serial communication on Linux • Features: variables read & write, scope & recorder functionalities & node.exe • NodeJS powered service • Web server (static content & custom web applications) • WebSocket server (JSON-RPC API) EXTERNAL 6
F R E E M AS T E R L I T E - R U N N I N G T H E T O O L C:\NXP\FreeMASTER 3.0\FreeMASTER Lite\node.exe http://localhost:8090/ node.exe Server starts with default config EXTERNAL 7
{ F R E E M AS T E R L I T E - C O N F I G U R AT I O N F I L E "port": 41000, Service "web_root": "path_to_static_web_content", "dirs": [ config { Exporting project configuration from FreeMASTER "path": "C:\\Temp", "opts": "r", File → Export → FreeMASTER Service Configuration "exts": [ ".txt", File IO config ".json" ] } ], Target connection config "connections": [ { "name": "S32K144 UART", "description": "UART over USB (Open SDA)", "connection_string": "RS232;port=COM6;speed=115200", "elf": "" } ], Target project config "variables": [ { "name": "Potentiometer", "addr": "potmtr", "size": 4, "type": "uint" } ] } EXTERNAL 8
E X AM P L E 1 PYTHON SCRIPTING C:\NXP\FreeMASTER 3.0\FreeMASTER Lite\ scripting examples\Python •Install Prerequisites: _>pip install -r requirements.txt •Start Jupyter notebook _>jupyter notebook • Use browser based IDE to interact with the board EXTERNAL 9
E X AM P L E 2 NODEJS SCRIPTING C:\NXP\FreeMASTER 3.0\FreeMASTER Lite\ scripting examples\NodeJS •Install Prerequisites: _>npm install •Start Jupyter notebook _>jupyter notebook • Use browser based IDE to interact with the board EXTERNAL 10
E X AM P L E 3 W E B D AS H B O A R D S EXTERNAL 11
C O D I N G S U M M A RY F R E E M AS T E R - C L I E N T. J S • Include simple-jsonrpc-js.js and freemaster-client.js into your web page • freemaster-client.js functions return a JavaScript Promise that is executed asynchronously freemaster-client.js function resolve result • Sends a JSON-RPC to the back-end .then(function(result) { .catch(function(error) { // process the result // process the error • Returns an async Promise // exit or continue // exit or continue pcm.ReadVariable("x") // with next call // with next call == }) }) new Promise() reject error EXTERNAL 12
C O D I N G S U M M A RY CONNECTING TO THE BOARD • Initialize the PCM object once the page is loaded $(document).ready(function() { pcm = new PCM(“localhost:8090", open_handler, close_handler, error_handler); }); • Connect to the board once the client is connected to the server (inside open_handler) function open_handler() { pcm.StartComm("connection name as set in configuration file") .then((response) => { // proceed with main application logic }) .catch((error) => { // handle the error (board may be not connected or the connection string is wrong) }); }; EXTERNAL 13
C O D I N G S U M M A RY R E AD & W R I T E VAR I A B L E • Read TSA or ELF file to map project variables to their corresponding addresses pcm.ReadVariable("variable_name") pcm.WriteVariable("variable_name", value) .then((response) => { .then((response) => { // process response.data property // response does not carry any data }) }) .catch((error) => { .catch((error) => { // handle the error // handle the error }); }); • Read multiple calls and wait all to return before proceeding further Promise.all([ pcm.ReadVariable("variable_name_1") pcm.ReadVariable("variable_name_2") ]).then((responses) => { // process the array of responses in the same order as the functions were invoked in }) .catch((error) => { // handle the error }); EXTERNAL 14
S H AR E Y O U R F R E E M A S T E R D AS H B O A R D D E S I G N S W I T H T H E N X P C O M M U N I T Y GET A FREE BOARD! Why? To build a robust community of support for FreeMASTER with idea share. How to participate? 1. Submit your idea through June 19, 2020 to the NXP Community, request your board of choice (one of the following: i.MX RT1020 EVK , LPC55S28 development board and S32K144EVB), available on first come, first served basis until quantities are depleted. 2. Once you’ve created your code example, post a brief description and a screenshot of your dashboard along with a ZIPped code to the original blog comment thread. Click here for complete details! EXTERNAL 15
H O W T O C O N T R O L AN D V I S U A L I Z E D ATA F R O M Y O U R E M B E D D E D AP P L I C AT I O N W I T H F R E E M AS T E R | A F O U R - PA R T W E B I N A R S E R I E S • Part 1: Now Available On-Demand | Watch Now > Get to Know the Easy-to-Use FreeMASTER Runtime Debugging Tool – Now Part of MCUXpresso SDK • Part 2: Now Available On-Demand | Watch Now > Tips for Enhancing Embedded Applications with FreeMASTER UI from Various Development Environments like S32DS and Matlab/Simulink • Part 3: Now Available On-Demand | Watch Now > Introduction to FreeMASTER Dashboard Coding Using HTML, JavaScript, ActiveX and JSON-RPC • Part 4: Today Getting Started with FreeMASTER Lite and JSON-RPC Protocol: From Scripting to Visual Dashboards with Python and JavaScript EXTERNAL 16
& EXTERNAL 17
NXP, THE NXP LOGO AND NXP SECURE CONNECTIONS FOR A SMARTER WORLD ARE TRADEMARKS OF NXP B.V. ALL OTHER PRODUCT OR SERVICE NAMES ARE THE PROPERTY OF THEIR RESPECTIVE OWNERS. © 2020 NXP B.V.
You can also read