我正在尝试使用上面的代码连接到某个路由器而我正在使用juniperj2320.py模块并且在测试文件中我有 我正在使用此http://subversion.assembla.com/svn/clauzsistel08/trunk/dist/
的代码库#!/usr/bin/python
from localconf import *
from juniperj2320 import *
import sys
import traceback
SERIALDEVICE = '/dev/ttyUSB0'
# Now configure the router
try:
router = JuniperJ2320(SERIALDEVICE)
except RouterConfigurationException, err:
print "Router configuration error: ", err
print "Please try again."
sys.exit(1)
但是我遇到了以下错误
./test.py > /root/pyserial-2.6/examples/serialrouter.py(37)__init__() -> serial.Serial.__init__(self, serialdevice, baudrate=baudrate, \ (Pdb) c Traceback (most recent call last): File "./test.py", line 30, in router = JuniperJ2320(SERIALDEVICE) File "/root/pyserial-2.6/examples/juniperj2320.py", line 32, in __init__ BYTESIZE, PARITY, STOPBITS, TIMEOUT) File "/root/pyserial-2.6/examples/serialrouter.py", line 44, in __init__ fdpexpect.fdspawn.__init__(self, self.fileno()) File "/usr/lib/python2.6/site-packages/fdpexpect.py", line 40, in __init__ spawn.__init__(self, None, args, timeout, maxread, searchwindowsize, logfile ) File "/usr/lib/python2.6/site-packages/pexpect.py", line 412, in __init__ self.closed = True # File-like object. AttributeError: can't set attribute
并且绝对不知道在这里发生了什么!任何帮助将不胜感激
谢谢
答案 0 :(得分:0)
这是一个黑暗的镜头,因为我不熟悉你正在使用的模块,但基于回溯,它看起来像构造函数期待一个类似文件的对象,而不仅仅是文件路径。试试这个。
SERIALDEVICE = '/dev/ttyUSB0'
# Now configure the router
try:
router = JuniperJ2320(open(SERIALDEVICE))
答案 1 :(得分:0)
不是编写自己的串行通信程序就不会更容易让pexpect驱动像minicom这样的串行程序吗?