Showing posts with label pyserial port scan. Show all posts
Showing posts with label pyserial port scan. Show all posts

Friday, March 14, 2014

Python libraries


Long time no c ... :)  I know.
lets get back to business.
I have had interesting issues with my python scripting . thought of sharing one of them.
I was asked to create a plot for application performance comparison across multiple platforms. this turned out to be a tricky one as I hardly worked on graphs.

To my surprise, i found an easy and interesting library for this.

matplotlib.pyplot

amazing tool. very user friendly. here is the link to the same with few examples.

http://matplotlib.org/index.html

happy scripting :)




Friday, April 6, 2012

pyserial - usb serial port scan

good to be back after a break. I have been using pyserial for performing serial automation on hardware. I faced a peculiar problem . Thought it will be a good idea to post it. I have usb-serial cable connected to pc which is bluetooth capable. Now, when i do a port scan , it also lists the serial ports from bluetooth too. this was causing problems in my script execution. so I had to modify the port scan script to take care of this problem . the script is below ..

print "Checking for the Serial Port....."

for i in range(256):
try:
ser = serial.Serial(i, 115200,timeout=1)
print ser.portstr
ser.setWriteTimeout(1)
ser.write("hello" + "\n")
data = ser.read(9999)
print data
ser.close()
except serial.SerialException:
print "exception",sys.exc_info()[1]
pass

Just copy this code and use it. keep in mind , the true validation can be based on the data in my script or the time it takes to respond to such a request over serial.

i have also added the exception print info which could turn in handy .

Happy Scripting

Wednesday, December 28, 2011

pyserial port scan

if you are using pyserial module to read the communication from your device on UART , you will have to know which port the is your system connected to.

the following is a simple code to scan through all the COM ports and find out which com port is in opened. at the end of the program , you will see the serial uart that is in use being printed

import pyserial
for i in range(256):
try:
s = serial.Serial(i)
available.append( (i, s.portstr))
port = i
s.close()
except serial.SerialException:
pass

ser = serial.Serial(port, 115200,timeout=1)
print ser.portstr


happy scripting!