2016-04-17 144 views
1

私はまだPythonと計測器制御の新人ですが、私はまだ答えを見つけることができなかったいくつかの問題に直面しています。 私はPyvisaを使用してrs232を介してモノクロメーター(Spectral Products dk240)を制御しています。 (Python 3.5、PyVisa 1.8)PyVisa読み取りタイムアウト

コマンドを記述し、正しい終了文字を設定することで応答を読み取ることができます。問題は、計測器の応答が終了せずに1バイトであることがあり、タイムアウトが発生することです(ポートモニタで必要な応答が表示されているにもかかわらず)。

私はread_rawを使用して1バイトを取得しようとしましたが、動作しません。 ここに私のコードのシンプルなバージョンです:

import pyvisa 
rm = pyvisa.ResourceManager() 
instrument = rm.open_resource('ASRL1::INSTR') 
instrument.baud_rate= 9600 
instrument.data_bits=8 
instrument.stop_bits = pyvisa.constants.StopBits.one 
instrument.parity = pyvisa.constants.Parity.none 
instrument.read_termination = chr(24) #specified in the manual 

instrument.write(chr(33)) # command to get the serial number 
instrument.read()   # this works! 

instrument.write(chr(27)) # echo command 
          # instrument replies one byte echo (seen on port monitor) 
instrument.read_raw(1)  # I get a timeout here 

とエラー:

raise errors.VisaIOError(ret_value) 
pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed. 

私も「なし」に終端文字を設定しようとしましたので、ビザがそれを待たないだろうが、まだはタイムアウトを取得します。 さらに、私はread_raw(1)でシリアル番号を読み取ろうとしましたが、1バイトではなく、楽器から完全な答えを得るのはなぜですか?

何か助けていただければ幸いです!

答えて

1

これはおそらく少し遅いですが、私はこの問題がbytes_in_buffer属性に依存する独自の関数で発生している間に助けてくれました。

def read_all(devicehandle): 

    with devicehandle.ignore_warning(constants.VI_SUCCESS_DEV_NPRESENT, constants.VI_SUCCESS_MAX_CNT): 

     try: 
      data , status = devicehandle.visalib.read(devicehandle.session, devicehandle.bytes_in_buffer) 
     except: 
      pass 
    return data 

備考:イーサネット接続では機能しません。属性は存在しません。

関連する問題