2

Berkeley Simulations Lab が提供する Python27 ブロックを使用して、Modelica と Python を接続しようとしています。

http://simulationresearch.lbl.gov/modelica

このブロックを使用して Python 関数を呼び出します。

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

完璧に動作します。

ここで、いくつかのモジュールをインポートする必要があります

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

同様に動作します

Python の一部ではなく、サイト パッケージであるモジュールをインポートしたいのは今だけです。

    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)

これは動作しません。関数内またはグローバルに BACpypes モジュールをインポートするかどうかは問題ではありません - エラーは常に

    'module' object has no attribute 'argv'

同僚は、それが複数のインポートの問題に関連している可能性があるという考えを私に指摘しました。この関数は、Modelica によって 10 秒ごとに呼び出されています (リアルタイム シミュレーション)。

Test1 関数を Modelica の外で呼び出しても問題ありません。Python27 ブロックを使用した場合にのみ失敗します!

BACpypes のインポートを機能させる方法を知っている人はいますか?

2013 年 10 月 16 日更新:

Python ディレクトリでのスクリプト実行と Modelica からの実行の sys.argv の値を出力しました。

Python ディレクトリの sys.argv:

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

関数が Modelica 内部から呼び出された場合の sys.argv:

    ['modpython']

これは、私が受け取ったエラーメッセージに何らかの形で関連している可能性がありますか?

4

1 に答える 1