FreeMASTER Lite Tutorial & Example Code Issue - Jupyter Notebook #1328826

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FreeMASTER Lite Tutorial & Example Code Issue - Jupyter Notebook #1328826

Jump to solution
766 Views
CY9
Contributor III
First of all,
I am trying to run FreeMaster Example code of Jupyter Notebook for NodeJS: 
installed on `C:\NXP\FreeMASTER 3.2\FreeMASTER Lite\scripting examples\NodeJS\FML_NodeJS.ipynb`
But the code seems like Javascript , not Python !?
 
So, Should I install JavaScipr Kernel before running this example ?
Which JavaScript Kernel should I install ?
1. IJavascript , 2. jp-kerne, 3. NeluKernelu, 4. TSLab, or others ?
Is it passible to write it into README.md file ?
 
--
 
And,  for python code on Jupyter 

I am having similar issue with This Page.

Fail on Win11 platform and S32K144 uC.
Is there anything I am missing ?.
Thank you.

 

 

data = await SendRequest(ws, 'GetDetectedBoardInfo')
## print('Detected board info: ' + data)  ## Error: TypeError: can only concatenate str (not "dict") to str
print('Detected board info: ')
print(data)​

 

 

 

Detected board info:
{'protVer': 3, 'cfgFlags': 0, 'dataBusWdt': 1, 'globVerMajor': 2, 'globVerMinor': 0, 'cmdBuffSize': 60, 'recBuffSize': 512, 'recTimeBase': 16384, 'descr': [83, 51, 50, 120, 120, 32, 70, 114, 101, 101, 77, 65, 83, 84, 69, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0]}
 
'protVer'=3
Is this meaning my protocol version=3?

 

for param=`GetDetectedBoardInfo` work fine.

but... 

--

 

 

data = await SendRequest(ws, 'GetConfigParamString', "VS", 20)
print('Application version: ' + data)

 

 

 


---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[11], line 1
----> 1 data = await SendRequest(ws, 'GetConfigParamString', "VS", 20)
      2 print('Application version: ' + data)
Cell In[5], line 9, in SendRequest(ws, method, *args)
      7         return response.result['data']
      8     else:
----> 9         raise Exception(response.result['error'])
     10 else:
     11     raise Exception(response.message)
Exception: {'code': 2147483923, 'message': 'This feature is only available on devices supporting protocol v4 and later.'}
Query application name.
Note: this API endpoint was added in protocol version 4. For older versions use GetDetectedBoardInfo.
 

 

「...was added in `protocol version 4`」
? but my 'protVer'=3?

 

 
Basically, all `GetConfigParamString` cause exception.
 
Should I remark all `GetConfigParamString` code ?

So, how to upgrade to protocol version 4 ?  on uC? on Win11? 
 
 
0 Kudos
Reply
1 Solution
649 Views
iulian_stan
NXP Employee
NXP Employee

Hi @CY9,

I was able to reproduce your issue - it was related to the variable definition:

var variable = {
    'name': 'adcMeanValue',
    'addr': 'adcMeanValue', <-- this is a symbol name
    'type': 'uint',
    'size': 4
}

FreeMASTER Lite fails to resolve 'adcMeanValue' to an actual address because there is no symbolic information loaded. Eventually it fails due to type mismatch - read operation expects a numeric number but is receives a string (we will fix this behavior in next release).

To fix this issue you have the following options:

  1. Define the symbol in TSA (in the embedded application)
    FMSTR_TSA_TABLE_BEGIN(my_tsa_table)
        FMSTR_TSA_RW_VAR(adcMeanValue, FMSTR_TSA_UINT32)
    FMSTR_TSA_TABLE_END()
    
    FMSTR_TSA_TABLE_LIST_BEGIN()
        FMSTR_TSA_TABLE(my_tsa_table)
    FMSTR_TSA_TABLE_LIST_END()
    ​

    and enable TSA feature in freemaster_cfg.h

    #define FMSTR_USE_TSA           1   // Enable TSA functionality​

    After this the call to 'ReadTSA' from Jupyter notebook should return 1 symbol.

  2. Replace 'ReadTSA' with 'ReadELF'
    var count = 0;
    SendRequest(jrpc, 'ReadELF', ['path to the elf file']).then(data => {
        console.log('Parsed TSA contained ' + data.count + ' symbols.');
        count = parseInt(data.count);
    });​

    Note: after either of the above functions you should be able to find `adcMeanValue` among parsed symbols:

    for (var i = 0; i < count; ++i) {
        SendRequest(jrpc, 'EnumSymbols', [i]).then(data => console.log(data));
    }​
  3. Define the variable using a numeric value:
    var variable = {
        'name': 'adcMeanValue',
        'addr': 0x2000abcd, // this value can be found in the .map file produced by the compiler
        'type': 'uint',
        'size': 4
    }
    SendRequest(jrpc, 'DefineVariable', [variable])
      .then(() => console.log('Variable defined successfully.'))
      .catch(err => console.error(err.message));​

