Index: spi_test.py =================================================================== --- spi_test.py (revision 597) +++ spi_test.py (working copy) @@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License along with pyBusPirate. If not, see . """ +from serial.serialutil import SerialException import sys, optparse from pyBusPirateLite.SPI import * @@ -55,6 +56,9 @@ parser.add_option("-s", "--size", dest="flash_size", default=128, help="Size of Flashchip in bytes", type="int") + parser.add_option("-d", "--dev", + dest="dev_name", default="/dev/tty.usbserial-A7004qlY", + help="The device to connect to", type="string") (options, args) = parser.parse_args() @@ -77,7 +81,11 @@ elif opt.command == "write": f=open(args[0], 'rb') - spi = SPI("/dev/tty.usbserial-A7004qlY", 115200) + try: + spi = SPI(opt.dev_name, 115200) + except SerialException as ex: + print ex + sys.exit(); print "Entering binmode: ", if spi.BBmode(): @@ -93,15 +101,23 @@ print "failed." sys.exit() - print "Configuring SPI." + print "Configuring SPI peripherals: ", if spi.cfg_pins(PinCfg.POWER | PinCfg.CS | PinCfg.AUX): - print "Failed to set SPI peripherals." + print "OK." + else: + print "failed." sys.exit() + print "Configuring SPI speed: ", if spi.set_speed(SPISpeed._2_6MHZ): - print "Failed to set SPI Speed." + print "OK." + else: + print "failed." sys.exit() + print "Configuring SPI configuration: ", if spi.cfg_spi(SPICfg.CLK_EDGE | SPICfg.OUT_TYPE): - print "Failed to set SPI configuration."; + print "OK." + else: + print "failed." sys.exit() spi.timeout(0.2)