473,382 Members | 1,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

connecting to serial port + python

Hello,

I am trying to connect my Nokia 6610 using usb cable,
I have installed usb-serial driver of it.
I hv tested it with Hyperterminal and it works fine.

but when I wrote a python script I am not able to receive the responce
from the device.

import os
import re
import time
import sys
from threading import Thread
import serial

class connect_serial(Thread):
def __init__(self,socks):
Thread.__init__(self)
self.sock = socks
self.count = 0

def run(self):
self.count = 0
try:
while 1:
self.count +=1
if (self.count>=5):
break

lines = self.sock.read(100)
if lines:
print lines
print 'read
success-----------------------------------------------'
else:
print 'nothing to read',str(self.getName())
except Exception,e:
print self.getName()

print time.ctime()
print
try:
conn1 = serial.Serial(4)
conn1.baudrate = '9600'
conn1.parity = serial.PARITY_EVEN
conn1.timeout=1
except Exception,e:
print 'port is Buzy'
sys.exit(-1)
print '------------------------------'
print 'getSupportedBaudrates',conn1.getSupportedBaudrate s()
print 'getSupportedByteSizes',conn1.getSupportedByteSize s()
print 'getSupportedParities',conn1.getSupportedParities( )
print 'getSupportedStopbits',conn1.getSupportedStopbits( )
print '------------------------------'
print 'getBaudrates',conn1.getBaudrate()
print 'getByteSizes',conn1.getByteSize()
print 'getParities',conn1.getParity()
print 'getStopbits',conn1.getStopbits()
print '------------------------------'
print 'port is in use',conn1.portstr
list1 = []

command = ['AT','ATI','ATl1','AT+GMMM']

for cmd in command:
conn1.write(str(cmd))
th = connect_serial(conn1)
list1.append(th)
th.start()

for th1 in list1:
print 'started joining',th1.getName(), 'counter :',th1.count
th1.join()

print time.ctime()

Jul 3 '07 #1
2 2409
En Tue, 03 Jul 2007 10:01:51 -0300, Japan Shah <sh*******@gmail.com>
escribió:
I am trying to connect my Nokia 6610 using usb cable,
I have installed usb-serial driver of it.
I hv tested it with Hyperterminal and it works fine.
but when I wrote a python script I am not able to receive the responce
from the device.
lines = self.sock.read(100)
If the response contains less than 100 bytes, the above line will block.
command = ['AT','ATI','ATl1','AT+GMMM']

for cmd in command:
conn1.write(str(cmd))
Don't you have to send <ENTERafter each command? "\n"
th = connect_serial(conn1)
list1.append(th)
th.start()
You can't have four threads all reading the same serial port. The device
sends its responses sequentially anyway.

--
Gabriel Genellina

Jul 5 '07 #2
In article <11**********************@m37g2000prh.googlegroups .com>,
Japan Shah <sh*******@gmail.comwrote:
>Hello,

I am trying to connect my Nokia 6610 using usb cable,
I have installed usb-serial driver of it.
I hv tested it with Hyperterminal and it works fine.

but when I wrote a python script I am not able to receive the responce
from the device.
Jul 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: willie | last post by:
Hi, I'm writing a program which requires the use of three serial ports and one parallel port. My application has a scanning devices on each port, which I can access fine with pyserial. ...
14
by: McBooCzech | last post by:
Hi I am just trying to analyze (parse) data from the serial port (I have connected GPS receiver to the ttyS0, so I can read ASCII characters in the CSV form on the serial port 1). I am doing this...
6
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 get going <sigh>) I'd like to use only...
5
by: George T. | last post by:
I need to access the serial port via python on a windows machine. Reading on the web, there are three solutions: pyserial, siomodule and USPP. pyserial seems to be the best option since the other...
15
by: xkenneth | last post by:
Hi, I'm writing a couple python applications that use the serial port (RS-232) quite extensively. Is there any way I can monitor all activity on the serial port and have it printed as the...
3
by: pcm | last post by:
Hi, Has anyone ever worked on a Python-WinCE-based program that involved serial port management ? Regards, Philippe
13
by: Rob | last post by:
Hi all, I am fairly new to python, but not programming and embedded. I am having an issue which I believe is related to the hardware, triggered by the software read I am doing in pySerial. I...
4
by: rowan | last post by:
I'm writing a driver in Python for an old fashioned piece of serial equipment. Currently I'm using the USPP serial module. From what I can see all the serial modules seem to set the timeout when...
2
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 much related to general python structure. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.