diff -ur /tmp/t616hack/ContactDownload.py t616hack/ContactDownload.py --- /tmp/t616hack/ContactDownload.py 2003-11-16 20:27:11.000000000 +0100 +++ t616hack/ContactDownload.py 2004-03-12 14:45:03.000000000 +0100 @@ -7,7 +7,7 @@ from T616 import T616 -p = T616(debug=False) +p = T616(debug=True) try: p.selectMemory() diff -ur /tmp/t616hack/ContactUpload.py t616hack/ContactUpload.py --- /tmp/t616hack/ContactUpload.py 2003-11-16 20:27:09.000000000 +0100 +++ t616hack/ContactUpload.py 2004-03-12 14:45:03.000000000 +0100 @@ -3,7 +3,7 @@ """Upload phone contacts to memory from a file. Note: this will overwrite your contact list with the new records!""" -import sys +import sys, time datafile = "converted.txt" fp = file(datafile, "r") @@ -15,13 +15,14 @@ p = T616(debug=True, timeout=1.0) +p.selectMemory() +p.selectEncoding("8859-1") try: - p.selectMemory() for c in contacts: p.writeContact(c) - p.close() except Exception, e: sys.stderr.write("%s\n" % e) - p.close() + +p.close() print "Wrote contacts!" Only in t616hack: converted.txt Only in t616hack: serial diff -ur /tmp/t616hack/T616.py t616hack/T616.py --- /tmp/t616hack/T616.py 2003-11-16 20:26:58.000000000 +0100 +++ t616hack/T616.py 2004-03-12 14:45:03.000000000 +0100 @@ -3,7 +3,7 @@ "Talk to a T616 via the serial port and make it do various things" -# import serial # Requires pySerial http://pyserial.sourceforge.net/ +import serial # Requires pySerial http://pyserial.sourceforge.net/ import time, re, sys contactParseRE=re.compile(r''' @@ -11,7 +11,7 @@ (?P\d+), "(?P[\dp*#+]+)", (?P\d+), - "(?P[^/]+)/(?P\S)"$''', + "(?P.+)/(?P\S)"$''', re.VERBOSE) def contactParse(s): """Parse a contact from the phone's format. @@ -58,15 +58,11 @@ http://www.ericsson.hu/mobilinternet/products/sh888/888_r1d.pdf """ - def __init__(self, port='COM4', timeout=1.0, debug=False): + def __init__(self, port='/dev/ttyUSB0', timeout=1.0, debug=False): """Create a connection to the phone, clear the channel and test it. port: name of the serial port for pySerial to open timeout: default timeout for reads""" - raise """This code is for demonstration purposes only. You must -be a Python programmer to make use of it. This code could potentially -destroy your phone. Understand it before using it!""" - self.debug = debug # Open port @@ -107,6 +103,12 @@ "Execute a command, then verify output. Relies on timeout." self._sendCmd(cmd) result = self.ser.read(len(expected)) # Rely on timeout here + if result == '': + self._debug("Received '': trying again") + time.sleep(1) + self._sendCmd(cmd) + result = self.ser.read(len(expected)) # Rely on timeout here + self._debug("Received %s:" % repr(result)) if not result == expected: raise "Expected %s but got %s" % (repr(expected), repr(result)) @@ -124,6 +126,10 @@ def selectMemory(self, type="ME"): "Select cell phone's memory (type can be one of ME or SM)" self._expect('AT+CPBS="%s"' % type, '\r\nOK\r\n') + + def selectEncoding(self, encoding="8859-1"): + "Select the character encoding" + self._expect('AT+CSCS="%s"' % encoding, '\r\nOK\r\n') def readContacts(self): """Read all the contacts in the phone's memory.