connecting to serial port + python

Japan Shah shahjapan at gmail.com
Tue Jul 3 15:01:51 CEST 2007


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.getSupportedBaudrates()
print 'getSupportedByteSizes',conn1.getSupportedByteSizes()
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()




More information about the Python-list mailing list