2011-05-10 3 views
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) 

나는 전송을 사용 받고이 일을 ohter 모듈에 명령을 중지하기 위해 노력하고있어 때 문제는 다음과 같습니다

>>> 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에 보내기 속성이 없습니다" 어떻게 해결할 수 있습니까 ??

도움 주셔서 감사합니다.

+3

'tn.send' 및'tn.stop'이 아니어야합니까? – 6502

+0

예, 죄송하지만 더 이상 작동하지 않습니다. 내 수업 ModTelnet을 유효한 파이썬 구문으로 만들려면 어떻게해야합니까? – user732663

+0

구문에 대한 내 (삭제 된) 주석을 무시하십시오. 나는 오래된 파이썬 버전을보고 있었다. 진흙탕에 유감스럽게 생각합니다. – slowdog

답변

0

은 거짓 인 경우

'send' in dir(tn) 

, 당신은 send 메소드를 구현하지 않은 시도. 내가 다른 클래스에서 상속하지 않기 때문에

class ModTelnet(): 

느릅 나무는 쓸모가 ... : :

class ModTelnet: 

그리고하지 :

+0

오키 감사합니다. 내일 시험해 보겠습니다. 집에서 나와 함께 보드를 가지고 있지 않습니다! – user732663

0

문제는 내 클래스 정의의 구문이었다 D

어쨌든 고마워!