robertobucher / pysimCoder

Block diagram editor and real time code generator for Python
GNU General Public License v3.0
142 stars 31 forks source link

Feat/tune params window #83

Closed divad4a closed 4 months ago

divad4a commented 4 months ago

Parameter tuning of running models

Adds "tune parameter" capability to pysimcoder. It takes form of a new dialog window available under right mouse click dropdown menu of a block.

Usage

First, tuning needs to be enabled first in SHV menu.

After that, in the tune parameters dialog window a list of block parameters with values taken from broker will be shown. Connection to broker is established during first parametr tuning action. Values used to connect and login to broker are taken from the SHV menu.

If connection fails at some point, a new connection attemp will be established during next parametr tuning action.

Implementation

Pyshiv's SimpleClient is used as a base for the broker connection. This object relies on asyncio and its funcitons are expected to be run from async context. For that a new Thread with event loop is created during scene initialization and every call to the SimpleClient is made via asyncio.run_coroutine_threadsafe.

robertobucher commented 4 months ago

I have some troubles...

I've installed the following packages:

drwxrwxr-x  2 bucher bucher  4096 May 16 17:48 pyshv-0.6.1.dist-info
drwxrwxr-x  5 bucher bucher  4096 May 16 17:48 shv
drwxrwxr-x  2 bucher bucher  4096 May 16 17:48 aioserial-1.3.1.dist-info
drwxrwxr-x  3 bucher bucher  4096 May 16 17:48 aioserial
drwxrwxr-x  2 bucher bucher  4096 May 16 17:48 asyncinotify-4.0.9.dist-info
drwxrwxr-x  3 bucher bucher  4096 May 16 17:48 asyncinotify

With a simple blockdiagra with sinus input connected to gain and to RTPlot, I generated the code with both "Enable SHV protocol" and "Enable tuning over SHV".

Then I started the usual SHV (shvbroker+shvspy), I started the generated application (test) from a shell and I opened the connection to SHV. All till now is ok.

When I try to open the block submenu and I try "Tune parameters" pysimCoder chashes with the following messages:

Connecting to broker...
Connection to SHV broker:  tcp://admin@127.0.0.1:3755?password=admin%21123
Connected to broker.
Traceback (most recent call last):
  File "/home/bucher/CACSD/pysimCoder/toolbox/supsisim/supsisim/editor.py", line 236, in shvAction
    if not connection.isConnected():
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/bucher/CACSD/pysimCoder/toolbox/supsisim/supsisim/client.py", line 133, in isConnected
    return asyncio.run_coroutine_threadsafe(_is_connected(self.client), self.asyncio_loop).result()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/home/bucher/CACSD/pysimCoder/toolbox/supsisim/supsisim/client.py", line 53, in _is_connected
    return client.client.connected()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'bool' object is not callable

What I do wrong? Thanks in advance!