jeudi 7 janvier 2021

Python multiple condition checkings

Python 3.7, windows 10

I'm appending all the values that I get from a modbus holding register.The data values goes like this : 0 to 4000, So if I run continuously, I repeatedly get values in #between 0 and 4000, in every call. (Verified it in the console that the value is looping from 0-4000, till here no issues, all fine)

... modbus init code snippets here ...

data = client.read_input_registers(0, 3, unit=1)
initial_value = data.registers[2]
data_log = []

while(True):
    data = client.read_input_registers(0, 3, unit=1)
    data_log.append((data.registers[2]))
    
    if(len(data_log) > 3):
        if(int(data.registers[2]) < int(data_log[-2])) and (int(data.registers[2]) > int(initial_value)):
            print("ISSUE HERE..THIS DOESNT GET PRINTED")

This never gets printed, even though the values in a are increasing from 0, goes till 4000 and again falls to 0 and again keeps increasing.I want to print it whenever I cross my initial reading

Both the conditions work well when testing individually. But even if I write it like usual nested if or, in a single line, it doesn't get executed. Any guidance thankfully appreciated

Aucun commentaire:

Enregistrer un commentaire