def threadFunc(self): while 1: bits = DataBank.get_bits(0, 5) print(bits) #words = DataBank.get_words(0,4) #print(words) time.sleep(0.2)
def threadFunc(c): while 1: for i in range(100): bits = DataBank.get_bits(0,1) temp = os.popen("vcgencmd measure_temp").readline() now = datetime.now() str_date = now.strftime("%M%S") temp = temp.replace("temp=", "").replace("'C\n" , "") tempint = int(float(temp)) int_date = int(str_date) temperature.append(tempint) time_now.append(int_date) dizi = time_now[i],temperature[i] time.sleep(1) #print(dizi, type(dizi)) DataBank.set_words(0, dizi) if bits[0] == 1: print("1 geldi babba") GPIO.output(40, GPIO.HIGH) else: print("0 geldi babba") GPIO.output(40, GPIO.LOW) time.sleep(0.25)
# -*- coding: utf-8 -*- # modbus_thread # start a thread for polling a set of registers, display result on console # exit with ctrl+c import time from threading import Thread, Lock from pyModbusTCP.client import ModbusClient from pyModbusTCP.server import DataBank SERVER_HOST = "localhost" SERVER_PORT = 502 # set global regs = DataBank.get_bits(0, 4) # init a thread lock regs_lock = Lock() # modbus polling thread def polling_thread(): global regs c = ModbusClient(host=SERVER_HOST, port=SERVER_PORT) # polling loop while True: # keep TCP open if not c.is_open(): c.open() # do modbus reading on socket