472,119 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 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 2352
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by willie | last post: by
14 posts views Thread by McBooCzech | last post: by
6 posts views Thread by Casey Bralla | last post: by
5 posts views Thread by George T. | last post: by
15 posts views Thread by xkenneth | last post: by
3 posts views Thread by pcm | last post: by
13 posts views Thread by Rob | last post: by
4 posts views Thread by rowan | last post: by
2 posts views Thread by mmrasheed | last post: by
reply views Thread by leo001 | last post: by

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.