martes, 8 de agosto de 2023

Tesys T LTMR + pymodbus + Tkinter

from Tkinter import *

import os
import MySQLdb
from pymodbus.client.sync import ModbusTcpClient

#-------------------------------------------------------

#-------------------------------------------------------
def decbin(numero):
  cadenabin = ""	
  for i in range(1,17):  
    resultado = numero / 2
    resto = numero % 2
    if resto == 0:
      cadenabin = cadenabin + "0"
    else:
      cadenabin = cadenabin + "1"
		
    numero=resultado

  return cadenabin

def FUNC_OFF_a():
    cliente.write_register(704, 0b0000000000000000)

def FUNC_ON_a():
    cliente.write_register(704, 0b0000000000000001)

def FUNC_WRITE():
    dato = entrada.get()
    print dato
    dato = int(dato)
    cliente.write_register(652,dato)

def FUNC_ON_b():
    cliente.write_register(704, 0b0000000000000010)

def FUNC_Reset():
    cliente.write_register(704, 0b0000000000001000)

def FUNC_Kill():
    print ("Cuidado !")
    cliente.write_register(705, 0b0000000000011111)


def FUNC_Estado():
    estado = cliente.read_holding_registers(455,1)
    datos = estado.registers[0]
    print("-------------------------------------")
    print ("Registro 455")
    #print datos
    print decbin(datos)
    if (datos & 1): print ("Sistema listo")
    if (datos & 2): print ("Sistema activado")
    if (datos & 4): print ("Sistema fallo")
    if (datos & 8): print ("Sistema advertencia")
    if (datos & 16): print ("Sistema disparo")
    if (datos & 32): print ("Reinicio de fallo autorizado")
    if (datos & 64): print ("Controlador potencia\n")

    print("-------------------------------------")
    estado = cliente.read_holding_registers(457,1)
    datos = estado.registers[0]
    print ("Registro 457")
    #print datos
    print decbin(datos)

    if (datos & 1): print ("E1 Start")
    if (datos & 2): print ("E2 Close O2")
    if (datos & 4): print ("E3 Free")
    if (datos & 8): print ("E4 Stop O1 O2")
    if (datos & 16): print ("E5 Reset")
    if (datos & 32): print ("E6 L/R")





#    VENT_Estados = Tk()
#    VENT_Estados.title("LTMR Tesys T - Estados -")
#    VENT_Estados.minsize(300,200)

#    texto = Label(VENT_Estados, text="Estado LTMR")
#    texto.pack()
    



#-------------------------------------------------------
cliente = ModbusTcpClient('192.168.4.169','502')
cliente.connect()

#-------------------------------------------------------
# MAIN LOOP

VENTANA = Tk()
VENTANA.title("LTMR Tesys T")
VENTANA.minsize(250,200)


texto = Label(VENTANA, text="Comandos LTMR")
texto.pack()

ON_Img = PhotoImage(file="ON.png")
imagen = ON_Img.subsample(10,10)

ON_a = Button(VENTANA, text="ON 0", width=8, height=1, command=FUNC_ON_a, bg="green")
ON_a.pack()


OFF_a = Button(VENTANA, text="OFF 0", width=8, height=1, command=FUNC_OFF_a)
OFF_a.pack()


ON_b = Button(VENTANA, text="ON 1", width=8, height=1, command=FUNC_ON_b, bg="green")
ON_b.pack()


#---------------------------------------------------------------------------
entrada = StringVar()
corriente = Entry(VENTANA, width=10, textvariable=entrada)
corriente.pack()


OFF_b = Button(VENTANA, text="WRITE", width=8, height=1, command=FUNC_WRITE)
OFF_b.pack()
#---------------------------------------------------------------------------

RESET = Button(VENTANA, text="Reset", width=8, height=1, command=FUNC_Reset)
RESET.pack()

ESTADO = Button(VENTANA, text="Estado", width=8, height=1, command=FUNC_Estado)
ESTADO.pack()


KILL = Button(VENTANA, text="Kill", width=8, height=1, bg="red", command=FUNC_Kill)
KILL.pack()


VENTANA.mainloop()
cliente.close()

No hay comentarios:

IRC

#freenode->#usljujuy

Seguidores

Eventos n_n

Tira Ecol Nano,Bilo y Luca