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

Update main.py

parent a193fb9b
......@@ -52,15 +52,13 @@ def ReadProperty(device, location, offset, width, verbose=0):
if isRead == -1:
print("An error occured while executing C function read_bits")
return -1
string_32bits = "{:032b}".format(read_32bits.value)
if verbose:
string_32bits = "{:032b}".format(read_32bits.value)
print("Read: %s"%(string_32bits))
string_32bits = "{:032b}".format(read_32bits.value>>offset)
string_out = string_32bits[-1*width:] # remove masked bits
output = int(string_out, 2) # convert selected string to integer
mask = 2**width - 1
output = (read_32bits.value>>offset) & mask # convert selected string to integer
if verbose:
print("Unmasked result: %i (%s)"%(output, string_out))
print("Unmasked result: %i (%s)"%(output, str(bin(output))))
return output
def WriteProperty(device, location, offset, width, write_value, verbose=0):
......@@ -69,14 +67,14 @@ def WriteProperty(device, location, offset, width, write_value, verbose=0):
if isRead == -1:
print("An error occured while executing C function read_bits")
return -1
string_read = "{:032b}".format(read_value.value)
string_write = "{:032b}".format(write_value.value<<offset)
if verbose:
string_read = "{:032b}".format(read_value.value)
string_write = "{:032b}".format(write_value.value<<offset)
print("Read: %s"%(string_read))
print("Write: %s"%(string_write))
string_write = string_read[:-1*(offset+width)] + string_write[-1*(offset+width):-1*offset] + string_read[-1*offset:]
output = int(string_write, 2)
mask = (2**width-1)<<offset
notmask = (2**32-1)-mask
output = ((write_value.value<<offset) & mask) | (read_value.value & notmask)
isWritten = reg.write_bits(device, location, output, ctypes.c_uint(verbose))
if isWritten == -1:
print("An error occured while executing C function write_bits.")
......
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