0

私は、JTAG コネクタと OpenOCD サーバーとのボード接続をテストするプロジェクトに取り組んでいます。

コーディングした接続クラスは次のとおりです。単純に pexpect を使用しています。

"""
Communication with embedded board
"""
import sys 
import time
import threading
import Queue

import pexpect
import serial
import fdpexpect

from pexpect import EOF, TIMEOUT


class ModTelnet():
    def __init__(self):    

        self.is_running = False
        self.HOST = 'localhost'
        self.port = '4444'

    def receive(self):
        #receive data (= msg) from telnet stdout
        data = [ EOF, TIMEOUT, '>' ]
        index = self._tn.expect(data, 2)
        if index == 0:
            return 'eof', None
        elif index == 1:
            return 'timeout', None
        elif index == 2:
            print 'success', self._tn.before.split('\r\n')[1:]
            return 'success',self._tn.before

    def send(self, command):
        print 'sending command: ', command
        self._tn.sendline(command)


    def stop(self):
        print 'Connection stopped !'
        self._ocd.sendcontrol('c')

    def connect(self):
        #connect to MODIMX27 with JTAG and OpenOCD
        self.is_running = True
        password = 'xxxx'
        myfile = 'openocd.cfg'
        self._ocd = pexpect.spawn('sudo openocd -f %s' % (myfile))
        i = self._ocd.expect(['password', EOF, TIMEOUT])
        if i == 0:
            self._ocd.sendline(password)
            time.sleep(1.0)
            self._connect_to_tn()
        elif i == 1:
            print ' *** OCD Connection failed *** '
            raise Disconnected()
        elif i == 2:
            print ' *** OCD Connection timeout *** '
            raise Timeout()  

    def _connect_to_tn(self):
         #connect to telnet session @ localhost port 4444
         self._tn = pexpect.spawn('telnet %s %s' % (self.HOST, self.port))
         condition = self._tn.expect(['>', EOF, TIMEOUT])
         if condition == 0:
            print 'Telnet opened with success'
         elif condition == 1:
            print self._tn.before
            raise Disconnected()
         elif condition == 2: 
            print self._tn.before
            raise Timeout()

if __name__ =='__main__':
    try:
        tn = ModTelnet()
        tn.connect()   
    except :
            print 'Cannot connect to board!'
            exit(0)

問題は、これを行う他のモジュールで送信、受信、および停止コマンドを使用しようとしているときです:

    >>> from OCDConnect import *
>>> import time

>>> tn = ModTelnet()
>>> tn.connect()
Telnet opened with success

>>> time.sleep(2.0)
>>> self.send('soft_reset_halt')
MMU: disabled, D-Cache: disabled, I-Cache: disabled

>>> self.stop()

「ModTelnet has no send attribute」のようなエラーが表示されます。これを修正するにはどうすればよいですか??

助けてくれてありがとう!

4

2 に答える 2

0

問題は私のクラス定義の構文でした:

class ModTelnet:

そしてそうではありません:

class ModTelnet():

私は他のクラスから継承していないので、これは役に立たない... :D

とにかくありがとう !

于 2011-05-12T05:25:56.947 に答える
0

試す

'send' in dir(tn)

False の場合は、send メソッドが実装されていません。

于 2011-05-10T18:06:20.143 に答える