problemas con conexion python a tia portal #491
Unanswered
ignaciofigue
asked this question in
Q&A
Replies: 2 comments
-
@ignaciofigue I don't understand the half of your post because of mixing English and Spainish with your code snippets. Can you reformat the post ? |
Beta Was this translation helpful? Give feedback.
0 replies
-
this DOESN'T return an int ...
Your Issue isn't related to your library it will be closed |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm having issues with the following code in the part where it says datos = simular_datos_balanza. I added int() to convert the value to a numeric one, but it raises an error when reaching that line (int() argument must be a string, a bytes-like object, or a real number, not 'function').
I'm posting my code here below to see if someone can help me. I'm trying to simulate sending a weight to the general server when passing my hand over a sensor. Thank you in advance.
import socket
import random
import time
import snap7
def simular_datos_balanza():
# Simula la generación de datos de la balanza
peso = random.uniform(-0.1, 5.0) # Genera un peso aleatorio entre -0.1 y 5.0 kg
return f"{peso:.2f} kg"
def recibir_pulso_sensor(plc):
data = plc.read_area(0x82, 0, 0, 1)
return data[0] == 1
def iniciar_cliente(host, puerto):
try:
# Configurar el socket del cliente
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as cliente_socket:
cliente_socket.connect((host, puerto))
print(f"Conexión establecida con el servidor en {host}:{puerto}")
# Configuración del servidor, puerto y intervalos de tiempo
servidor_host = '192.168.0.2' # Cambia esto a la dirección del servidor
servidor_puerto = 2147 # Cambia esto al puerto del servidor
# Llamar a la función para iniciar el cliente
iniciar_cliente(servidor_host, servidor_puerto)
Beta Was this translation helpful? Give feedback.
All reactions