Menu

Python 2.7 and 3 discrepancies/integration

Developers
2021-04-21
2022-11-25
  • Gabe Mestas

    Gabe Mestas - 2021-04-21

    Hi Percy, and all,

    My group is interested in controlling GXSM with external python scripts. If anyone is familiar with running Python 2.7 to control GXSM through Spyder for hardware control and data acquisition, what are potential solutions for maintaining both Python 2.7 and Python 3 in parallel, perhaps with having two separate versions of Spyder? We use Ubuntu Mint, latest download.

    Thanks,

    Gabe Mestas

     
  • Percy Zahl

    Percy Zahl - 2021-04-22

    Hi Gabe,

    I never heard about Spyder, looked it up and seams only a "IDE" -- is that right. I assume it is working with python3.7 or 3.8 as well ? Is there any reason you depend still on the outdated 2.7?

    Regarding Gxsm and Python control -- as I am using a embedded python interpretor the script has to be executed via the Gxsm python console as a Gxsm sub process.

    You can import and use any python support libs like numpy, etc. -- you can even open via mathplotlib a plot but giving the focus to it will BLOCK Gxsm until it terminated and there may be conditions of unexpected behaviors when using 2nd level GUIs (not recommended)/process controls. Try. But any calculations, or other device access shall be just fine. Also GXSM provides simple in/output GUI options for python.

    So you could create your script using the Spyder IDE, but need to save and execute it inside GXSM.

    Any gxsm.set()/.... (embedded interpretor registered gxsm control commands) are ONLY accessible in the main script executed in the gxsm console. The only way to separate code to other files is using the gxsm python special "inline" command.

    However, there is currently one way to externally connect to GXSM python remote control commands via a network based socket server/client interface.

    For this you simple start a python based "socket sever" in the gxsm remote console.
    This listens to the socket.

    On the other side you have to implement a socket client (can be any language). I have a basic server/client written in python:

    This bride then allows to run the client in any python flavor version or even any other language -- all you need is the socket functionality. This then includes simple access via Ethernet as well! The socket server currently provides the most basic commands, but can be easy extended to anything you need...

    See the socket server/client example scripts (string vis gxsm python console):

    https://sourceforge.net/p/gxsm/svn/HEAD/tree/trunk/Gxsm-3.0/plug-ins/common/gxsm-sok-server.py

    and this client example (python3, but you can easy port this to any version, strip the KERAS based AI stuff) -- it includes the client python code/class beside some other code currently work in progress. This is a attempt to create a GXSM instance independent more basic scan controller with future AI based intelligence.... stay tuned.

    https://sourceforge.net/p/gxsm/svn/HEAD/tree/trunk/Gxsm-3.0/plug-ins/common/gxsm-scan-image-viewer-sok-client.py

    I hope this helps.
    -Percy

     
    • Huey

      Huey - 2022-11-25

      Hi Percy,

      I read the code of socket sever gxsm-sok-server.py, which starts scanning by calling gxsm.startscan(), but it seems the client does not get the image after scanning. Is it possible to transfer the image data to the client by the server? what kind of gxsm functions should I use to implement transfering of image data?

      Thank you in advance!
      Huey

       
      • Percy Zahl

        Percy Zahl - 2022-11-25

        after issuing start scan it does NOT block or wait for it to complete. Thus:

        Have a look at the counter part demo -- the external python client program.

        You can send a command to trigger a data update into the assigned files name and query the file name/path. Then read the data scanned to that moment) from file! Thus been able to watch the data coming in.

        You can also query the current scan line / status to find out about completion.

        Anyhow, there are gxsm python commands to transfer scan/image data to a python / numpy array. However, the currently implemented server does NOT bridge those functions. But feel free to implement / add if needed and you may not have access to the local file system.

         

Log in to post a comment.