Add method to create ADAM message directly from mA value and update simulator tab to use it
This commit is contained in:
parent
0caea3ddc0
commit
86669fc94c
|
@ -55,6 +55,18 @@ class ProtocolHandler:
|
||||||
|
|
||||||
return full_message_str.encode('ascii'), ma_val
|
return full_message_str.encode('ascii'), ma_val
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def create_adam_message_from_ma(adam_address, ma_value):
|
||||||
|
"""
|
||||||
|
Crea un mensaje completo ADAM (como bytes) directamente desde un valor mA.
|
||||||
|
Permite enviar valores mA fuera del rango 4-20mA si es necesario.
|
||||||
|
"""
|
||||||
|
ma_str = ProtocolHandler.format_ma_value(ma_value) # Formato XX.XXX
|
||||||
|
message_part = f"#{adam_address}{ma_str}"
|
||||||
|
checksum = ProtocolHandler.calculate_checksum(message_part)
|
||||||
|
full_message_str = f"{message_part}{checksum}\r"
|
||||||
|
return full_message_str.encode('ascii'), ma_value
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ma_to_voltage(ma_value):
|
def ma_to_voltage(ma_value):
|
||||||
"""Convierte valor mA a Voltaje (0-10V). 0mA -> 0V, 20mA -> 10V."""
|
"""Convierte valor mA a Voltaje (0-10V). 0mA -> 0V, 20mA -> 10V."""
|
||||||
|
|
|
@ -315,15 +315,26 @@ class SimulatorTab:
|
||||||
final_ma = ProtocolHandler.voltage_to_ma(final_voltage)
|
final_ma = ProtocolHandler.voltage_to_ma(final_voltage)
|
||||||
final_brix = ProtocolHandler.ma_to_brix(final_ma, min_brix_map, max_brix_map)
|
final_brix = ProtocolHandler.ma_to_brix(final_ma, min_brix_map, max_brix_map)
|
||||||
|
|
||||||
message, calculated_ma_from_brix = ProtocolHandler.create_adam_message(adam_address, final_brix, min_brix_map, max_brix_map)
|
# Usar el nuevo método que toma ma_value directamente para el modo manual
|
||||||
|
message, returned_ma = ProtocolHandler.create_adam_message_from_ma(adam_address, final_ma)
|
||||||
|
|
||||||
# Actualizar display
|
# Actualizar display
|
||||||
self.current_brix_var.set(Utils.format_brix_display(final_brix))
|
brix_display_text = ""
|
||||||
self.current_ma_var.set(Utils.format_ma_display(final_ma))
|
# Si la entrada fue mA o Voltaje y el resultado es un mA < 4 (estado de error)
|
||||||
|
if (input_type == "mA" or input_type == "Voltaje") and final_ma < 4.0:
|
||||||
|
brix_display_text = "Error (Sub 4mA)"
|
||||||
|
else:
|
||||||
|
# Para entrada Brix, o mA/Voltaje que resultan en mA >= 4.0
|
||||||
|
brix_display_text = Utils.format_brix_display(final_brix)
|
||||||
|
|
||||||
|
self.current_brix_var.set(brix_display_text)
|
||||||
|
self.current_ma_var.set(Utils.format_ma_display(returned_ma)) # Usar returned_ma que es igual a final_ma
|
||||||
self.current_voltage_var.set(ProtocolHandler.format_voltage_display(final_voltage))
|
self.current_voltage_var.set(ProtocolHandler.format_voltage_display(final_voltage))
|
||||||
|
|
||||||
# Agregar al gráfico
|
# Agregar al gráfico
|
||||||
self.add_data_point(final_brix, final_ma)
|
# final_brix aquí es el valor numérico calculado (ej. min_brix_map si mA < 4),
|
||||||
|
# lo cual es consistente para el gráfico.
|
||||||
|
self.add_data_point(final_brix, returned_ma)
|
||||||
|
|
||||||
# Enviar por conexión temporal
|
# Enviar por conexión temporal
|
||||||
current_config_values = {
|
current_config_values = {
|
||||||
|
|
Loading…
Reference in New Issue