Commit a193fb9b authored by Gaia Grosso's avatar Gaia Grosso
Browse files

Update main.py

parent d8fc0a49
......@@ -128,19 +128,41 @@ if __name__ == '__main__':
if action == "set":
if value == None:
print("action 'set' requires the optional argument --value (-v).")
if filelog:
print("Save log at %s"%(filelog))
f = open(filelog, "w")
f.write("board: %s\n"%(device))
f.write("property: %s\n"%(prop))
f.write("location: %s\n"%(location))
f.write("offset: %i\n"%(offset))
f.write("width: %i\n"%(width))
f.write("action: %s\n"%(action))
f.write("error: action 'set' requires the optional argument --value (-v).")
f.close()
exit()
nbits_allowed = width # number of allowed bits
nbits_write = value.bit_length() # number of bits needed
if nbits_write > nbits_allowed:
print("Overflow error! value %s doesn't fit in the allowed memory location."%(args.value))
if filelog:
print("Save log at %s"%(filelog))
f = open(filelog, "w")
f.write("board: %s\n"%(device))
f.write("property: %s\n"%(prop))
f.write("location: %s\n"%(location))
f.write("offset: %i\n"%(offset))
f.write("width: %i\n"%(width))
f.write("action: %s\n"%(action))
f.write("error: overflow error! value %s doesn't fit in the allowed memory location."%(args.value))
f.close()
exit()
else:
writevalue = ctypes.c_uint(value) #unsigned int (32 bits)
output = WriteProperty(device, location, offset, width, writevalue, verbose=verbose)
if output == -1:
print('The value could not be updated.')
exit()
else:
print('Set property %s from location %s on %s: %i'%(prop, location, board, writevalue.value))
......@@ -148,7 +170,6 @@ if __name__ == '__main__':
output = ReadProperty(device, location, offset, width, verbose=verbose)
if output == -1:
print('The register could not be read.')
exit()
else:
print('Get property %s from location %s on %s: %i'%(prop, location, board, output))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment