Files
Feeding_control_system/hardware/transmitter_device.py

32 lines
1.3 KiB
Python
Raw Normal View History

2026-04-07 09:51:38 +08:00
# hardware/transmitter.py
from pymodbus.exceptions import ModbusException
import socket
from config.ini_manager import ini_manager
from config.settings import app_set_config
import time
from metric_device import DeviceManager
from enum import Enum, unique
@unique
class HopperType(Enum):
UPPER = 1 # 上料斗
LOWER = 2 # 下料斗
class TransmitterController:
def __init__(self, relay_controller=None):
self.relay_controller = relay_controller
UPPER_HOPPER_IP = ini_manager.upper_transmitter_ip
UPPER_HOPPER_PORT = ini_manager.upper_transmitter_port
LOWER_HOPPER_IP = ini_manager.lower_transmitter_ip
LOWER_HOPPER_PORT = ini_manager.lower_transmitter_port
self.upper_scale = DeviceManager.get_device(UPPER_HOPPER_IP, UPPER_HOPPER_PORT, "upper_scale") # 上料斗
self.lower_scale = DeviceManager.get_device(LOWER_HOPPER_IP, LOWER_HOPPER_PORT, "lower_scale") # 下料斗
def read_data(self, transmitter_id):
"""获取重量函数:
Args: transmitter_id 为指定的上/下料斗的id
"""
if transmitter_id == HopperType.UPPER:
return self.upper_scale.get_valid_weight()
elif transmitter_id == HopperType.LOWER:
return self.lower_scale.get_valid_weight()