Regarding the the socket connection - due to asynchronous nature of the communication you need to wait for the socket to connect before sending FreeMASTER commands.

Hope it helps,
Iulian

 

View solution in original post

0 Kudos
Reply
7 Replies
749 Views
iulian_stan
NXP Employee
NXP Employee

Hi @CY9,

FreeMASTER Lite includes separate examples for Python and NodeJS. Note that, functionality-wise, they are identical.

The one you are referring to does use JavaScript as programming language. For Python, please refer to the Jupyter notebook from `scripting examples\Python` directory.

JavaScript kernel - if you ran the `npm install` command as specified in README IJavascript should have been already installed on your workstation. (we will add these details in the README).

Protocol version error - 'protVer': 3, means that FreeMASTER Driver running on MCU is using protocol version 3 (which is currently the latest one available for S32K1). It does not mean that there are any issues with your application. It means that some new functions introduced in protocol version 4 will not be available - core FreeMASTER functionality is there so you can still monitor & control the embedded application. Additionally, FreeMASTER (desktop tool) is fully backward compatible with older version of the protocol running on the MCU.

Hope it helps,
Iulian

0 Kudos
Reply
715 Views
CY9
Contributor III

fully backward compatible with older version of the protocol

?

But, if I didn't remark all `GetConfigParamString` related code : 

FreeMasterJupyterPythonException.png

 

The Jupyter will not executed aby more !!

 

 

0 Kudos
Reply
704 Views
iulian_stan
NXP Employee
NXP Employee

Backward compatibility means that newer version of the tool supports older API interfaces or converts the API call to an older format if there is a compatible function.

In case the new additions to the API that have no compatible functions in the old API a corresponding error  is returned. 

We added notes to the affected Jupyter cells:

Note: this API endpoint was added in protocol version 4. For older versions use GetDetectedBoardInfo.

0 Kudos
Reply
718 Views
CY9
Contributor III

Dear iulian_stan,

 

 

(base) C:\Users\%UserNAme%\Documents\FreeMASTER Lite\scripting examples\NodeJS> npm i

> freemaster-jsonrpc-api@1.0.0 postinstall
> npm i -g ijavascript && ijsinstall

npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN cleanup Failed to remove some directories [
npm WARN cleanup [
npm WARN cleanup 'C:\\ProgramData\\anaconda3\\node_modules\\.ijavascript-P4cT8Jzn',
npm WARN cleanup [Error: EPERM: operation not permitted, unlink 'C:\ProgramData\anaconda3\node_modules\.ijavascript-P4cT8Jzn\node_modules\zeromq\prebuilds\win32-x64\node.abi108.node'] {
npm WARN cleanup errno: -4048,
npm WARN cleanup code: 'EPERM',
npm WARN cleanup syscall: 'unlink',
npm WARN cleanup path: 'C:\\ProgramData\\anaconda3\\node_modules\\.ijavascript-P4cT8Jzn\\node_modules\\zeromq\\prebuilds\\win32-x64\\node.abi108.node'
npm WARN cleanup }
npm WARN cleanup ]
npm WARN cleanup ]

changed 8 packages in 1s

up to date, audited 4 packages in 7s

1 package is looking for funding
run `npm fund` for details

found 0 vulnerabilities

(base) C:\Users\%UserName%\Documents\FreeMASTER Lite\scripting examples\NodeJS>npm fund
freemaster-jsonrpc-api@1.0.0
`-- https://github.com/sponsors/broofa
`-- uuid@10.0.0

 

 

 

After running `jupyter notebook` :

 

 

 

SendRequest(jrpc,'StopComm')
  .then(() => console.log('Communication stopped'))
  .catch(err => console.error(err.message));

 

 

Promise { <pending> }
 
Parsed TSA contained 0 symbols.
Variable defined successfully.
{
  name: 'adcMeanValue',
  addr: 'adcMeanValue',
  type: 'uint',
  size: 4,
  alias: 'adcMeanValue',
  baseType: { size: 4, indirection: 1, alignment: 4, name: 'uint32' }
}
{
  code: -32603,
  message: 'Internal error. Internal JSON-RPC error.',
  data: 'writeUInt64: no digits we found in input String'
}
{
  code: -32603,
  message: 'Internal error. Internal JSON-RPC error.',
  data: 'writeUInt64: no digits we found in input String'
}
{
  code: -32603,
  message: 'Internal error. Internal JSON-RPC error.',
  data: 'writeUInt64: no digits we found in input String'
}
Communication stopped

 

