connecting to serial port + python

J

Japan Shah

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()
 
G

Gabriel Genellina

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 said:
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.
 
C

Cameron Laird

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.
.
.
.
It's quite likely that you do NOT want to regard this as
a "serial port" device as commonly understood. It's even
more likely that you're going to be very happy once you
start reading about gammu <URL: http://www.gammu.org/ >,
an open-source project (or collection of open-source pro-
jects) focussed on mobile telephony handset devices,
especially those from Nokia.

Gammu works particularly well with the 6610 and closely-
related handsets, in my experience; I've been using it so
for a couple of years.

What's your preferred (desktop) operating system? Which
cable did you buy? Is it compatible with one made at the
Nokia factories? Not all USB cables are alike ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top