0

I'm trying to calculate the maintenance time so my program is continuously reading registers to identify the stats and then using a pandas csv register the time when the register == 1 (maintenance in progress) and register = 0 (no maintenance) this way... creating a variable "mantenimiento" to make sure the time is registered only when the maintenance starts or ends saving its value at a column of csv.

regs1 = c.read_holding_registers(230)

mantenimiento = df['col28']

if regs1 == [1] and mantenimiento == 0:
    df['col1'] = time.time()
    df.to_csv("oee.csv", sep=' ', header=True, index=False, mode='r+')
    print(df['col1'])
    c.write_multiple_registers(0, [0])
    c.write_multiple_registers(5, [10])
    mantenimiento = 1
    print("Maintenance in progress", mantenimiento)

if regs1 == [0] and mantenimiento == 1:
    tiempoparomant = time.time() - df['col1']
    df['col2'] = tiempoparomant
    minutos = tiempoparomant / 60
    segundos = tiempoparomant % 60
    df['col2'] = minutos * 60

    df['col3'] = df['col3'] + df['col2']
    df.to_csv("oee.csv", sep=' ', header=True, index=False, mode='r+')
    c.write_multiple_registers(0, [0])
    mantenimiento = 0

I was doing it wrong registering time every time that regs1=0 so it has no sense... when added the mantenimiento variable stored at the csv shows me the following error: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Do you know what can I do to solve this?

There would be any way to register time firs moment when regs1=1 and then wait for regs1=0 to save the time again making the program stop to no loosing time of maintenance during the readings of the stats of registers?

Thank you in advice.

Edu P
  • 1
  • You may want to take a look at event handling, I'd check out this thread https://stackoverflow.com/questions/1092531/event-system-in-python – João Areias Sep 25 '20 at 11:21
  • Reading your code a bit better I see the problem you are facing with the pandas dataframe. When you call mantenimiento == 0 it will return a series of true or false, think of it as a list like this [True, False, True, True, False, ...], the "and" operator expects two booleans not a boolean and a list of booleans – João Areias Sep 25 '20 at 11:28

0 Answers0