but I can NOT find anything define `writeUInt64` in the NodeJS code ?

 

0 Kudos
Reply
706 Views
iulian_stan
NXP Employee
NXP Employee

Hi @CY9,

From the provided output I can assume the you perform the following:

  1. Read TSA table, but it returns 0 symbols, meaning you dot use TSA (Table Side Addressing) in your embedded application. 
  2. Define `adcMeanValue` variable. There's a potential issue in the definition because you are using a symbol name in the `addr` field, but there are no symbols loaded so FreeMASTER won't be able to resolve the variable address.
  3. In the next step I am not sure what call you perform. I can assume that you want to read a 64 bit unsigned variable. If so, your call should look like this:
    SendRequest(jrpc, 'WriteVariable', ['adcMeanValue', 100])
      .then(data => console.log(data))
      .catch(err => console.error(err.message));​​

    Where :
    'adcMeanValue' is the variable defined in the previous step
    100 is the value to be written

     

     

    another options is
    SendRequest(jrpc, 'WriteUIntVariable', [0x200004cc, 4, 100])
      .then(data => console.log(data))
      .catch(err => console.error(err.message));​
    Where 
    0x200004cc is the address, (can be symbol name, but in this case it should be loaded either via ReadTSA or ReadElf
    4 is the size
    100 is the value

Could you share the code that produced the 

data: 'writeUInt64: no digits we found in input String'   

error so I can better understand the issue ?

0 Kudos
Reply
668 Views
CY9
Contributor III

Dear iulian_stan, 

Please reference attachment

 

The strange thing is that readyState is NOT CONNECTED(OPEN), but CONNECTING.

WebSocket is not open: readyState 0 (CONNECTING)

 

Should it delay/wait until the `readyState` is OPEN ?

 

 

 

0 Kudos
Reply
650 Views
iulian_stan
NXP Employee
NXP Employee

Hi @CY9,

I was able to reproduce your issue - it was related to the variable definition:

var variable = {
    'name': 'adcMeanValue',
    'addr': 'adcMeanValue', <-- this is a symbol name
    'type': 'uint',
    'size': 4
}

FreeMASTER Lite fails to resolve 'adcMeanValue' to an actual address because there is no symbolic information loaded. Eventually it fails due to type mismatch - read operation expects a numeric number but is receives a string (we will fix this behavior in next release).

To fix this issue you have the following options:

  1. Define the symbol in TSA (in the embedded application)
    FMSTR_TSA_TABLE_BEGIN(my_tsa_table)
        FMSTR_TSA_RW_VAR(adcMeanValue, FMSTR_TSA_UINT32)
    FMSTR_TSA_TABLE_END()
    
    FMSTR_TSA_TABLE_LIST_BEGIN()
        FMSTR_TSA_TABLE(my_tsa_table)
    FMSTR_TSA_TABLE_LIST_END()
    ​

    and enable TSA feature in freemaster_cfg.h

    #define FMSTR_USE_TSA           1   // Enable TSA functionality​

    After this the call to 'ReadTSA' from Jupyter notebook should return 1 symbol.

  2. Replace 'ReadTSA' with 'ReadELF'
    var count = 0;
    SendRequest(jrpc, 'ReadELF', ['path to the elf file']).then(data => {
        console.log('Parsed TSA contained ' + data.count + ' symbols.');
        count = parseInt(data.count);
    });​

    Note: after either of the above functions you should be able to find `adcMeanValue` among parsed symbols:

    for (var i = 0; i < count; ++i) {
        SendRequest(jrpc, 'EnumSymbols', [i]).then(data => console.log(data));
    }​
  3. Define the variable using a numeric value:
    var variable = {
        'name': 'adcMeanValue',
        'addr': 0x2000abcd, // this value can be found in the .map file produced by the compiler
        'type': 'uint',
        'size': 4
    }
    SendRequest(jrpc, 'DefineVariable', [variable])
      .then(() => console.log('Variable defined successfully.'))
      .catch(err => console.error(err.message));​

Regarding the the socket connection - due to asynchronous nature of the communication you need to wait for the socket to connect before sending FreeMASTER commands.

Hope it helps,
Iulian

 

0 Kudos
Reply