0

I am trying to connect to some router using the above code and I am using juniperj2320.py module and in test file I have am using code base from this 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)

but am getting this following error

    ./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

and absolutely clue less on wat happening here ! any help ll be greatly appreciated

thanks

0

2 Answers 2

0

This is a little bit of a shot in the dark, because I'm not familiar with the modules you're using, but based on the traceback, it looks like the constructor is expecting a file-like object, not just a file path. Try this instead.

SERIALDEVICE = '/dev/ttyUSB0'

# Now configure the router
try:
    router = JuniperJ2320(open(SERIALDEVICE))
Sign up to request clarification or add additional context in comments.

Comments

0

Instead of writing your own serial communications program wouldn't be easier to have pexpect drive a serial program like minicom?

1 Comment

I think we can not use pexpect to drive the minicom one can use runscript for that purpose with the minicom ... i tried using pexpect and pyserial but some tiems pexpect is not giving me the expected results ! so have written my own while loop waits.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.