#!/usr/bin/python # Copyright (C) 2009 Jeff Epler # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import serial import time import sys master = True if 'slave' in sys.argv: master = False s = serial.Serial("/dev/ttyUSB0", 19200) def W(c,r=60,timeout=1): print '->', repr(c) s.write(c) s.setTimeout(timeout) r = s.read(r) print '<-', repr(r) if not r or r.strip() == 'ERROR': raise ValueError, (c,r) time.sleep(2) W("+++", timeout=2) W("ATBD4\r\n") W("ATID1234\r\n") if master: W("ATMY0\r\n") # W("ATDLFFFF\r\n") W("ATD33\r\n") W("ATIC8\r\n") else: W("ATMY1\r\n") W("ATDL0\r\n") W("ATD35\r\n") W("ATIU0\r\n") W("ATIAFFFF\r\n") W("ATWR\r\n") W("ATCN\r\n") #master = True #if master: # W("ATBD3,ID1234,MY0,DLFFFF,D33,IC8,WR,CN\r", timeout=1); #else: # W("ATBD3,ID1234,MY1,DL0,D35,IU0,IAFFF,WR,CN\r", timeout=1);