I am new to scripting. I am trying to read the settings from a serial
device using Python. I have been able to successfully connect to the
device and change baud rate settings, ect... with PySerial. I am
trying to send a command to the serial device and capture the returned
info, however, it is not working. Code is below:
import serial
import time
s = serial.Serial(port=1, timeout=None, baudrate=9600)
print s
time.sleep(5)
print "Enter CFG"
s.write('CFG')
print "Change baud"
s.baudrate=115200
print s
time.sleep(5)
print "New line"
s.write('\n')
time.sleep(2)
print "Show Encryption Setting"
nw = s.write('sh nw enc')
time.sleep(1)
print nw
s.close()
Thanks
B 6 4532
On 2008-10-10, brianrpsgt1 <br*******@cox.netwrote:
I am new to scripting. I am trying to read the settings from a serial
device using Python. I have been able to successfully connect to the
device and change baud rate settings, ect... with PySerial. I am
trying to send a command to the serial device and capture the returned
info, however, it is not working.
It works fine for me.
I'm afraid you're going to have to be a bit more detailed than
"it is not working". Are we supposed to guess what it's doing
and how that differs from what you want it to do?
Do you have the serial cable plugged in?
Is the device to which you're talking powered on?
Code is below:
import serial
import time
s = serial.Serial(port=1, timeout=None, baudrate=9600)
print s
time.sleep(5)
print "Enter CFG"
s.write('CFG')
print "Change baud"
s.baudrate=115200
print s
time.sleep(5)
print "New line"
s.write('\n')
time.sleep(2)
print "Show Encryption Setting"
nw = s.write('sh nw enc')
time.sleep(1)
print nw
s.close()
--
Grant Edwards grante Yow! Well, I'm INVISIBLE
at AGAIN ... I might as well
visi.com pay a visit to the LADIES
ROOM ...
Thanks for the message
What exactly is happening is that the return is "None" for the command
that I am sending. If I connect through Hyperterminal and execute the
'sh nw enc' command, it returns 'WEP'
I have confirmed that the serial port is correct and open with the
s.isOpen() function. Also able to successfully connect in
Hypterterminal with the same configuration settings.
Grant Edwards wrote:
On 2008-10-10, brianrpsgt1 <br*******@cox.netwrote:
I am new to scripting. I am trying to read the settings from a serial
device using Python. I have been able to successfully connect to the
device and change baud rate settings, ect... with PySerial. I am
trying to send a command to the serial device and capture the returned
info, however, it is not working.
It works fine for me.
I'm afraid you're going to have to be a bit more detailed than
"it is not working". Are we supposed to guess what it's doing
and how that differs from what you want it to do?
Do you have the serial cable plugged in?
Is the device to which you're talking powered on?
Code is below:
import serial
import time
s = serial.Serial(port=1, timeout=None, baudrate=9600)
print s
time.sleep(5)
print "Enter CFG"
s.write('CFG')
print "Change baud"
s.baudrate=115200
print s
time.sleep(5)
print "New line"
s.write('\n')
time.sleep(2)
print "Show Encryption Setting"
nw = s.write('sh nw enc')
time.sleep(1)
print nw
s.close()
--
Grant Edwards grante Yow! Well, I'm INVISIBLE
at AGAIN ... I might as well
visi.com pay a visit to the LADIES
ROOM ...
On 2008-10-10, brianrpsgt1 <br*******@cox.netwrote:
Thanks for the message
What exactly is happening is that the return is "None" for the command
that I am sending. If I connect through Hyperterminal and execute the
'sh nw enc' command, it returns 'WEP'
It looks to me like you're never reading from the serial port.
All you're calling is write().
Also, are you sure that the device doesn't expect commands to
be termined by carriage returns?
import serial
import time
s = serial.Serial(port=1, timeout=None, baudrate=9600)
print s
time.sleep(5)
print "Enter CFG"
s.write('CFG')
print "Change baud"
s.baudrate=115200
print s
time.sleep(5)
print "New line"
s.write('\n')
time.sleep(2)
print "Show Encryption Setting"
nw = s.write('sh nw enc')
time.sleep(1)
Try changing that to
s.write('sh nw enc')
time.sleep(1)
nw = s.read(1024)
print nw
s.close()
There are plenty of example programs at: http://pyserial.svn.sourceforge.net/...rial/examples/
--
Grant Edwards grante Yow!
at BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-
visi.com
Gave that a shot.... what is happening is that the script is
hanging. Does that mean that the write function is not making it
through, thus there is nothing to return?
Grant Edwards wrote:
On 2008-10-10, brianrpsgt1 <br*******@cox.netwrote:
Thanks for the message
What exactly is happening is that the return is "None" for the command
that I am sending. If I connect through Hyperterminal and execute the
'sh nw enc' command, it returns 'WEP'
It looks to me like you're never reading from the serial port.
All you're calling is write().
Also, are you sure that the device doesn't expect commands to
be termined by carriage returns?
import serial
import time
s = serial.Serial(port=1, timeout=None, baudrate=9600)
print s
time.sleep(5)
print "Enter CFG"
s.write('CFG')
print "Change baud"
s.baudrate=115200
print s
time.sleep(5)
print "New line"
s.write('\n')
time.sleep(2)
print "Show Encryption Setting"
nw = s.write('sh nw enc')
time.sleep(1)
Try changing that to
s.write('sh nw enc')
time.sleep(1)
nw = s.read(1024)
print nw
s.close()
There are plenty of example programs at:
http://pyserial.svn.sourceforge.net/...rial/examples/
--
Grant Edwards grante Yow!
at BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-
visi.com
Again, what is weird is that all works fine in Hyperterminal, but not
with the Python script.
brianrpsgt1 wrote:
Gave that a shot.... what is happening is that the script is
hanging. Does that mean that the write function is not making it
through, thus there is nothing to return?
Grant Edwards wrote:
On 2008-10-10, brianrpsgt1 <br*******@cox.netwrote:
Thanks for the message
>
What exactly is happening is that the return is "None" for the command
that I am sending. If I connect through Hyperterminal and execute the
'sh nw enc' command, it returns 'WEP'
It looks to me like you're never reading from the serial port.
All you're calling is write().
Also, are you sure that the device doesn't expect commands to
be termined by carriage returns?
import serial
import time
>
s = serial.Serial(port=1, timeout=None, baudrate=9600)
print s
time.sleep(5)
print "Enter CFG"
s.write('CFG')
print "Change baud"
s.baudrate=115200
print s
time.sleep(5)
print "New line"
s.write('\n')
>
>
time.sleep(2)
print "Show Encryption Setting"
nw = s.write('sh nw enc')
time.sleep(1)
Try changing that to
s.write('sh nw enc')
time.sleep(1)
nw = s.read(1024)
print nw
s.close()
There are plenty of example programs at: http://pyserial.svn.sourceforge.net/...rial/examples/
--
Grant Edwards grante Yow!
at BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-
visi.com
That did it! The fix was the '\r'
Thanks for the assistance Dennis and Grant!
Dennis Lee Bieber wrote:
On Fri, 10 Oct 2008 15:40:08 -0700 (PDT), brianrpsgt1
<br*******@cox.netdeclaimed the following in comp.lang.python:
Again, what is weird is that all works fine in Hyperterminal, but not
with the Python script.
And are you hitting the return key when using Hyperterminal?
Try changing that to
s.write('sh nw enc')
s.write("sh nw enc\r") #presuming you have to hit the return key in
Hyperterminal
You may also want to configure the serial port with a read timeout
--
Wulfraed Dennis Lee Bieber KD6MOG wl*****@ix.netcom.com wu******@bestiaria.com HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com) HTTP://www.bestiaria.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gavin |
last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other
groups in a hope to get a response from anyone.
Can any one tell me how...
|
by: jas |
last post by:
Hi,
I would like to start a new process and be able to read/write from/to
it. I have tried things like...
import subprocess as sp
p =...
|
by: Casey Bralla |
last post by:
I'd like to read ASCII data from a serial port, but (once again) I'm having
trouble getting started. (Can't seem to find the basic level of docs to...
|
by: ssc |
last post by:
I'm new to C#, but have been doing embedded programming for years. I have
an application that talks to an embedded radio on the serial port of my...
|
by: jim.omalley |
last post by:
I'm trying to write an interface to send scoreboard data from an XML
file generated by a football stats program to a Chyron CODi character...
|
by: alexandre_irrthum |
last post by:
Hi there,
I am trying to use pyserial to read data from a temperature logger
device (T-logger). T-logger is based on the DS1615 temperature...
|
by: Cintury |
last post by:
Hi all,
I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was...
|
by: darkking |
last post by:
Ok,
I'm trying to read data from the serial port. Problem is, that i always have to query the port for new data, and in 99.9% of acses my query...
|
by: mmrasheed |
last post by:
Hi,
I am newbie in python. I am working on Telit GM862 GPS/GPRS module
which has python interpreter built in. But it seems this problem is
pretty...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...
| |