first commit
This commit is contained in:
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
10
.idea/Feeding_control_system.iml
generated
Normal file
10
.idea/Feeding_control_system.iml
generated
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="rob" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
7
.idea/misc.xml
generated
Normal file
7
.idea/misc.xml
generated
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.9 (Feeding_control_system)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="rob" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Feeding_control_system.iml" filepath="$PROJECT_DIR$/.idea/Feeding_control_system.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
44
config/config.yaml
Normal file
44
config/config.yaml
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# 网络配置
|
||||||
|
network:
|
||||||
|
relay:
|
||||||
|
host: "192.168.0.18"
|
||||||
|
port: 50000
|
||||||
|
inverter:
|
||||||
|
host: "192.168.0.20"
|
||||||
|
port: 502
|
||||||
|
slave_id: 1
|
||||||
|
transmitters:
|
||||||
|
upper:
|
||||||
|
host: "192.168.0.21"
|
||||||
|
port: 502
|
||||||
|
slave_id: 1
|
||||||
|
weight_register: 0
|
||||||
|
register_count: 2
|
||||||
|
lower:
|
||||||
|
host: "192.168.0.22"
|
||||||
|
port: 502
|
||||||
|
slave_id: 2
|
||||||
|
weight_register: 0
|
||||||
|
register_count: 2
|
||||||
|
|
||||||
|
# 系统参数
|
||||||
|
parameters:
|
||||||
|
min_required_weight: 50
|
||||||
|
max_error_count: 3
|
||||||
|
monitoring_interval: 1
|
||||||
|
timeout: 30
|
||||||
|
|
||||||
|
# 下料参数,频率
|
||||||
|
feeding:
|
||||||
|
stage1_frequency: 30.0
|
||||||
|
stage2_frequency: 40.0
|
||||||
|
stage3_frequency: 50.0
|
||||||
|
target_weight_per_stage: 33.3
|
||||||
|
|
||||||
|
# 继电器DO端口映射
|
||||||
|
relay:
|
||||||
|
door_upper: 0 # DO0 - 上料斗滑动门
|
||||||
|
door_lower_1: 1 # DO1 - 出砼门控制1
|
||||||
|
door_lower_2: 2 # DO2 - 出砼门控制2
|
||||||
|
break_arch_upper: 3 # DO3 - 上料斗破拱
|
||||||
|
break_arch_lower: 4 # DO4 - 下料斗破拱
|
||||||
5
src/__init__.py
Normal file
5
src/__init__.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from .control import feeding_controller,state_machine
|
||||||
|
from .divices import inverter,relay,transmitter
|
||||||
|
from .utils import config,logger
|
||||||
|
|
||||||
|
__all__ = ['FeedingController', 'FeedingStateMachine', 'FeedingState']
|
||||||
BIN
src/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
src/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
4
src/control/__init__.py
Normal file
4
src/control/__init__.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
from .feeding_controller import FeedingController
|
||||||
|
from .state_machine import FeedingStateMachine, FeedingState
|
||||||
|
|
||||||
|
__all__ = ['FeedingController', 'FeedingStateMachine', 'FeedingState']
|
||||||
BIN
src/control/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
src/control/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
src/control/__pycache__/feeding_controller.cpython-39.pyc
Normal file
BIN
src/control/__pycache__/feeding_controller.cpython-39.pyc
Normal file
Binary file not shown.
BIN
src/control/__pycache__/state_machine.cpython-39.pyc
Normal file
BIN
src/control/__pycache__/state_machine.cpython-39.pyc
Normal file
Binary file not shown.
325
src/control/feeding_controller.py
Normal file
325
src/control/feeding_controller.py
Normal file
@ -0,0 +1,325 @@
|
|||||||
|
import time
|
||||||
|
from src.utils.config import config
|
||||||
|
from src.utils.logger import app_logger
|
||||||
|
from src.divices.relay import RelayController
|
||||||
|
from src.divices.inverter import InverterController
|
||||||
|
from src.divices.transmitter import TransmitterController
|
||||||
|
from .state_machine import FeedingStateMachine, FeedingState
|
||||||
|
|
||||||
|
|
||||||
|
class FeedingController:
|
||||||
|
"""下料控制器"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.logger = app_logger.getChild('FeedingController')
|
||||||
|
self.state_machine = FeedingStateMachine()
|
||||||
|
|
||||||
|
# 初始化设备
|
||||||
|
self._initialize_devices()
|
||||||
|
|
||||||
|
# 系统参数
|
||||||
|
self.min_required_weight = config.get('parameters.min_required_weight', 50)
|
||||||
|
self.max_error_count = config.get('parameters.max_error_count', 3)
|
||||||
|
self.timeout = config.get('parameters.timeout', 30)
|
||||||
|
|
||||||
|
# 下料参数
|
||||||
|
self.stage_frequencies = {
|
||||||
|
1: config.get('feeding.stage1_frequency', 30.0),
|
||||||
|
2: config.get('feeding.stage2_frequency', 40.0),
|
||||||
|
3: config.get('feeding.stage3_frequency', 50.0)
|
||||||
|
}
|
||||||
|
self.target_weight_per_stage = config.get('feeding.target_weight_per_stage', 33.3)
|
||||||
|
|
||||||
|
# 状态
|
||||||
|
self.error_count = 0
|
||||||
|
self.last_upper_weight = 0
|
||||||
|
self.last_lower_weight = 0
|
||||||
|
self.last_weight_time = time.time()
|
||||||
|
|
||||||
|
def _initialize_devices(self):
|
||||||
|
"""初始化设备"""
|
||||||
|
try:
|
||||||
|
# 网络继电器
|
||||||
|
relay_config = config.get('network.relay')
|
||||||
|
self.relay = RelayController(
|
||||||
|
relay_config['host'],
|
||||||
|
relay_config['port']
|
||||||
|
)
|
||||||
|
|
||||||
|
# 设置继电器设备映射
|
||||||
|
relay_mapping = config.get('relay')
|
||||||
|
self.relay.set_device_mapping(relay_mapping)
|
||||||
|
|
||||||
|
# 变频器
|
||||||
|
inverter_config = config.get('network.inverter')
|
||||||
|
self.inverter = InverterController(
|
||||||
|
inverter_config['host'],
|
||||||
|
inverter_config['port'],
|
||||||
|
inverter_config['slave_id']
|
||||||
|
)
|
||||||
|
|
||||||
|
# 变送器
|
||||||
|
transmitters_config = config.get('network.transmitters')
|
||||||
|
|
||||||
|
self.upper_transmitter = TransmitterController(
|
||||||
|
'upper',
|
||||||
|
transmitters_config['upper']['host'],
|
||||||
|
transmitters_config['upper']['port'],
|
||||||
|
transmitters_config['upper']['slave_id']
|
||||||
|
)
|
||||||
|
self.upper_transmitter.set_config(
|
||||||
|
transmitters_config['upper']['weight_register'],
|
||||||
|
transmitters_config['upper']['register_count']
|
||||||
|
)
|
||||||
|
|
||||||
|
self.lower_transmitter = TransmitterController(
|
||||||
|
'lower',
|
||||||
|
transmitters_config['lower']['host'],
|
||||||
|
transmitters_config['lower']['port'],
|
||||||
|
transmitters_config['lower']['slave_id']
|
||||||
|
)
|
||||||
|
self.lower_transmitter.set_config(
|
||||||
|
transmitters_config['lower']['weight_register'],
|
||||||
|
transmitters_config['lower']['register_count']
|
||||||
|
)
|
||||||
|
|
||||||
|
self.logger.info("设备初始化完成")
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"设备初始化失败: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
def check_material_request(self):
|
||||||
|
"""检查是否需要向上料斗要料"""
|
||||||
|
current_weight = self.upper_transmitter.read_weight()
|
||||||
|
|
||||||
|
# 如果读取失败,增加错误计数
|
||||||
|
if current_weight is None:
|
||||||
|
self.error_count += 1
|
||||||
|
self.logger.warning(f"上料斗重量读取失败,错误计数: {self.error_count}")
|
||||||
|
|
||||||
|
# 如果连续错误次数超过阈值,触发报警
|
||||||
|
if self.error_count >= self.max_error_count:
|
||||||
|
self.logger.error("警告:上料斗重量传感器连续读取失败,请检查设备连接")
|
||||||
|
return False # 读取失败时不触发要料
|
||||||
|
|
||||||
|
# 重置错误计数
|
||||||
|
self.error_count = 0
|
||||||
|
|
||||||
|
if current_weight < self.min_required_weight:
|
||||||
|
self.logger.info("上料斗重量不足,通知搅拌楼要料")
|
||||||
|
self.move_upper_door_to_mixer()
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def move_upper_door_to_mixer(self):
|
||||||
|
"""移动上料斗到搅拌楼出砼口"""
|
||||||
|
self.logger.info("移动上料斗到搅拌楼出砼口")
|
||||||
|
self.relay.control('door_upper', 'open')
|
||||||
|
|
||||||
|
def return_upper_door(self):
|
||||||
|
"""返回上料斗"""
|
||||||
|
self.logger.info("上料斗返回原位")
|
||||||
|
self.relay.control('door_upper', 'close')
|
||||||
|
|
||||||
|
def start_feeding(self):
|
||||||
|
"""开始下料过程"""
|
||||||
|
if self.state_machine.get_state() != FeedingState.IDLE:
|
||||||
|
self.logger.warning("下料已在进行中")
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.logger.info("开始三阶段下料过程")
|
||||||
|
self.state_machine.set_state(FeedingState.STAGE_ONE)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def execute_stage_one(self):
|
||||||
|
"""执行第一阶段下料"""
|
||||||
|
self.logger.info("开始第一阶段下料 (1/3)")
|
||||||
|
|
||||||
|
# 设置变频器频率
|
||||||
|
frequency = self.stage_frequencies[1]
|
||||||
|
if not self.inverter.set_frequency(frequency):
|
||||||
|
self.logger.error("设置变频器频率失败")
|
||||||
|
self.finish_feeding()
|
||||||
|
return
|
||||||
|
|
||||||
|
# 启动变频器
|
||||||
|
if not self.inverter.control('start'):
|
||||||
|
self.logger.error("启动变频器失败")
|
||||||
|
self.finish_feeding()
|
||||||
|
return
|
||||||
|
|
||||||
|
# 控制出砼门
|
||||||
|
self.relay.control('door_lower_1', 'open')
|
||||||
|
self.relay.control('door_lower_2', 'open')
|
||||||
|
|
||||||
|
# 监控下料过程
|
||||||
|
start_time = time.time()
|
||||||
|
initial_weight = self.lower_transmitter.read_weight()
|
||||||
|
|
||||||
|
# 如果初始重量读取失败,取消操作
|
||||||
|
if initial_weight is None:
|
||||||
|
self.logger.error("无法获取初始重量,取消下料操作")
|
||||||
|
self.finish_feeding()
|
||||||
|
return
|
||||||
|
|
||||||
|
target_weight = initial_weight + self.target_weight_per_stage
|
||||||
|
|
||||||
|
while self.state_machine.get_state() == FeedingState.STAGE_ONE:
|
||||||
|
current_weight = self.lower_transmitter.read_weight()
|
||||||
|
|
||||||
|
# 检查重量读取是否成功
|
||||||
|
if current_weight is None:
|
||||||
|
self.error_count += 1
|
||||||
|
if self.error_count >= self.max_error_count:
|
||||||
|
self.logger.error("下料斗重量传感器连续读取失败,停止下料")
|
||||||
|
self.finish_feeding()
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self.error_count = 0 # 重置错误计数
|
||||||
|
|
||||||
|
# 检查是否达到目标重量或超时
|
||||||
|
if (current_weight is not None and current_weight >= target_weight) or \
|
||||||
|
(time.time() - start_time) > self.timeout:
|
||||||
|
self.state_machine.set_state(FeedingState.STAGE_TWO)
|
||||||
|
break
|
||||||
|
|
||||||
|
time.sleep(2) # 每2秒读取一次
|
||||||
|
|
||||||
|
def execute_stage_two(self):
|
||||||
|
"""执行第二阶段下料"""
|
||||||
|
self.logger.info("开始第二阶段下料 (2/3)")
|
||||||
|
|
||||||
|
# 调整变频器频率
|
||||||
|
frequency = self.stage_frequencies[2]
|
||||||
|
if not self.inverter.set_frequency(frequency):
|
||||||
|
self.logger.error("设置变频器频率失败")
|
||||||
|
self.finish_feeding()
|
||||||
|
return
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
|
initial_weight = self.lower_transmitter.read_weight()
|
||||||
|
|
||||||
|
if initial_weight is None:
|
||||||
|
self.logger.error("无法获取初始重量,取消下料操作")
|
||||||
|
self.finish_feeding()
|
||||||
|
return
|
||||||
|
|
||||||
|
target_weight = initial_weight + self.target_weight_per_stage
|
||||||
|
|
||||||
|
while self.state_machine.get_state() == FeedingState.STAGE_TWO:
|
||||||
|
current_weight = self.lower_transmitter.read_weight()
|
||||||
|
|
||||||
|
if current_weight is None:
|
||||||
|
self.error_count += 1
|
||||||
|
if self.error_count >= self.max_error_count:
|
||||||
|
self.logger.error("下料斗重量传感器连续读取失败,停止下料")
|
||||||
|
self.finish_feeding()
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self.error_count = 0
|
||||||
|
|
||||||
|
if (current_weight is not None and current_weight >= target_weight) or \
|
||||||
|
(time.time() - start_time) > self.timeout:
|
||||||
|
self.state_machine.set_state(FeedingState.STAGE_THREE)
|
||||||
|
break
|
||||||
|
|
||||||
|
time.sleep(2) # 每2秒读取一次
|
||||||
|
|
||||||
|
def execute_stage_three(self):
|
||||||
|
"""执行第三阶段下料"""
|
||||||
|
self.logger.info("开始第三阶段下料 (3/3)")
|
||||||
|
|
||||||
|
# 调整变频器频率
|
||||||
|
frequency = self.stage_frequencies[3]
|
||||||
|
if not self.inverter.set_frequency(frequency):
|
||||||
|
self.logger.error("设置变频器频率失败")
|
||||||
|
self.finish_feeding()
|
||||||
|
return
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
|
initial_weight = self.lower_transmitter.read_weight()
|
||||||
|
|
||||||
|
if initial_weight is None:
|
||||||
|
self.logger.error("无法获取初始重量,取消下料操作")
|
||||||
|
self.finish_feeding()
|
||||||
|
return
|
||||||
|
|
||||||
|
target_weight = initial_weight + self.target_weight_per_stage
|
||||||
|
|
||||||
|
while self.state_machine.get_state() == FeedingState.STAGE_THREE:
|
||||||
|
current_weight = self.lower_transmitter.read_weight()
|
||||||
|
|
||||||
|
if current_weight is None:
|
||||||
|
self.error_count += 1
|
||||||
|
if self.error_count >= self.max_error_count:
|
||||||
|
self.logger.error("下料斗重量传感器连续读取失败,停止下料")
|
||||||
|
self.finish_feeding()
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self.error_count = 0
|
||||||
|
|
||||||
|
if (current_weight is not None and current_weight >= target_weight) or \
|
||||||
|
(time.time() - start_time) > self.timeout:
|
||||||
|
self.state_machine.set_state(FeedingState.COMPLETED)
|
||||||
|
break
|
||||||
|
|
||||||
|
time.sleep(2) # 每2秒读取一次
|
||||||
|
|
||||||
|
def finish_feeding(self):
|
||||||
|
"""完成下料"""
|
||||||
|
self.logger.info("下料完成,关闭出砼门")
|
||||||
|
self.inverter.control('stop')
|
||||||
|
self.relay.control('door_lower_1', 'close')
|
||||||
|
self.relay.control('door_lower_2', 'close')
|
||||||
|
self.state_machine.set_state(FeedingState.IDLE)
|
||||||
|
self.error_count = 0
|
||||||
|
|
||||||
|
def check_arch_blocking(self):
|
||||||
|
"""检查是否需要破拱"""
|
||||||
|
current_time = time.time()
|
||||||
|
|
||||||
|
# 检查上料斗
|
||||||
|
upper_weight = self.upper_transmitter.read_weight()
|
||||||
|
if upper_weight is not None:
|
||||||
|
if (abs(upper_weight - self.last_upper_weight) < 0.1) and \
|
||||||
|
(current_time - self.last_weight_time) > 10:
|
||||||
|
self.logger.info("上料斗可能堵塞,启动破拱")
|
||||||
|
self.relay.control('break_arch_upper', 'open')
|
||||||
|
time.sleep(2)
|
||||||
|
self.relay.control('break_arch_upper', 'close')
|
||||||
|
|
||||||
|
# 检查下料斗
|
||||||
|
lower_weight = self.lower_transmitter.read_weight()
|
||||||
|
if lower_weight is not None:
|
||||||
|
if (abs(lower_weight - self.last_lower_weight) < 0.1) and \
|
||||||
|
(current_time - self.last_weight_time) > 10:
|
||||||
|
self.logger.info("下料斗可能堵塞,启动破拱")
|
||||||
|
self.relay.control('break_arch_lower', 'open')
|
||||||
|
time.sleep(2)
|
||||||
|
self.relay.control('break_arch_lower', 'close')
|
||||||
|
|
||||||
|
# 更新重量记录
|
||||||
|
if upper_weight is not None:
|
||||||
|
self.last_upper_weight = upper_weight
|
||||||
|
if lower_weight is not None:
|
||||||
|
self.last_lower_weight = lower_weight
|
||||||
|
|
||||||
|
if upper_weight is not None or lower_weight is not None:
|
||||||
|
self.last_weight_time = current_time
|
||||||
|
|
||||||
|
def run_cycle(self):
|
||||||
|
"""运行一个控制周期"""
|
||||||
|
try:
|
||||||
|
# 检查是否需要要料
|
||||||
|
self.check_material_request()
|
||||||
|
|
||||||
|
# 检查破拱
|
||||||
|
self.check_arch_blocking()
|
||||||
|
|
||||||
|
# 执行状态机
|
||||||
|
self.state_machine.transition(self)
|
||||||
|
|
||||||
|
return True
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"控制周期执行错误: {e}")
|
||||||
|
return False
|
||||||
105
src/control/state_machine.py
Normal file
105
src/control/state_machine.py
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
from enum import Enum
|
||||||
|
from src.utils.logger import app_logger
|
||||||
|
|
||||||
|
|
||||||
|
class FeedingState(Enum):
|
||||||
|
"""下料状态枚举"""
|
||||||
|
IDLE = 0
|
||||||
|
STAGE_ONE = 1
|
||||||
|
STAGE_TWO = 2
|
||||||
|
STAGE_THREE = 3
|
||||||
|
COMPLETED = 4
|
||||||
|
|
||||||
|
|
||||||
|
class State(ABC):
|
||||||
|
"""状态基类"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.logger = app_logger.getChild('StateMachine')
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def handle(self, context):
|
||||||
|
"""处理状态逻辑"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class IdleState(State):
|
||||||
|
"""空闲状态"""
|
||||||
|
|
||||||
|
def handle(self, context):
|
||||||
|
self.logger.info("系统处于空闲状态")
|
||||||
|
# 等待开始下料命令
|
||||||
|
return FeedingState.IDLE
|
||||||
|
|
||||||
|
|
||||||
|
class StageOneState(State):
|
||||||
|
"""第一阶段下料状态"""
|
||||||
|
|
||||||
|
def handle(self, context):
|
||||||
|
self.logger.info("执行第一阶段下料")
|
||||||
|
# 第一阶段下料逻辑
|
||||||
|
context.execute_stage_one()
|
||||||
|
return FeedingState.STAGE_TWO
|
||||||
|
|
||||||
|
|
||||||
|
class StageTwoState(State):
|
||||||
|
"""第二阶段下料状态"""
|
||||||
|
|
||||||
|
def handle(self, context):
|
||||||
|
self.logger.info("执行第二阶段下料")
|
||||||
|
# 第二阶段下料逻辑
|
||||||
|
context.execute_stage_two()
|
||||||
|
return FeedingState.STAGE_THREE
|
||||||
|
|
||||||
|
|
||||||
|
class StageThreeState(State):
|
||||||
|
"""第三阶段下料状态"""
|
||||||
|
|
||||||
|
def handle(self, context):
|
||||||
|
self.logger.info("执行第三阶段下料")
|
||||||
|
# 第三阶段下料逻辑
|
||||||
|
context.execute_stage_three()
|
||||||
|
return FeedingState.COMPLETED
|
||||||
|
|
||||||
|
|
||||||
|
class CompletedState(State):
|
||||||
|
"""完成状态"""
|
||||||
|
|
||||||
|
def handle(self, context):
|
||||||
|
self.logger.info("下料完成")
|
||||||
|
# 完成逻辑
|
||||||
|
context.finish_feeding()
|
||||||
|
return FeedingState.IDLE
|
||||||
|
|
||||||
|
|
||||||
|
class FeedingStateMachine:
|
||||||
|
"""下料状态机"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.states = {
|
||||||
|
FeedingState.IDLE: IdleState(),
|
||||||
|
FeedingState.STAGE_ONE: StageOneState(),
|
||||||
|
FeedingState.STAGE_TWO: StageTwoState(),
|
||||||
|
FeedingState.STAGE_THREE: StageThreeState(),
|
||||||
|
FeedingState.COMPLETED: CompletedState()
|
||||||
|
}
|
||||||
|
self.current_state = FeedingState.IDLE
|
||||||
|
self.logger = app_logger.getChild('FeedingStateMachine')
|
||||||
|
|
||||||
|
def transition(self, context):
|
||||||
|
"""状态转换"""
|
||||||
|
if self.current_state in self.states:
|
||||||
|
next_state = self.states[self.current_state].handle(context)
|
||||||
|
if next_state != self.current_state:
|
||||||
|
self.logger.info(f"状态从 {self.current_state} 转换到 {next_state}")
|
||||||
|
self.current_state = next_state
|
||||||
|
|
||||||
|
def set_state(self, state: FeedingState):
|
||||||
|
"""设置当前状态"""
|
||||||
|
self.logger.info(f"手动设置状态为 {state}")
|
||||||
|
self.current_state = state
|
||||||
|
|
||||||
|
def get_state(self):
|
||||||
|
"""获取当前状态"""
|
||||||
|
return self.current_state
|
||||||
5
src/divices/__init__.py
Normal file
5
src/divices/__init__.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from .relay import RelayController
|
||||||
|
from .inverter import InverterController
|
||||||
|
from .transmitter import TransmitterController
|
||||||
|
|
||||||
|
__all__ = ['RelayController', 'InverterController', 'TransmitterController']
|
||||||
BIN
src/divices/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
src/divices/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
src/divices/__pycache__/inverter.cpython-39.pyc
Normal file
BIN
src/divices/__pycache__/inverter.cpython-39.pyc
Normal file
Binary file not shown.
BIN
src/divices/__pycache__/relay.cpython-39.pyc
Normal file
BIN
src/divices/__pycache__/relay.cpython-39.pyc
Normal file
Binary file not shown.
BIN
src/divices/__pycache__/transmitter.cpython-39.pyc
Normal file
BIN
src/divices/__pycache__/transmitter.cpython-39.pyc
Normal file
Binary file not shown.
96
src/divices/inverter.py
Normal file
96
src/divices/inverter.py
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
from pymodbus.client import ModbusTcpClient
|
||||||
|
from pymodbus.exceptions import ModbusException
|
||||||
|
from src.utils.logger import app_logger
|
||||||
|
|
||||||
|
|
||||||
|
class InverterController:
|
||||||
|
"""变频器控制器"""
|
||||||
|
|
||||||
|
def __init__(self, host: str, port: int, slave_id: int = 1):
|
||||||
|
self.host = host
|
||||||
|
self.port = port
|
||||||
|
self.slave_id = slave_id
|
||||||
|
self.client = None
|
||||||
|
self.logger = app_logger.getChild('InverterController')
|
||||||
|
|
||||||
|
# 变频器寄存器地址
|
||||||
|
self.registers = {
|
||||||
|
'frequency': 0x01, # 频率设置寄存器
|
||||||
|
'start': 0x00, # 启动命令寄存器
|
||||||
|
'stop': 0x01 # 停止命令寄存器
|
||||||
|
}
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
"""连接变频器"""
|
||||||
|
try:
|
||||||
|
self.client = ModbusTcpClient(self.host, port=self.port)
|
||||||
|
return self.client.connect()
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"连接变频器失败: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def disconnect(self):
|
||||||
|
"""断开变频器连接"""
|
||||||
|
if self.client:
|
||||||
|
try:
|
||||||
|
self.client.close()
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"断开变频器连接失败: {e}")
|
||||||
|
|
||||||
|
def set_frequency(self, frequency: float):
|
||||||
|
"""设置变频器频率"""
|
||||||
|
if not self.client:
|
||||||
|
if not self.connect():
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
# 写入频率值 (假设频率值需要转换为Hz*10)
|
||||||
|
result = self.client.write_register(
|
||||||
|
self.registers['frequency'],
|
||||||
|
int(frequency * 10),
|
||||||
|
slave=self.slave_id
|
||||||
|
)
|
||||||
|
|
||||||
|
if isinstance(result, Exception):
|
||||||
|
self.logger.error(f"设置变频器频率失败: {result}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.logger.info(f"设置变频器频率为 {frequency}Hz")
|
||||||
|
return True
|
||||||
|
except ModbusException as e:
|
||||||
|
self.logger.error(f"变频器Modbus通信错误: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def control(self, action: str):
|
||||||
|
"""控制变频器启停"""
|
||||||
|
if not self.client:
|
||||||
|
if not self.connect():
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
if action == 'start':
|
||||||
|
result = self.client.write_register(
|
||||||
|
self.registers['start'],
|
||||||
|
1,
|
||||||
|
slave=self.slave_id
|
||||||
|
)
|
||||||
|
self.logger.info("启动变频器")
|
||||||
|
elif action == 'stop':
|
||||||
|
result = self.client.write_register(
|
||||||
|
self.registers['stop'],
|
||||||
|
1,
|
||||||
|
slave=self.slave_id
|
||||||
|
)
|
||||||
|
self.logger.info("停止变频器")
|
||||||
|
else:
|
||||||
|
self.logger.error(f"无效的变频器操作: {action}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if isinstance(result, Exception):
|
||||||
|
self.logger.error(f"控制变频器失败: {result}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
except ModbusException as e:
|
||||||
|
self.logger.error(f"变频器控制错误: {e}")
|
||||||
|
return False
|
||||||
85
src/divices/relay.py
Normal file
85
src/divices/relay.py
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import socket
|
||||||
|
import binascii
|
||||||
|
import time
|
||||||
|
from src.utils.logger import app_logger
|
||||||
|
|
||||||
|
|
||||||
|
class RelayController:
|
||||||
|
"""网络继电器控制器"""
|
||||||
|
|
||||||
|
def __init__(self, host: str, port: int):
|
||||||
|
self.host = host
|
||||||
|
self.port = port
|
||||||
|
self.logger = app_logger.getChild('RelayController')
|
||||||
|
|
||||||
|
# 设备DO端口映射 (将在初始化时从配置加载)
|
||||||
|
self.device_mapping = {}
|
||||||
|
|
||||||
|
# 继电器控制命令
|
||||||
|
self.relay_commands = {
|
||||||
|
0: {'open': '00000000000601050000FF00', 'close': '000000000006010500000000'},
|
||||||
|
1: {'open': '00000000000601050001FF00', 'close': '000000000006010500010000'},
|
||||||
|
2: {'open': '00000000000601050002FF00', 'close': '000000000006010500020000'},
|
||||||
|
3: {'open': '00000000000601050003FF00', 'close': '000000000006010500030000'},
|
||||||
|
4: {'open': '00000000000601050004FF00', 'close': '000000000006010500040000'}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 读取状态命令
|
||||||
|
self.read_status_command = '000000000006010100000008'
|
||||||
|
|
||||||
|
def set_device_mapping(self, mapping: dict):
|
||||||
|
"""设置设备映射"""
|
||||||
|
self.device_mapping = mapping
|
||||||
|
|
||||||
|
def send_command(self, command_hex: str):
|
||||||
|
"""发送命令到网络继电器"""
|
||||||
|
try:
|
||||||
|
byte_data = binascii.unhexlify(command_hex)
|
||||||
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||||
|
sock.settimeout(5) # 设置超时
|
||||||
|
sock.connect((self.host, self.port))
|
||||||
|
sock.send(byte_data)
|
||||||
|
response = sock.recv(1024)
|
||||||
|
self.logger.debug(f"收到继电器响应: {binascii.hexlify(response)}")
|
||||||
|
return response
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"继电器通信错误: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_status(self):
|
||||||
|
"""获取继电器状态"""
|
||||||
|
response = self.send_command(self.read_status_command)
|
||||||
|
status_dict = {}
|
||||||
|
|
||||||
|
if response and len(response) >= 10:
|
||||||
|
status_byte = response[9]
|
||||||
|
status_bin = f"{status_byte:08b}"[::-1]
|
||||||
|
|
||||||
|
# 根据设备映射返回状态
|
||||||
|
for device_name, bit_index in self.device_mapping.items():
|
||||||
|
status_dict[device_name] = status_bin[bit_index] == '1'
|
||||||
|
else:
|
||||||
|
self.logger.warning("读取继电器状态失败或响应无效")
|
||||||
|
|
||||||
|
return status_dict
|
||||||
|
|
||||||
|
def control(self, device_name: str, action: str):
|
||||||
|
"""控制继电器开关"""
|
||||||
|
if device_name not in self.device_mapping:
|
||||||
|
self.logger.error(f"无效的继电器设备: {device_name}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
bit_index = self.device_mapping[device_name]
|
||||||
|
|
||||||
|
if bit_index not in self.relay_commands:
|
||||||
|
self.logger.error(f"不支持的DO端口: {bit_index}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
if action not in self.relay_commands[bit_index]:
|
||||||
|
self.logger.error(f"无效的继电器动作: {action}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.logger.info(f"控制继电器 {device_name} ({bit_index}) {action}")
|
||||||
|
result = self.send_command(self.relay_commands[bit_index][action])
|
||||||
|
time.sleep(0.1) # 短暂延迟确保命令执行
|
||||||
|
return result is not None
|
||||||
82
src/divices/transmitter.py
Normal file
82
src/divices/transmitter.py
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
from pymodbus.client import ModbusTcpClient
|
||||||
|
from pymodbus.exceptions import ModbusException
|
||||||
|
import struct
|
||||||
|
from src.utils.logger import app_logger
|
||||||
|
|
||||||
|
|
||||||
|
class TransmitterController:
|
||||||
|
"""重量变送器控制器"""
|
||||||
|
|
||||||
|
def __init__(self, name: str, host: str, port: int, slave_id: int = 1):
|
||||||
|
self.name = name
|
||||||
|
self.host = host
|
||||||
|
self.port = port
|
||||||
|
self.slave_id = slave_id
|
||||||
|
self.client = None
|
||||||
|
self.logger = app_logger.getChild(f'TransmitterController.{name}')
|
||||||
|
|
||||||
|
# 默认配置
|
||||||
|
self.weight_register = 0
|
||||||
|
self.register_count = 2
|
||||||
|
|
||||||
|
def set_config(self, weight_register: int, register_count: int):
|
||||||
|
"""设置变送器配置"""
|
||||||
|
self.weight_register = weight_register
|
||||||
|
self.register_count = register_count
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
"""连接变送器"""
|
||||||
|
try:
|
||||||
|
self.client = ModbusTcpClient(self.host, port=self.port)
|
||||||
|
return self.client.connect()
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"连接变送器 {self.name} 失败: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def disconnect(self):
|
||||||
|
"""断开变送器连接"""
|
||||||
|
if self.client:
|
||||||
|
try:
|
||||||
|
self.client.close()
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"断开变送器 {self.name} 连接失败: {e}")
|
||||||
|
|
||||||
|
def read_weight(self):
|
||||||
|
"""读取重量数据"""
|
||||||
|
if not self.client:
|
||||||
|
if not self.connect():
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
# 读取保持寄存器
|
||||||
|
result = self.client.read_holding_registers(
|
||||||
|
address=self.weight_register,
|
||||||
|
count=self.register_count,
|
||||||
|
slave=self.slave_id
|
||||||
|
)
|
||||||
|
|
||||||
|
if isinstance(result, Exception):
|
||||||
|
self.logger.error(f"读取变送器 {self.name} 数据失败: {result}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
# 解析重量数据
|
||||||
|
if self.register_count == 2:
|
||||||
|
# 组合两个寄存器为32位浮点数 (大端序)
|
||||||
|
weight_bytes = struct.pack('>HH', result.registers[0], result.registers[1])
|
||||||
|
weight = struct.unpack('>f', weight_bytes)[0]
|
||||||
|
elif self.register_count == 1:
|
||||||
|
# 单个寄存器直接作为整数
|
||||||
|
weight = float(result.registers[0])
|
||||||
|
else:
|
||||||
|
self.logger.error(f"不支持的寄存器数量: {self.register_count}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
self.logger.debug(f"变送器 {self.name} 读取重量: {weight}kg")
|
||||||
|
return weight
|
||||||
|
|
||||||
|
except ModbusException as e:
|
||||||
|
self.logger.error(f"变送器 {self.name} Modbus通信错误: {e}")
|
||||||
|
return None
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"变送器 {self.name} 数据解析错误: {e}")
|
||||||
|
return None
|
||||||
120
src/logs/app.log
Normal file
120
src/logs/app.log
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
2025-09-12 19:40:44,426 - FeedingControl.FeedingController - INFO - <20>豸<EFBFBD><E8B1B8>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:40:44,426 - FeedingControl.FeedingController - INFO - <20>豸<EFBFBD><E8B1B8>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:40:44,426 - FeedingControl.MainSystem - INFO - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:40:44,426 - FeedingControl.MainSystem - INFO - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:40:44,426 - FeedingControl.MainSystem - INFO - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ
|
||||||
|
2025-09-12 19:40:44,426 - FeedingControl.MainSystem - INFO - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ
|
||||||
|
2025-09-12 19:40:47,438 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 1
|
||||||
|
2025-09-12 19:40:47,438 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 1
|
||||||
|
2025-09-12 19:40:50,453 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-12 19:40:50,453 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-12 19:40:53,476 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-12 19:40:53,476 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-12 19:40:57,499 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-12 19:40:57,499 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-12 19:40:57,499 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 2
|
||||||
|
2025-09-12 19:40:57,499 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 2
|
||||||
|
2025-09-12 19:41:00,500 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-12 19:41:00,500 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-12 19:41:03,500 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-12 19:41:03,500 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-12 19:41:03,500 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-12 19:41:03,500 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-12 19:41:07,507 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-12 19:41:07,507 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-12 19:41:07,507 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 3
|
||||||
|
2025-09-12 19:41:07,507 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 3
|
||||||
|
2025-09-12 19:41:07,507 - FeedingControl.FeedingController - ERROR - <20><><EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:41:07,507 - FeedingControl.FeedingController - ERROR - <20><><EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:41:10,516 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-12 19:41:10,516 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-12 19:41:13,529 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-12 19:41:13,529 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-12 19:41:13,529 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-12 19:41:13,529 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-12 19:41:17,535 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-12 19:41:17,535 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-12 19:41:17,535 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 4
|
||||||
|
2025-09-12 19:41:17,535 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 4
|
||||||
|
2025-09-12 19:41:17,535 - FeedingControl.FeedingController - ERROR - <20><><EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:41:17,535 - FeedingControl.FeedingController - ERROR - <20><><EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:42:04,120 - FeedingControl.FeedingController - INFO - <20>豸<EFBFBD><E8B1B8>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:42:04,120 - FeedingControl.FeedingController - INFO - <20>豸<EFBFBD><E8B1B8>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:42:04,120 - FeedingControl.MainSystem - INFO - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:42:04,120 - FeedingControl.MainSystem - INFO - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:42:04,120 - FeedingControl.MainSystem - INFO - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ
|
||||||
|
2025-09-12 19:42:04,120 - FeedingControl.MainSystem - INFO - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ
|
||||||
|
2025-09-12 19:42:07,124 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 1
|
||||||
|
2025-09-12 19:42:07,124 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 1
|
||||||
|
2025-09-12 19:42:10,125 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-12 19:42:10,125 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:35:50,544 - FeedingControl.FeedingController - INFO - <20>豸<EFBFBD><E8B1B8>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-13 10:35:50,544 - FeedingControl.FeedingController - INFO - <20>豸<EFBFBD><E8B1B8>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-13 10:35:50,546 - FeedingControl.MainSystem - INFO - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-13 10:35:50,546 - FeedingControl.MainSystem - INFO - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-13 10:35:50,546 - FeedingControl.MainSystem - INFO - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ
|
||||||
|
2025-09-13 10:35:50,546 - FeedingControl.MainSystem - INFO - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ
|
||||||
|
2025-09-13 10:35:53,550 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 1
|
||||||
|
2025-09-13 10:35:53,550 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 1
|
||||||
|
2025-09-13 10:35:56,552 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:35:56,552 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:35:59,555 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-13 10:35:59,555 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-13 10:36:03,566 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:03,566 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:03,566 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 2
|
||||||
|
2025-09-13 10:36:03,566 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 2
|
||||||
|
2025-09-13 10:36:06,573 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:06,573 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:09,582 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-13 10:36:09,582 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-13 10:36:09,582 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-13 10:36:09,582 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-13 10:36:13,601 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:13,601 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:13,601 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 3
|
||||||
|
2025-09-13 10:36:13,601 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 3
|
||||||
|
2025-09-13 10:36:13,601 - FeedingControl.FeedingController - ERROR - <20><><EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||||
|
2025-09-13 10:36:13,601 - FeedingControl.FeedingController - ERROR - <20><><EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||||
|
2025-09-13 10:36:16,602 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:16,602 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:19,617 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-13 10:36:19,617 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-13 10:36:19,617 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-13 10:36:19,617 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-13 10:36:23,626 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:23,626 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:23,626 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 4
|
||||||
|
2025-09-13 10:36:23,626 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 4
|
||||||
|
2025-09-13 10:36:23,626 - FeedingControl.FeedingController - ERROR - <20><><EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||||
|
2025-09-13 10:36:23,626 - FeedingControl.FeedingController - ERROR - <20><><EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||||
|
2025-09-13 10:36:26,638 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:26,638 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:29,640 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-13 10:36:29,640 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-13 10:36:29,640 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-13 10:36:29,640 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-13 10:36:33,662 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:33,662 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:33,663 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 5
|
||||||
|
2025-09-13 10:36:33,663 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 5
|
||||||
|
2025-09-13 10:36:33,663 - FeedingControl.FeedingController - ERROR - <20><><EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||||
|
2025-09-13 10:36:33,663 - FeedingControl.FeedingController - ERROR - <20><><EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||||
|
2025-09-13 10:36:36,672 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:36,672 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:39,685 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-13 10:36:39,685 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-13 10:36:39,685 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-13 10:36:39,685 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-13 10:36:43,711 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:43,711 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:43,711 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 6
|
||||||
|
2025-09-13 10:36:43,711 - FeedingControl.FeedingController - WARNING - <20><><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: 6
|
||||||
|
2025-09-13 10:36:43,711 - FeedingControl.FeedingController - ERROR - <20><><EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||||
|
2025-09-13 10:36:43,711 - FeedingControl.FeedingController - ERROR - <20><><EFBFBD>棺<EFBFBD><E6A3BA><EFBFBD>϶<EFBFBD><CFB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡʧ<C8A1>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||||
|
2025-09-13 10:36:46,715 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:46,715 - FeedingControl.TransmitterController.upper - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> upper Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.21:502]
|
||||||
|
2025-09-13 10:36:49,725 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-13 10:36:49,725 - FeedingControl.TransmitterController.lower - ERROR - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lower Modbusͨ<73>Ŵ<EFBFBD><C5B4><EFBFBD>: Modbus Error: [Connection] Failed to connect[ModbusTcpClient 192.168.0.22:502]
|
||||||
|
2025-09-13 10:36:49,725 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
|
2025-09-13 10:36:49,725 - FeedingControl.StateMachine - INFO - ϵͳ<CFB5><CDB3><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>״̬
|
||||||
84
src/main.py
Normal file
84
src/main.py
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
import time
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
|
from utils.config import config
|
||||||
|
from utils.logger import app_logger
|
||||||
|
from control.feeding_controller import FeedingController
|
||||||
|
|
||||||
|
|
||||||
|
class FeedingControlSystem:
|
||||||
|
"""主控制系统"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.logger = app_logger.getChild('MainSystem')
|
||||||
|
self.running = False
|
||||||
|
self.controller = None
|
||||||
|
self._setup_signal_handlers()
|
||||||
|
self._initialize_controller()
|
||||||
|
|
||||||
|
def _setup_signal_handlers(self):
|
||||||
|
"""设置信号处理器"""
|
||||||
|
signal.signal(signal.SIGINT, self._signal_handler)
|
||||||
|
signal.signal(signal.SIGTERM, self._signal_handler)
|
||||||
|
|
||||||
|
def _signal_handler(self, signum, frame):
|
||||||
|
"""信号处理函数"""
|
||||||
|
self.logger.info(f"收到信号 {signum},正在停止系统...")
|
||||||
|
self.stop()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
def _initialize_controller(self):
|
||||||
|
"""初始化控制器"""
|
||||||
|
try:
|
||||||
|
self.controller = FeedingController()
|
||||||
|
self.logger.info("控制器初始化完成")
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"控制器初始化失败: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
"""启动系统"""
|
||||||
|
if self.running:
|
||||||
|
self.logger.warning("系统已在运行")
|
||||||
|
return
|
||||||
|
|
||||||
|
self.logger.info("启动控制系统")
|
||||||
|
self.running = True
|
||||||
|
|
||||||
|
# 主循环
|
||||||
|
monitoring_interval = config.get('parameters.monitoring_interval', 1)
|
||||||
|
|
||||||
|
while self.running:
|
||||||
|
try:
|
||||||
|
if self.controller:
|
||||||
|
self.controller.run_cycle()
|
||||||
|
time.sleep(monitoring_interval)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"系统运行错误: {e}")
|
||||||
|
time.sleep(monitoring_interval)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
"""停止系统"""
|
||||||
|
if not self.running:
|
||||||
|
self.logger.warning("系统未在运行")
|
||||||
|
return
|
||||||
|
|
||||||
|
self.logger.info("停止控制系统")
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
self.logger.info("控制系统已停止")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""主函数"""
|
||||||
|
try:
|
||||||
|
system = FeedingControlSystem()
|
||||||
|
system.start()
|
||||||
|
except Exception as e:
|
||||||
|
app_logger.error(f"系统启动失败: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
4
src/utils/__init__.py
Normal file
4
src/utils/__init__.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
from .config import Config
|
||||||
|
from .logger import setup_logger
|
||||||
|
|
||||||
|
__all__ = ['Config', 'setup_logger']
|
||||||
BIN
src/utils/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
src/utils/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
BIN
src/utils/__pycache__/config.cpython-39.pyc
Normal file
BIN
src/utils/__pycache__/config.cpython-39.pyc
Normal file
Binary file not shown.
BIN
src/utils/__pycache__/logger.cpython-39.pyc
Normal file
BIN
src/utils/__pycache__/logger.cpython-39.pyc
Normal file
Binary file not shown.
39
src/utils/config.py
Normal file
39
src/utils/config.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import yaml
|
||||||
|
import os
|
||||||
|
from typing import Dict, Any
|
||||||
|
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
"""配置管理类"""
|
||||||
|
|
||||||
|
def __init__(self, config_path: str = "D:\pycharmproject\Feeding_control_system\config\config.yaml"):
|
||||||
|
self.config_path = config_path
|
||||||
|
self._config = self._load_config()
|
||||||
|
|
||||||
|
def _load_config(self) -> Dict[str, Any]:
|
||||||
|
"""加载配置文件"""
|
||||||
|
if not os.path.exists(self.config_path):
|
||||||
|
raise FileNotFoundError(f"配置文件不存在: {self.config_path}")
|
||||||
|
|
||||||
|
with open(self.config_path, 'r', encoding='utf-8') as file:
|
||||||
|
return yaml.safe_load(file)
|
||||||
|
|
||||||
|
def get(self, key_path: str, default=None):
|
||||||
|
"""获取配置值,支持点号分隔的路径"""
|
||||||
|
keys = key_path.split('.')
|
||||||
|
value = self._config
|
||||||
|
|
||||||
|
try:
|
||||||
|
for key in keys:
|
||||||
|
value = value[key]
|
||||||
|
return value
|
||||||
|
except (KeyError, TypeError):
|
||||||
|
return default
|
||||||
|
|
||||||
|
def reload(self):
|
||||||
|
"""重新加载配置"""
|
||||||
|
self._config = self._load_config()
|
||||||
|
|
||||||
|
|
||||||
|
# 全局配置实例
|
||||||
|
config = Config()
|
||||||
33
src/utils/logger.py
Normal file
33
src/utils/logger.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def setup_logger(name, log_file, level=logging.INFO):
|
||||||
|
"""设置日志记录器"""
|
||||||
|
formatter = logging.Formatter(
|
||||||
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||||
|
)
|
||||||
|
|
||||||
|
# 确保日志目录存在
|
||||||
|
log_dir = os.path.dirname(log_file)
|
||||||
|
if log_dir and not os.path.exists(log_dir):
|
||||||
|
os.makedirs(log_dir)
|
||||||
|
|
||||||
|
# 文件处理器
|
||||||
|
file_handler = logging.FileHandler(log_file)
|
||||||
|
file_handler.setFormatter(formatter)
|
||||||
|
|
||||||
|
# 控制台处理器
|
||||||
|
console_handler = logging.StreamHandler()
|
||||||
|
console_handler.setFormatter(formatter)
|
||||||
|
|
||||||
|
logger = logging.getLogger(name)
|
||||||
|
logger.setLevel(level)
|
||||||
|
logger.addHandler(file_handler)
|
||||||
|
logger.addHandler(console_handler)
|
||||||
|
|
||||||
|
return logger
|
||||||
|
|
||||||
|
|
||||||
|
# 创建全局日志记录器
|
||||||
|
app_logger = setup_logger('FeedingControl', 'logs/app.log')
|
||||||
BIN
tests/test_control/__pycache__/test_feeding.cpython-39.pyc
Normal file
BIN
tests/test_control/__pycache__/test_feeding.cpython-39.pyc
Normal file
Binary file not shown.
3
tests/test_control/logs/app.log
Normal file
3
tests/test_control/logs/app.log
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
2025-09-12 19:40:24,636 - FeedingControl.FeedingController - INFO - <20>豸<EFBFBD><E8B1B8>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:40:27,379 - FeedingControl.FeedingController - INFO - <20>豸<EFBFBD><E8B1B8>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
2025-09-12 19:40:31,216 - FeedingControl.FeedingController - INFO - <20>豸<EFBFBD><E8B1B8>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
75
tests/test_control/test_feeding.py
Normal file
75
tests/test_control/test_feeding.py
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
import unittest
|
||||||
|
from unittest.mock import patch, MagicMock
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
from src.control.feeding_controller import FeedingController
|
||||||
|
|
||||||
|
# 添加src目录到Python路径
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'src'))
|
||||||
|
|
||||||
|
|
||||||
|
from src.control.state_machine import FeedingState
|
||||||
|
|
||||||
|
|
||||||
|
class TestFeedingController(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
# Mock配置
|
||||||
|
self.mock_config = {
|
||||||
|
'network': {
|
||||||
|
'relay': {'host': '192.168.0.18', 'port': 50000},
|
||||||
|
'inverter': {'host': '192.168.0.20', 'port': 502, 'slave_id': 1},
|
||||||
|
'transmitters': {
|
||||||
|
'upper': {'host': '192.168.0.21', 'port': 502, 'slave_id': 1, 'weight_register': 0,
|
||||||
|
'register_count': 2},
|
||||||
|
'lower': {'host': '192.168.0.22', 'port': 502, 'slave_id': 2, 'weight_register': 0,
|
||||||
|
'register_count': 2}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'parameters': {
|
||||||
|
'min_required_weight': 50,
|
||||||
|
'max_error_count': 3,
|
||||||
|
'monitoring_interval': 1,
|
||||||
|
'timeout': 30
|
||||||
|
},
|
||||||
|
'feeding': {
|
||||||
|
'stage1_frequency': 30.0,
|
||||||
|
'stage2_frequency': 40.0,
|
||||||
|
'stage3_frequency': 50.0,
|
||||||
|
'target_weight_per_stage': 33.3
|
||||||
|
},
|
||||||
|
'relay': {
|
||||||
|
'door_upper': 0,
|
||||||
|
'door_lower_1': 1,
|
||||||
|
'door_lower_2': 2,
|
||||||
|
'break_arch_upper': 3,
|
||||||
|
'break_arch_lower': 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@patch('control.feeding_controller.config')
|
||||||
|
def test_initialization(self, mock_config):
|
||||||
|
mock_config.get.side_effect = lambda key, default=None: self._get_nested_config(key, default)
|
||||||
|
|
||||||
|
with patch('control.feeding_controller.RelayController') as mock_relay, \
|
||||||
|
patch('control.feeding_controller.InverterController') as mock_inverter, \
|
||||||
|
patch('control.feeding_controller.TransmitterController') as mock_transmitter:
|
||||||
|
controller = FeedingController()
|
||||||
|
self.assertIsNotNone(controller)
|
||||||
|
|
||||||
|
def _get_nested_config(self, key_path, default=None):
|
||||||
|
"""辅助函数:获取嵌套配置值"""
|
||||||
|
keys = key_path.split('.')
|
||||||
|
value = self.mock_config
|
||||||
|
|
||||||
|
try:
|
||||||
|
for key in keys:
|
||||||
|
value = value[key]
|
||||||
|
return value
|
||||||
|
except (KeyError, TypeError):
|
||||||
|
return default
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
BIN
tests/test_devices/__pycache__/test_relay.cpython-39.pyc
Normal file
BIN
tests/test_devices/__pycache__/test_relay.cpython-39.pyc
Normal file
Binary file not shown.
1
tests/test_devices/logs/app.log
Normal file
1
tests/test_devices/logs/app.log
Normal file
@ -0,0 +1 @@
|
|||||||
|
2025-09-13 10:37:43,979 - FeedingControl.RelayController - INFO - <20><><EFBFBD>Ƽ̵<C6BC><CCB5><EFBFBD> door_upper (0) open
|
||||||
48
tests/test_devices/test_relay.py
Normal file
48
tests/test_devices/test_relay.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import unittest
|
||||||
|
from unittest.mock import patch, MagicMock
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
# 添加src目录到Python路径
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..', 'src'))
|
||||||
|
|
||||||
|
from src.divices.relay import RelayController
|
||||||
|
|
||||||
|
|
||||||
|
class TestRelayController(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.relay = RelayController('192.168.0.18', 50000)
|
||||||
|
self.relay.set_device_mapping({
|
||||||
|
'door_upper': 0,
|
||||||
|
'door_lower_1': 1,
|
||||||
|
'door_lower_2': 2,
|
||||||
|
'break_arch_upper': 3,
|
||||||
|
'break_arch_lower': 4
|
||||||
|
})
|
||||||
|
|
||||||
|
@patch('devices.relay.socket.socket')
|
||||||
|
def test_send_command_success(self, mock_socket):
|
||||||
|
# 模拟成功的socket通信
|
||||||
|
mock_socket_instance = MagicMock()
|
||||||
|
mock_socket.return_value.__enter__.return_value = mock_socket_instance
|
||||||
|
mock_socket_instance.recv.return_value = b'\x00\x00\x00\x00\x00\x06\x01\x05\x00\x00\xff\x00'
|
||||||
|
|
||||||
|
result = self.relay.send_command('00000000000601050000FF00')
|
||||||
|
self.assertIsNotNone(result)
|
||||||
|
|
||||||
|
def test_control_valid_device_and_action(self):
|
||||||
|
with patch.object(self.relay, 'send_command') as mock_send:
|
||||||
|
mock_send.return_value = b'some_response'
|
||||||
|
result = self.relay.control('door_upper', 'open')
|
||||||
|
self.assertTrue(result)
|
||||||
|
|
||||||
|
def test_control_invalid_device(self):
|
||||||
|
with patch.object(self.relay, 'send_command') as mock_send:
|
||||||
|
result = self.relay.control('invalid_device', 'open')
|
||||||
|
self.assertFalse(result)
|
||||||
|
mock_send.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user