# This code is not working! # Atleast not in its current state # I'm doing my best to figure out the issue # For now the work around I've found was to run the code, then in the shell type: ''' ser.open() ''' # Reopens the serial port ''' ADDR = int("1F00",base=16) ''' # Sets address to whatever hex value you put in the string, that is where the eeprom writer will start, make sure there is enough space for your program ''' for i in range(0,len(data)): #write_bulk(data[i])#,i write(data[i],ADDR) print(ser.readline(), end=' ') ADDR+=1 ''' # This sends the data to the eeprom programmer ''' ser.close() ''' # Closes the serial port # Always remember to close the port on your way out, it'd be rude not to~ import numpy as np import binascii, serial, time ser = serial.Serial(baudrate = 9600,port = 'COM3') ser.baudrate = 9600 ser.port = 'COM3' try: ser.open() except: print("port already open") ser.close() # These lines weren't in the code when I tested it ser.open() # It might work with them, but I'm not sure, give it a shot HexAscii="0123456789ABCDEF" def write(x,addr): global HexAscii setting = b'T' setting+=bytes(HexAscii[addr//4096], 'ASCII') addr%=4096 setting+=bytes(HexAscii[addr//256], 'ASCII') addr%=256 setting+=bytes(HexAscii[addr//16], 'ASCII') addr%=16 setting+=bytes(HexAscii[addr], 'ASCII') data = HexAscii[x//16]+HexAscii[x%16] ser.write(setting+b'-01'+bytearray(data, 'ASCII')) ser.flush() print(ser.readline()) #time.sleep(0.05) return def write_bulk(data): ser.write(data) return def write_read(x): ser.write(bytes(x, 'ASCII')) time.sleep(0.05) return data memory_size = 8192 fp=r"C:\vasm\vasm6502_oldstyle\a.out" #Binary File Hex = open(fp,'rb') data_Full=Hex.read() data=bytearray(data_Full) "TFE01-01AA" start="1F00" setting="W"+start+"-" Len=len(data) length=Len digit=length//4096 setting+=HexAscii[length//4096] length%=4096 setting+=HexAscii[length//256] length%=256 setting+=HexAscii[length//16] length%=16 setting+=HexAscii[length] if int(start,base=16)+Len > memory_size: print("File too large, move the starting point back to allow enough space") 0/0 0/0 #print(ser.readline()) print(setting) #ser.write(b'0100.0200')#b"RFF00-0100\n")#bytearray(ascii(setting+'\n'))) #print(ser.readline()) #ser.write(data) #print("done") #ser.write(b"P") ADDR=int(start,base=16) #ser.write(bytearray(setting, "ASCII")) time.sleep(0.5) ser.flush() print("writing...") # This is the code that should send the data to the eeprom programmer, but it doesn't work # You might just want to comment it out for i in range(0,len(data)): #write_bulk(data[i])#,i write(data[i],ADDR) print(ser.readline(), end=' ') ADDR+=1 #print(data[i],end=' ') #time.sleep(0.025) #ser.write(data) print("done!") ser.close() # This code isn't used, it was probably garbage, but I haven't checked recently # All I know is that it didn't work, so it's probably best to just not bother ''' start=7936 for i in range(start,start+len(data)): write_bulk(data[i-start])#,i) print(data[i-start],end=' ') time.sleep(0.025) print("done") time.sleep(0.05) ser.close() #print(binascii.hexlify(data)) #arr=np.zeros(len(data),dtype=np.uint16) #for i in range(0,len(data)): # arr[i]=data[i] #print(arr) ''' # Sorry to anyone who was subjected to this code, hopefully a better version will be out soon