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에 보내기 속성이 없습니다" 어떻게 해결할 수 있습니까 ??
도움 주셔서 감사합니다.
'tn.send' 및'tn.stop'이 아니어야합니까? – 6502
예, 죄송하지만 더 이상 작동하지 않습니다. 내 수업 ModTelnet을 유효한 파이썬 구문으로 만들려면 어떻게해야합니까? – user732663
구문에 대한 내 (삭제 된) 주석을 무시하십시오. 나는 오래된 파이썬 버전을보고 있었다. 진흙탕에 유감스럽게 생각합니다. – slowdog