Python script for loading hex to DS89C430/440/450 (LINUX)

Few days ago I was just trying to familiarize an 89C430 microcontroller. I am using SDCC in linux. Then I feel the process of hex loading (ISP) a bit difficult since I need to type the commands and send the hex file using a terminal emulator. Then I wrote a small python script (pyserial based) for the purpose. It requires the file name of the hex as command line argument and the remaining the script will do...
PHP:
import serial,time,sys,os
os.system("clear")
if not sys.argv[1:]:
    print "hex file not specified in command line argument\n\n"
    print "usage:\npython romloader.py filename.ihx\n\n"
    print "example:\n python romloader.py ledblink.ihx\n\n"
    sys.exit(0)
ser = serial.Serial("/dev/ttyUSB0",57600)
ser.timeout = 0.3
try:
    ser.open()
    ser.setDTR(1)
except Exception,e:
    print "error open serial port: " + str(e)
    exit()
if ser.isOpen():
    try:
        ser.flushInput()
        ser.flushOutput()
        ser.write("\x0D")
        time.sleep(0.1)
        recbuffer = ser.read(80)
        list = recbuffer.split(" ")
        if 'LOADER' in recbuffer:
            print "CONNECTED TO LOADER SUCCESSFULLY"
            print recbuffer
        else:
            print "CONNECTION ERROR"
            ser.setDTR(0)
            ser.close()
            sys.exit(0)
        ser.write("K\x0D")
        time.sleep(0.1)
        ser.write("L\x0D")
        f=open(sys.argv[1],"rU")      
        hexcontent = f.read()
        f.close()
        ser.write(hexcontent+"\x0D")
        k = ser.read(200)
        print k
        ser.setDTR(0)
        ser.close()
    except Exception, e1:
        print "error communicating...: " + str(e1)
else:
    print "cannot open serial port "


Comments

There are no comments to display.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…