Question

I am trying to connect Modelica and Python using the Python27 block, provided by the Berkeley Simulations Lab:

http://simulationresearch.lbl.gov/modelica

I use this block to call a Python function:

    def Test2(WriteValues):
        ''' Connection Test - Works if started from Dymola
        '''
        #Doing nothing and returning the input
        ReturnList=WriteValues
        return (ReturnList)

works perfectly.

Now I need to import some modules

    #Importing Python modules works in general
    import sys
    import thread
    import time

works aswell

Only now I want to import a module that is not part of Python but a site-package:

    def Test1(WriteValues):
    '''Connection Test - Doesnt work if started from Dymola
    '''
    #Importing some Bacpypes Module
    #Path is by default C:\Python27\Lib\site-packages\BACpypes-0.7-py2.7.egg\bacpypes
    #My os is win7
    from bacpypes.core import run
    #Doing nothing and returning the input
    ReturnList=WriteValues
    return (ReturnList)

This does not work. It does not matter if I import the BACpypes module inside a function or globally - the error is always

    'module' object has no attribute 'argv'

Colleagues pointed me to the idea that it might be related to a multiple import problem. The function is being called by Modelica every 10 seconds (real-time-simualtion).

If I call the function Test1 outside of Modelica, there is no problem. It only fails using the Python27 block!

Does anyone have an idea about how to make the BACpypes import work?

UPDATE 2013-10-16:

I printed out the value of sys.argv for the script excecution in the Python directory and an excecution from Modelica.

sys.argv from Python directory:

    ['C:\\Python27\\Testcon.py']

sys.argv if function is called from inside Modelica:

    ['modpython']

Might this in any way be related to the error message I get?

Was it helpful?

Solution

The bug is caused because bacpypes uses sys.argv but the Python interpreter did not call PySys_SetArgv.

This will be fixed in the next version of the Modelica Buildings library, see https://github.com/lbl-srg/modelica-buildings/issues/191

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top