diff --git a/motorHist.py b/motorHist.py index bc96aae1dd2ef6076565d4f9fec40d00fe233893..370460ad8d73aaedc286db01e5fe582742c6f5b4 100755 --- a/motorHist.py +++ b/motorHist.py @@ -1,48 +1,48 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # Interpret motor changes in camonitor log # import sys -#!print sys.argv +#!print(sys.argv) msta_dict = {1 << 0 : ("Direction", ("Negative", "Positive")), 1 << 1 : ("Done", ("Moving", "Done")), - 1 << 2 : ("Plus limit", ("Off", "On")), - 1 << 3 : ("Home limit", ("Off", "On")), - 1 << 4 : ("Unused", ("0", "1")), - 1 << 5 : ("Closed-loop", ("Enabled", "Disabled")), - 1 << 6 : ("Slip/stall", ("OK", "Stalled")), - 1 << 7 : ("Home", ("Not Home", "Home")), - 1 << 8 : ("Encoder present", ("No", "Yes")), - 1 << 9 : ("Problem", ("No", "Yes")), - 1 << 10 : ("Moving", ("Done", "Moving")), - 1 << 11 : ("Gain support", ("No", "Yes")), - 1 << 12 : ("Comm error", ("OK", "Error")), - 1 << 13 : ("Minus limit", ("Off", "On")), - 1 << 14 : ("Homed", ("Not homed", "Homed")), - } + 1 << 2 : ("Plus limit", ("Off", "On")), + 1 << 3 : ("Home limit", ("Off", "On")), + 1 << 4 : ("Unused", ("0", "1")), + 1 << 5 : ("Closed-loop", ("Enabled", "Disabled")), + 1 << 6 : ("Slip/stall", ("OK", "Stalled")), + 1 << 7 : ("Home", ("Not Home", "Home")), + 1 << 8 : ("Encoder present", ("No", "Yes")), + 1 << 9 : ("Problem", ("No", "Yes")), + 1 << 10 : ("Moving", ("Done", "Moving")), + 1 << 11 : ("Gain support", ("No", "Yes")), + 1 << 12 : ("Comm error", ("OK", "Error")), + 1 << 13 : ("Minus limit", ("Off", "On")), + 1 << 14 : ("Homed", ("Not homed", "Homed")), + } -#!print msta_dict +#!print(msta_dict) mip_dict = {1 << 0 : ("Jog forward", ("Done", "In Progress")), 1 << 1 : ("Jog reverse", ("Done", "In Progress")), - 1 << 2 : ("Post-jog backlash", ("Done", "In Progress")), - 1 << 3 : ("Home forard", ("Done", "In Progress")), - 1 << 4 : ("Home reverse", ("Done", "In Progress")), - 1 << 5 : ("Move (NOT home/jog)", ("Done", "In Progress")), - 1 << 6 : ("Retry", ("Done", "In Progress")), - 1 << 7 : ("Load position", ("Done", "In Progress")), - 1 << 8 : ("Backlash", ("Done", "In Progress")), - 1 << 9 : ("Stopping", ("Done", "In Progress")), - 1 << 10 : ("Delay request", ("Done", "In Progress")), - 1 << 11 : ("Delay acknowledge", ("Done", "In Progress")), - 1 << 12 : ("Jog request", ("Done", "In Progress")), - 1 << 13 : ("Jog stopping", ("Done", "In Progress")), - 1 << 14 : ("External move", ("Done", "In Progress")), - } + 1 << 2 : ("Post-jog backlash", ("Done", "In Progress")), + 1 << 3 : ("Home forard", ("Done", "In Progress")), + 1 << 4 : ("Home reverse", ("Done", "In Progress")), + 1 << 5 : ("Move (NOT home/jog)", ("Done", "In Progress")), + 1 << 6 : ("Retry", ("Done", "In Progress")), + 1 << 7 : ("Load position", ("Done", "In Progress")), + 1 << 8 : ("Backlash", ("Done", "In Progress")), + 1 << 9 : ("Stopping", ("Done", "In Progress")), + 1 << 10 : ("Delay request", ("Done", "In Progress")), + 1 << 11 : ("Delay acknowledge", ("Done", "In Progress")), + 1 << 12 : ("Jog request", ("Done", "In Progress")), + 1 << 13 : ("Jog stopping", ("Done", "In Progress")), + 1 << 14 : ("External move", ("Done", "In Progress")), + } -#!print msta_dict +#!print(mip_dict) motor_dict = {} def msta_diff(last_msta, current_msta): @@ -52,7 +52,7 @@ def msta_diff(last_msta, current_msta): bit = 1 << index if (current_msta & bit): bit_state = 1 - print "\t%s bit (0x%X) starting value is \"%s\" [0x%X]" % (msta_dict[bit][0], bit, msta_dict[bit][1][bit_state], bit_state) + print("\t{} bit (0x{:X}) starting value is \"{}\" [0x{:X}]".format(msta_dict[bit][0], bit, msta_dict[bit][1][bit_state], bit_state)) else: # XOR shows changed bits changed_bits = last_msta ^ current_msta @@ -62,10 +62,10 @@ def msta_diff(last_msta, current_msta): bit = 1 << index if (bit & changed_bits): if (current_msta & bit): - bit_state = 1 + bit_state = 1 else: - bit_state = 0 - print "MSTA:\t%s bit (0x%X) changed to \"%s\" (%i)" % (msta_dict[bit][0], bit, msta_dict[bit][1][bit_state], bit_state) + bit_state = 0 + print("MSTA:\t{} bit (0x{:X}) changed to \"{}\" ({})".format(msta_dict[bit][0], bit, msta_dict[bit][1][bit_state], bit_state)) def mip_diff(last_mip, current_mip): if last_mip == None: @@ -74,7 +74,7 @@ def mip_diff(last_mip, current_mip): bit = 1 << index if (current_mip & bit): bit_state = 1 - print "\t%s bit (0x%X) starting value is \"%s\" [0x%X]" % (mip_dict[bit][0], bit, mip_dict[bit][1][bit_state], bit_state) + print("\t{} bit (0x{:X}) starting value is \"{}\" [0x{:X}]".format(mip_dict[bit][0], bit, mip_dict[bit][1][bit_state], bit_state)) else: # XOR shows changed bits changed_bits = last_mip ^ current_mip @@ -84,10 +84,10 @@ def mip_diff(last_mip, current_mip): bit = 1 << index if (bit & changed_bits): if (current_mip & bit): - bit_state = 1 + bit_state = 1 else: - bit_state = 0 - print "MIP:\t%s bit (0x%X) changed to \"%s\" (%i)" % (mip_dict[bit][0], bit, mip_dict[bit][1][bit_state], bit_state) + bit_state = 0 + print("MIP:\t{} bit (0x{:X}) changed to \"{}\" ({})".format(mip_dict[bit][0], bit, mip_dict[bit][1][bit_state], bit_state)) def main(log_file): @@ -95,11 +95,11 @@ def main(log_file): try: fh = open(log_file, 'r') except IOError: - print "%s doesn't exist." % log_file + print("{} doesn't exist.".format(log_file)) sys.exit(1) for line in fh: - #!print line[:-1] + #!print(line[:-1]) # Break line into list of values: PV name, date, time, value line_list = line[:-1].split() @@ -121,57 +121,57 @@ def main(log_file): # Check for VAL change if field == "VAL": # Catch error here? - current_val = float(value) - last_val = motor_dict[name]["VAL"] + current_val = float(value) + last_val = motor_dict[name]["VAL"] if last_val == None: - print "[%s %s] %s's %s field starts at %0.4f" % (date, time, name, field, current_val) - else: - print "[%s %s] %s's %s field changed from %0.4f to %0.4f" % (date, time, name, field, last_val, current_val) - motor_dict[name]["VAL"] = current_val - print + print("[{} {}] {}'s {} field starts at {:0.4f}".format(date, time, name, field, current_val)) + else: + print("[{} {}] {}'s {} field changed from {:0.4f} to {:0.4f}".format(date, time, name, field, last_val, current_val)) + motor_dict[name]["VAL"] = current_val + print() # Check for DMOV change if field == "DMOV": # Catch error here? - current_dmov = int(value) - last_dmov = motor_dict[name]["DMOV"] + current_dmov = int(value) + last_dmov = motor_dict[name]["DMOV"] if last_dmov == None: - print "[%s %s] %s's %s field starts at %i" % (date, time, name, field, current_dmov) - else: - print "[%s %s] %s's %s field changed from %i to %i" % (date, time, name, field, last_dmov, current_dmov) - motor_dict[name]["DMOV"] = current_dmov - print + print("[{} {}] {}'s {} field starts at {}".format(date, time, name, field, current_dmov)) + else: + print("[{} {}] {}'s {} field changed from {} to {}".format(date, time, name, field, last_dmov, current_dmov)) + motor_dict[name]["DMOV"] = current_dmov + print() # Check for MSTA change if field == "MSTA": # Catch error here? - current_msta = int(value) - last_msta = motor_dict[name]["MSTA"] - if last_msta == None: - print "[%s %s] %s's %s field starts at %i [0x%X]" % (date, time, name, field, current_msta, current_msta) - else: - print "[%s %s] %s's %s field changed from %i [0x%X] to %i [0x%X]" % (date, time, name, field, last_msta, last_msta, current_msta, current_msta) - msta_diff(last_msta, current_msta) - motor_dict[name]["MSTA"] = current_msta - print - + current_msta = int(value) + last_msta = motor_dict[name]["MSTA"] + if last_msta == None: + print("[{} {}] {}'s {} field starts at {} [0x{:X}]".format(date, time, name, field, current_msta, current_msta)) + else: + print("[{} {}] {}'s {} field changed from {} [0x{:X}] to {} [0x{:X}]".format(date, time, name, field, last_msta, last_msta, current_msta, current_msta)) + msta_diff(last_msta, current_msta) + motor_dict[name]["MSTA"] = current_msta + print() + # Check for MIP change if field == "MIP": # Catch error here? current_mip = int(value) - last_mip = motor_dict[name]["MIP"] - if last_mip == None: - print "[%s %s] %s's %s field starts at %i [0x%X]" % (date, time, name, field, current_mip, current_mip) - else: - print "[%s %s] %s's %s field changed from %i [0x%X] to %i [0x%X]" % (date, time, name, field, last_mip, last_mip, current_mip, current_mip) - mip_diff(last_mip, current_mip) - motor_dict[name]["MIP"] = current_mip - print + last_mip = motor_dict[name]["MIP"] + if last_mip == None: + print("[{} {}] {}'s {} field starts at {} [0x{:X}]".format(date, time, name, field, current_mip, current_mip)) + else: + print("[{} {}] {}'s {} field changed from {} [0x{:X}] to {} [0x{:X}]".format(date, time, name, field, last_mip, last_mip, current_mip, current_mip)) + mip_diff(last_mip, current_mip) + motor_dict[name]["MIP"] = current_mip + print() fh.close() if __name__ == '__main__': if len(sys.argv) != 2: - print "Usage: motorHist.py <log_file>" + print("Usage: motorHist.py <log_file>") else: main(sys.argv[1])