Commit 6ba77d49 LN

结构优化

1 个父辈 292b0df8
正在显示 220 个修改的文件 包含 1300 行增加289 行删除
......@@ -74,91 +74,58 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DeviceLibrary\AcSerialBean.cs" />
<Compile Include="DeviceLibrary\Camera.cs" />
<Compile Include="DeviceLibrary\CameraTest.cs" />
<Compile Include="DeviceLibrary\CylinderManger.cs" />
<Compile Include="DeviceLibrary\dauxiKS107\DauxiKS107Controller.cs" />
<Compile Include="DeviceLibrary\flyelectronicControl\Flyelectronic_485_RGB_Controller.cs" />
<Compile Include="DeviceLibrary\IOMonitor.cs" />
<Compile Include="DeviceLibrary\IPCamera.cs" />
<Compile Include="DeviceLibrary\I_SafetyDevice.cs" />
<Compile Include="DeviceLibrary\LiftMonitor.cs" />
<Compile Include="DeviceLibrary\LineRunMonitor.cs" />
<Compile Include="DeviceLibrary\C8WeightSensor.cs" />
<Compile Include="DeviceLibrary\OKLEController.cs" />
<Compile Include="DeviceLibrary\ServerCommunication.cs" />
<Compile Include="DeviceLibrary\AxisBean.cs" />
<Compile Include="DeviceLibrary\ServerCommunication_AgvProcess.cs" />
<Compile Include="DeviceLibrary\VisionHelper.cs" />
<Compile Include="DeviceLibrary\weightSensor\OKLE_WeightSensor.cs" />
<Compile Include="Devices\Controllers\AcSerialBean.cs" />
<Compile Include="Devices\Camera\Camera.cs" />
<Compile Include="Devices\Camera\CameraTest.cs" />
<Compile Include="Devices\Controllers\CylinderManger.cs" />
<Compile Include="Devices\Controllers\dauxiKS107\DauxiKS107Controller.cs" />
<Compile Include="Devices\Controllers\flyelectronicControl\Flyelectronic_485_RGB_Controller.cs" />
<Compile Include="Devices\IO\IOMonitor.cs" />
<Compile Include="Devices\Controllers\IPCamera.cs" />
<Compile Include="Devices\Controllers\I_SafetyDevice.cs" />
<Compile Include="Devices\Controllers\LiftMonitor.cs" />
<Compile Include="Devices\Controllers\LineRunMonitor.cs" />
<Compile Include="Devices\Sensors\C8WeightSensor.cs" />
<Compile Include="Devices\Controllers\OKLEController.cs" />
<Compile Include="Communication\ServerCommunication.cs" />
<Compile Include="Devices\Controllers\AxisBean.cs" />
<Compile Include="Communication\ServerCommunication_AgvProcess.cs" />
<Compile Include="Devices\Controllers\VisionHelper.cs" />
<Compile Include="Devices\Sensors\weightSensor\OKLE_WeightSensor.cs" />
<Compile Include="TestRoi.cs" />
<Compile Include="theMachine\BoxTransport.cs" />
<Compile Include="theMachine\Common.cs" />
<Compile Include="theMachine\JobList.cs" />
<Compile Include="theMachine\LabelParam.cs" />
<Compile Include="theMachine\MainMachine _LedRGBProcess.cs" />
<Compile Include="theMachine\MainMachine_AGV.cs" />
<Compile Include="theMachine\MainMachine_ServerControl.cs" />
<Compile Include="theMachine\MainMachine _BtnProcess.cs" />
<Compile Include="theMachine\MainMachine _Common.cs" />
<Compile Include="theMachine\MainMachine _AutoInOutTest.cs" />
<Compile Include="theMachine\MainMachine_Clamp.cs" />
<Compile Include="theMachine\MainMachine_String.cs" />
<Compile Include="theMachine\MainMachine_Store.cs" />
<Compile Include="theMachine\MainMachine _IOMonitor.cs" />
<Compile Include="theMachine\MainMachine _LedProcess.cs" />
<Compile Include="theMachine\MainMachine.cs" />
<Compile Include="theMachine\MoveInfo.cs" />
<Compile Include="theMachine\MoveStep.cs" />
<Compile Include="DeviceLibrary\AlarmBuzzer.cs" />
<Compile Include="DeviceLibrary\CodeManager.cs" />
<Compile Include="theMachine\RobotManage.cs" />
<Compile Include="theMachine\IRobot.cs" />
<Compile Include="DeviceLibrary\IAxisManager.cs" />
<Compile Include="DeviceLibrary\AxisManager.cs" />
<Compile Include="DeviceLibrary\HC\HCAxisManager.cs" />
<Compile Include="DeviceLibrary\HC\HCIOManager.cs" />
<Compile Include="DeviceLibrary\I_IOManager.cs" />
<Compile Include="DeviceLibrary\IOManager.cs" />
<Compile Include="BusinessLogic\BoxTransport.cs" />
<Compile Include="MachineControl\Common.cs" />
<Compile Include="BusinessLogic\JobList.cs" />
<Compile Include="DataProcessing\LabelParam.cs" />
<Compile Include="MachineControl\Components\MainMachine _LedRGBProcess.cs" />
<Compile Include="MachineControl\Components\MainMachine_AGV.cs" />
<Compile Include="MachineControl\Components\MainMachine_ServerControl.cs" />
<Compile Include="MachineControl\Components\MainMachine _BtnProcess.cs" />
<Compile Include="MachineControl\Components\MainMachine _Common.cs" />
<Compile Include="MachineControl\Components\MainMachine _AutoInOutTest.cs" />
<Compile Include="MachineControl\Components\MainMachine_Clamp.cs" />
<Compile Include="MachineControl\Components\MainMachine_String.cs" />
<Compile Include="MachineControl\Components\MainMachine_Store.cs" />
<Compile Include="MachineControl\Components\MainMachine _IOMonitor.cs" />
<Compile Include="MachineControl\Components\MainMachine _LedProcess.cs" />
<Compile Include="MachineControl\MainMachine.cs" />
<Compile Include="BusinessLogic\MoveInfo.cs" />
<Compile Include="BusinessLogic\MoveStep.cs" />
<Compile Include="Devices\Controllers\AlarmBuzzer.cs" />
<Compile Include="Devices\Camera\CodeManager.cs" />
<Compile Include="MachineControl\RobotManage.cs" />
<Compile Include="MachineControl\IRobot.cs" />
<Compile Include="Devices\Axis\IAxisManager.cs" />
<Compile Include="Devices\Axis\AxisManager.cs" />
<Compile Include="Devices\Controllers\HC\HCAxisManager.cs" />
<Compile Include="Devices\Controllers\HC\HCIOManager.cs" />
<Compile Include="Devices\IO\I_IOManager.cs" />
<Compile Include="Devices\IO\IOManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="theMachine\SoundsController.cs" />
<Compile Include="userControl\AxisMoveControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="userControl\AxisMoveControl.Designer.cs">
<DependentUpon>AxisMoveControl.cs</DependentUpon>
</Compile>
<Compile Include="userControl\AxisTipControl.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="userControl\AxisTipControl.Designer.cs">
<DependentUpon>AxisTipControl.cs</DependentUpon>
</Compile>
<Compile Include="userControl\ToucDownBtn.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="DataProcessing\SoundsController.cs" />
<Compile Include="WindowManager.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="userControl\AxisMoveControl.resx">
<DependentUpon>AxisMoveControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="userControl\AxisTipControl.resx">
<DependentUpon>AxisTipControl.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj">
<Project>{43cdd09e-fcf3-4960-a01d-3bbfe9933122}</Project>
<Name>Common</Name>
</ProjectReference>
<ProjectReference Include="..\LoadCVSLibrary\LoadCSVLibrary.csproj">
<Project>{064bebf5-8faa-4ea2-a5f3-a06e6e7d9251}</Project>
<Name>LoadCSVLibrary</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Config\Config.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
......@@ -176,6 +143,15 @@
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<ProjectReference Include="..\Infrastructure\Common\Common.csproj">
<Project>{43cdd09e-fcf3-4960-a01d-3bbfe9933122}</Project>
<Name>Common</Name>
</ProjectReference>
<ProjectReference Include="..\Infrastructure\LoadCVSLibrary\LoadCSVLibrary.csproj">
<Project>{064bebf5-8faa-4ea2-a5f3-a06e6e7d9251}</Project>
<Name>LoadCSVLibrary</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using DeviceLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
public class HIKCamera
{
Thread camerathread;
//static HIKCamera _camera;
//Asa.Camera.VisionLib camera;
//public static HIKCamera Current
//{
// get
// {
// if (_camera == null)
// _camera = new HIKCamera();
// return _camera;
// }
//}
public string Name = "";
public event EventHandler<Bitmap> camera_event;
public string DeviceName = "monitor1";
public PictureBox picture = new PictureBox();
bool enableCamera = ConfigHelper.Config.Get("Func_EnableCam", true);
public bool LoadCameraConfig(string CameraID, out string msg, object preview = null)
{
Name = CameraID;
msg = "";
if (!enableCamera) return true;
string path = $".\\Config\\{CameraID}.json";
if (!File.Exists(path))
{
msg = Name + crc.GetString(L.monitor_config_not_exist, "找不到监控相机配置文件");
LogUtil.error(Name + "找不到监控相机配置文件" + path);
return false;
}
try
{
var configtxt = File.ReadAllText(path);
if (configtxt.IndexOf("Pwd") > 0)
{
configtxt = configtxt.Replace("Pwd", "Password");
configtxt = configtxt.Replace("\"8000\"", "8000");
File.WriteAllText(path, configtxt);
}
var m = Regex.Match(configtxt, "name\".*?\"(.+)\"", RegexOptions.IgnoreCase);
DeviceName = m.Groups[1].Value;
camera = new VisionLib(path, true, "HIK.IPCamera");
}
catch (Exception e)
{
msg = Name + crc.GetString(L.monitor_config_load_fail, "加载监控相机配置文件失败:") + e.ToString();
LogUtil.error(Name + "加载监控相机配置文件失败:" + e.ToString());
return false;
}
PictureBox p1 = new PictureBox();
camera.PreviewImage(DeviceName, p1.Handle);
//if (preview == null)
//{
// camera.PreviewImage(DeviceName, picture.Handle);
//}
//else
//{
// camera.PreviewImage(DeviceName, (IntPtr)preview);
//}
camera.Open(DeviceName);
Bitmap bmp = camera.GetImage(DeviceName);
if (bmp == null)
{
msg = Name + crc.GetString(L.monitor_open_fail, "监控相机打开失败");
LogUtil.error(Name + $"监控相机打开失败");
return false;
}
camera_event?.Invoke(this, bmp);
camerathread = new Thread(new ThreadStart(startCamera));
camerathread.Start();
GC.KeepAlive(camerathread);
return true;
}
int errortimes = 0;
bool camerathreadrun = true;
public void stopCamera()
{
camerathreadrun = false;
}
void startCamera()
{
int errorsleeptime = 5000;
camerathreadrun = true;
while (camerathreadrun)
{
try
{
Bitmap bmp = camera.GetImage(DeviceName);
if (bmp != null)
{
errortimes = 0;
errorsleeptime = 5000;
//saveTest(bmp);
camera_event?.Invoke(this, bmp);
}
else if (bmp == null && errortimes < 5)
{
errortimes++;
LogUtil.error(Name + $"相机获取图像出错,{errortimes}");
Thread.Sleep(errorsleeptime);
}
else if (errortimes == 5)
{
camera.Close(DeviceName);
Thread.Sleep(1000);
camera.Open(DeviceName);
errortimes = 0;
errorsleeptime = errorsleeptime * 2;
LogUtil.error(Name + $"相机错误次数过多,重新打开,{errortimes}");
}
else if (errortimes == 6)
{
LogUtil.error(Name + $"相机连接失败, 相机线程退出,{errortimes}");
break;
}
Thread.Sleep(1000 / 5);
}
catch
{
errortimes++;
}
}
try
{
camera.Close(DeviceName);
}
catch { }
camera.Dispose();
}
void saveTest(Bitmap bitmap)
{
if (!Directory.Exists(".\\TestImg"))
{
Directory.CreateDirectory(".\\TestImg");
}
bitmap.Save(Path.Combine(".\\TestImg\\", $"{DateTime.Now.ToString("yyyyMMddhhmmssfff")}.bmp"));
}
public void CameraGrabOne(string filename)
{
try
{
LogUtil.info(Name + "库位文件名:" + filename);
Bitmap bmp = camera.GetImage(DeviceName);
if (bmp != null)
{
if (File.Exists(filename))
File.Delete(filename);
bmp.Save(filename, ImageFormat.Jpeg);
bmp.Dispose();
}
}
catch (Exception e)
{
LogUtil.error(Name + e.ToString());
}
}
public string GetFixtureStateFilename(string PositionNum, string WareNumber, StoreMoveType storeMoveType, FixtureState fixtureState)
{
Path.GetInvalidFileNameChars().ToList().ForEach((ix) => { WareNumber = WareNumber.Replace(ix.ToString(), ""); });
if (WareNumber.Length > 150)
{
WareNumber = "";
}
if (string.IsNullOrEmpty(WareNumber))
WareNumber = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
string dir = $"\\image\\Fixture\\{storeMoveType}\\{PositionNum}\\";
Directory.CreateDirectory(dir);
string filename = $"{WareNumber}@@{fixtureState}.jpg";
foreach (var x in Path.GetInvalidFileNameChars())
{
filename = filename.Replace(x.ToString(), "");
}
return dir + filename;
}
}
public enum FixtureState
{
FromIn,
FromOut,
FromInSide,
FromOutSide,
ToIn,
ToOut,
ToInSide,
ToOutSide,
ToFix,
}
# Layer5 (边缘计算层) 和 Layer6 (设备控制层) 详细设计
## 1. 概述
本文档详细描述了SISO系统中的Layer5(边缘计算层)和Layer6(设备控制层)的架构设计、组件关系和实现方式。这两层是系统与物理设备交互的核心,负责设备控制、数据采集和边缘计算处理。
## 2. Layer6 (设备控制层)
### 2.1 架构概览
设备控制层作为系统的底层,直接与物理设备进行交互,提供统一的设备抽象和控制接口。
#### 核心组件
- **设备抽象接口**:定义了各类设备的统一操作接口
- **设备管理器**:负责设备的生命周期管理和状态监控
- **通信协议适配器**:处理不同通信协议的转换
- **数据采集模块**:负责从设备获取实时数据
#### 目录结构
```
DeviceLibrary/
├── Interfaces/ # 设备抽象接口
│ ├── IAxisManager.cs # 轴管理器接口
│ ├── I_IOManager.cs # IO管理器接口
│ ├── I_SafetyDevice.cs # 安全设备接口
│ └── IRobot.cs # 机器人接口
├── Implementations/ # 具体实现
│ ├── Axis/ # 轴控制相关实现
│ ├── IO/ # IO控制相关实现
│ ├── Sensors/ # 传感器实现
│ └── Actuators/ # 执行器实现
├── Helpers/ # 辅助工具类
└── Configs/ # 设备配置文件
```
### 2.2 主要模块说明
#### 2.2.1 轴控制模块
负责控制和监控运动轴的状态和行为,提供运动控制的基本功能。
- **AxisManager**:管理所有运动轴,提供统一的控制接口
- **AxisBean**:描述轴的属性和状态信息
- **运动指令封装**:封装各类运动指令如点动、连续运动等
#### 2.2.2 IO控制模块
管理系统的输入输出信号,处理数字量和模拟量的读写操作。
- **IOManager**:管理所有IO点,提供IO读写功能
- **IOMonitor**:监控IO状态变化,触发相应事件
- **IO映射管理**:维护IO点与实际物理设备的映射关系
#### 2.2.3 传感器模块
处理各类传感器数据的采集和处理,包括重量传感器、视觉传感器等。
- **C8WeightSensor**:C8系列重量传感器实现
- **OKLE_WeightSensor**:OKLE系列重量传感器实现
- **Camera**:相机设备抽象和控制
### 2.3 设备接口设计原则
- **接口隔离**:每个设备接口专注于特定类型设备的操作
- **依赖倒置**:高层模块依赖于抽象接口,不依赖于具体实现
- **单一职责**:每个类只负责单一功能领域的任务
- **可扩展性**:设计支持轻松添加新设备类型和通信协议
## 3. Layer5 (边缘计算层)
### 3.1 架构概览
边缘计算层位于设备控制层之上,负责处理设备数据、实现业务逻辑和协调设备间的交互。
#### 核心组件
- **业务逻辑处理器**:实现核心业务逻辑
- **状态管理器**:维护系统状态和设备状态
- **任务调度器**:协调和调度各类任务执行
- **数据处理引擎**:进行边缘数据处理和分析
#### 目录结构
```
TheMachine/
├── Core/ # 核心业务逻辑
│ ├── MainMachine.cs # 主机器控制逻辑
│ ├── RobotManage.cs # 机器人管理逻辑
│ └── BoxTransport.cs # 料箱传输控制逻辑
├── Controllers/ # 控制器
│ ├── AxisControl.cs # 轴控制界面控制器
│ ├── IOControls.cs # IO控制界面控制器
│ └── SettingControl.cs # 设置界面控制器
├── Services/ # 服务层
│ ├── JobManagement/ # 任务管理服务
│ ├── StateManagement/ # 状态管理服务
│ └── EventProcessing/ # 事件处理服务
└── Utils/ # 工具类
```
### 3.2 主要功能模块
#### 3.2.1 机器控制模块
作为系统的核心,协调各设备完成整体任务流程。
- **MainMachine**:实现主机器控制逻辑,协调各子系统工作
- **状态机设计**:使用状态机模式管理系统运行状态转换
- **任务协调**:协调各设备完成复杂任务序列
#### 3.2.2 机器人管理模块
管理机器人设备,实现机器人的运动控制和任务执行。
- **RobotManage**:机器人设备的管理和控制
- **运动规划**:简单的运动路径规划和避障
- **任务执行**:执行预设的机器人任务序列
#### 3.2.3 数据处理和分析
对从设备层采集的数据进行处理、分析和存储。
- **数据过滤**:过滤和清洗原始传感器数据
- **边缘分析**:在边缘设备上进行简单的数据统计和分析
- **数据存储**:管理本地数据存储和缓存
## 4. 层间交互设计
### 4.1 通信机制
Layer5和Layer6之间采用以下通信机制:
- **接口调用**:Layer5通过接口直接调用Layer6提供的服务
- **事件通知**:Layer6通过事件机制向Layer5通知设备状态变化
- **异步通信**:关键操作采用异步方式执行,避免阻塞主线程
### 4.2 数据流设计
- **下行数据流**:指令从Layer5传递到Layer6,最终执行到物理设备
- **上行数据流**:设备状态和传感器数据从Layer6采集后传递到Layer5
- **数据转换**:在两层之间进行数据格式和语义的转换
## 5. 设计模式应用
### 5.1 创建型模式
- **工厂模式**:用于创建不同类型的设备实例
- **单例模式**:管理全局唯一的设备管理器实例
### 5.2 结构型模式
- **适配器模式**:适配不同类型的设备通信协议
- **装饰器模式**:为设备操作添加额外功能(如日志、监控等)
### 5.3 行为型模式
- **状态模式**:管理系统和设备的状态转换
- **命令模式**:封装设备操作指令
- **观察者模式**:实现设备状态变化的通知机制
## 6. 性能和安全考虑
### 6.1 性能优化
- **资源池化**:对频繁创建的对象使用对象池
- **异步操作**:关键操作采用异步方式执行
- **缓存机制**:缓存常用配置和状态信息
### 6.2 安全机制
- **访问控制**:对设备操作进行权限控制
- **故障恢复**:实现自动故障检测和恢复机制
- **日志审计**:记录关键操作和状态变化,便于审计和故障排查
## 7. 扩展性设计
### 7.1 新设备接入
设计支持通过以下方式轻松接入新设备:
- **接口实现**:实现相应的设备接口
- **配置注册**:在配置文件中注册新设备信息
- **驱动适配**:开发相应的设备驱动适配器
### 7.2 功能扩展
系统支持通过以下方式扩展功能:
- **插件机制**:支持加载自定义功能插件
- **配置化**:关键参数和行为支持配置化调整
- **事件扩展**:通过事件机制支持功能扩展
## 8. 总结
Layer5和Layer6作为SISO系统的核心组成部分,通过清晰的分层设计和接口定义,实现了设备控制和边缘计算功能的有效分离和协作。这种设计使得系统具有良好的可维护性、可扩展性和可靠性,能够满足工业自动化场景的需求。
\ No newline at end of file
# SISO系统架构概述
## 1. 系统简介
SISO(Single Input Single Output)系统是一个工业自动化控制平台,用于管理和控制各类工业设备,包括运动轴、传感器、执行器等。系统采用分层架构设计,实现了设备控制、数据处理、业务逻辑和用户交互的有效分离。
## 2. 整体架构
### 2.1 分层架构
SISO系统采用经典的分层架构设计,从上到下依次分为以下几层:
1. **表现层(Layer 1-2)**:用户界面和交互组件
2. **应用层(Layer 3-4)**:业务应用和功能模块
3. **边缘计算层(Layer 5)**:数据处理和业务逻辑
4. **设备控制层(Layer 6)**:设备抽象和控制接口
5. **设备层(Layer 7)**:物理设备和硬件接口
本文档主要关注系统的Layer5和Layer6部分。
### 2.2 核心组件关系
系统的主要组件及其关系如下:
```
┌─────────────────────────────────────────────────┐
│ 表现层 (Layer 1-2) │
│ ┌───────────────┐ ┌───────────────┐ │
│ │ 主界面 │ │ 配置界面 │ │
│ └───────┬───────┘ └───────┬───────┘ │
│ │ │ │
└──────────┼──────────────────┼───────────────────┘
│ │
┌──────────┼──────────────────┼───────────────────┐
│ │ │ │
│ ┌───────▼───────┐ ┌───────▼───────┐ │
│ │ 应用服务 │ │ 业务模块 │ │
│ └───────┬───────┘ └───────┬───────┘ │
│ │ │ │
│ └──────────┬───────┘ │
│ │ │
│ 边缘计算层 (Layer 5) │
│ ┌─────────────────▼─────────────────┐ │
│ │ MainMachine (主控) │ │
│ ├─────────────────┬─────────────────┤ │
│ │ RobotManage │ BoxTransport │ │
│ └─────────────────┴─────────────────┘ │
│ │ │
│ ┌──────────┴──────────┐ │
│ │ │ │
└──────────┼─────────────────────┼───────────────┘
│ │
┌──────────▼─────────┐ ┌─────────▼─────────┐
│ 设备控制层 │ │ 设备控制层 │
│ (Layer 6 - 轴控) │ │ (Layer 6 - IO) │
│ ┌─────────────┐ │ │ ┌─────────────┐ │
│ │ AxisManager │ │ │ │ IOManager │ │
│ └─────────────┘ │ │ └─────────────┘ │
└───────────────────┘ └───────────────────┘
│ │
┌──────────┴─────────┐ ┌─────────┴─────────┐
│ 设备层 │ │ 设备层 │
│ (Layer 7 - 电机) │ │ (Layer 7 - IO板) │
└───────────────────┘ └───────────────────┘
```
## 3. 主要功能模块
### 3.1 设备控制层 (Layer 6)
设备控制层负责提供统一的设备抽象和控制接口,主要包括:
- **轴控制**:管理运动轴的状态和运动
- **IO控制**:管理输入输出信号
- **传感器管理**:处理各类传感器数据
- **执行器控制**:控制各类执行器动作
### 3.2 边缘计算层 (Layer 5)
边缘计算层负责处理设备数据、实现业务逻辑和协调设备交互,主要包括:
- **机器控制**:协调各设备完成整体任务流程
- **任务管理**:管理和调度各类任务
- **状态监控**:监控系统和设备状态
- **数据处理**:对采集的数据进行处理和分析
## 4. 技术架构
### 4.1 开发技术栈
- **开发语言**:C#/.NET Framework
- **UI框架**:Windows Forms
- **通信协议**:TCP/IP、串口通信
- **设备驱动**:自定义驱动和第三方库
### 4.2 关键技术特性
- **多线程处理**:使用多线程处理设备通信和数据采集
- **异步操作**:关键操作采用异步方式执行
- **事件驱动**:基于事件机制实现组件间通信
- **配置化设计**:支持通过配置文件定制系统行为
## 5. 系统扩展性
### 5.1 设备扩展
系统设计支持轻松接入新类型设备:
- 实现相应的设备接口
- 在设备管理器中注册新设备
- 配置设备参数和通信方式
### 5.2 功能扩展
系统支持通过以下方式扩展功能:
- 开发新的业务模块和服务
- 实现自定义的设备控制逻辑
- 添加新的用户界面组件
## 6. 系统维护
### 6.1 日志系统
系统集成了完善的日志记录机制,记录关键操作、错误信息和系统状态,便于问题排查和系统监控。
### 6.2 故障恢复
系统实现了基本的故障检测和恢复机制,在设备异常时能够采取相应的保护措施。
## 7. 总结
SISO系统采用分层架构设计,实现了设备控制和业务逻辑的有效分离,具有良好的可维护性、可扩展性和可靠性。系统的Layer5和Layer6部分作为连接应用层和物理设备的桥梁,在系统中扮演着至关重要的角色。
\ No newline at end of file
# 轴配置说明
## 1. 概述
本文档详细说明SISO系统中运动轴的配置方法,包括配置文件格式、参数说明以及配置示例。轴配置对于系统的运动控制精度和稳定性至关重要,用户应根据实际设备情况正确配置相关参数。
## 2. 配置文件格式
轴配置可以通过配置文件或系统界面进行设置。配置文件通常采用XML或JSON格式,存储在系统配置目录中。
### 2.1 基本配置结构
```xml
<?xml version="1.0" encoding="utf-8" ?>
<AxesConfig>
<Axes>
<Axis>
<Id>1</Id>
<Name>X-Axis</Name>
<Type>Linear</Type>
<MotorType>Servo</MotorType>
<ControllerId>1</ControllerId>
<AxisNumber>0</AxisNumber>
<Enable>true</Enable>
<!-- 机械参数 -->
<Mechanical>
<TravelRange>1000.0</TravelRange>
<Unit>mm</Unit>
<GearRatio>1.0</GearRatio>
<LeadScrewPitch>5.0</LeadScrewPitch>
<PulleyRatio>1.0</PulleyRatio>
</Mechanical>
<!-- 编码器参数 -->
<Encoder>
<CountsPerRevolution>131072</CountsPerRevolution>
<CountsPerUnit>26214.4</CountsPerUnit>
<Direction>Positive</Direction>
</Encoder>
<!-- 运动参数 -->
<Motion>
<MaxSpeed>500.0</MaxSpeed>
<MaxAcceleration>1000.0</MaxAcceleration>
<MaxDeceleration>1000.0</MaxDeceleration>
<Jerk>10000.0</Jerk>
<HomeSpeed>50.0</HomeSpeed>
<JogSpeed>30.0</JogSpeed>
<CreepSpeed>10.0</CreepSpeed>
</Motion>
<!-- 限位配置 -->
<Limits>
<PositiveLimit>1000.0</PositiveLimit>
<NegativeLimit>0.0</NegativeLimit>
<SoftLimitEnable>true</SoftLimitEnable>
<HardLimitEnable>true</HardLimitEnable>
</Limits>
<!-- 回零配置 -->
<Homing>
<HomeMode>ActiveLimitHome</HomeMode>
<HomeDirection>Negative</HomeDirection>
<HomeOffset>10.0</HomeOffset>
<HomeSensorId>101</HomeSensorId>
</Homing>
<!-- IO映射 -->
<IOMapping>
<PositiveLimitSensor>1</PositiveLimitSensor>
<NegativeLimitSensor>2</NegativeLimitSensor>
<HomeSensor>3</HomeSensor>
<ServoEnable>11</ServoEnable>
<ServoAlarm>12</ServoAlarm>
</IOMapping>
</Axis>
<!-- 更多轴配置... -->
</Axes>
</AxesConfig>
```
## 3. 配置参数说明
### 3.1 基本参数
| 参数 | 类型 | 说明 | 是否必需 |
|-----|------|-----|--------|
| Id | Integer | 轴的唯一标识ID | 是 |
| Name | String | 轴的名称(如X轴、Y轴等) | 是 |
| Type | String | 轴类型(Linear-直线轴、Rotary-旋转轴) | 是 |
| MotorType | String | 电机类型(Servo-伺服电机、Stepper-步进电机) | 是 |
| ControllerId | Integer | 控制器ID | 是 |
| AxisNumber | Integer | 在控制器中的轴号 | 是 |
| Enable | Boolean | 是否启用该轴 | 是 |
### 3.2 机械参数
| 参数 | 类型 | 说明 | 是否必需 |
|-----|------|-----|--------|
| TravelRange | Double | 轴的行程范围 | 是 |
| Unit | String | 单位(mm、deg等) | 是 |
| GearRatio | Double | 齿轮传动比 | 否 |
| LeadScrewPitch | Double | 丝杠导程(对于直线轴) | 否 |
| PulleyRatio | Double | 皮带轮传动比 | 否 |
### 3.3 编码器参数
| 参数 | 类型 | 说明 | 是否必需 |
|-----|------|-----|--------|
| CountsPerRevolution | Integer | 编码器每转脉冲数 | 是 |
| CountsPerUnit | Double | 每单位移动对应的脉冲数 | 是 |
| Direction | String | 运动方向(Positive-正向、Negative-反向) | 是 |
### 3.4 运动参数
| 参数 | 类型 | 说明 | 是否必需 |
|-----|------|-----|--------|
| MaxSpeed | Double | 最大运动速度 | 是 |
| MaxAcceleration | Double | 最大加速度 | 是 |
| MaxDeceleration | Double | 最大减速度 | 是 |
| Jerk | Double | 加加速度 | 否 |
| HomeSpeed | Double | 回零速度 | 是 |
| JogSpeed | Double | 点动速度 | 是 |
| CreepSpeed | Double | 爬行速度(用于精确定位) | 否 |
### 3.5 限位配置
| 参数 | 类型 | 说明 | 是否必需 |
|-----|------|-----|--------|
| PositiveLimit | Double | 正向软限位值 | 否 |
| NegativeLimit | Double | 负向软限位值 | 否 |
| SoftLimitEnable | Boolean | 是否启用软限位 | 否 |
| HardLimitEnable | Boolean | 是否启用硬限位 | 否 |
### 3.6 回零配置
| 参数 | 类型 | 说明 | 是否必需 |
|-----|------|-----|--------|
| HomeMode | String | 回零模式 | 是 |
| HomeDirection | String | 回零方向 | 是 |
| HomeOffset | Double | 回零偏移量 | 否 |
| HomeSensorId | Integer | 回零传感器ID | 否 |
### 3.7 IO映射
| 参数 | 类型 | 说明 | 是否必需 |
|-----|------|-----|--------|
| PositiveLimitSensor | Integer | 正向限位传感器IO点 | 否 |
| NegativeLimitSensor | Integer | 负向限位传感器IO点 | 否 |
| HomeSensor | Integer | 回零传感器IO点 | 否 |
| ServoEnable | Integer | 伺服使能IO点 | 否 |
| ServoAlarm | Integer | 伺服报警IO点 | 否 |
## 4. 回零模式说明
| 回零模式 | 描述 |
|--------|------|
| ActiveLimitHome | 主动回零(碰到限位后返回) |
| PassiveHome | 被动回零(等待外部信号触发) |
| SensorHome | 传感器回零(找到原点传感器信号) |
| IndexHome | 编码器索引回零 |
| NoHome | 无需回零 |
## 5. 配置示例
### 5.1 X轴配置示例
```xml
<Axis>
<Id>1</Id>
<Name>X-Axis</Name>
<Type>Linear</Type>
<MotorType>Servo</MotorType>
<ControllerId>1</ControllerId>
<AxisNumber>0</AxisNumber>
<Enable>true</Enable>
<!-- 机械参数 -->
<Mechanical>
<TravelRange>1000.0</TravelRange>
<Unit>mm</Unit>
<GearRatio>1.0</GearRatio>
<LeadScrewPitch>5.0</LeadScrewPitch>
<PulleyRatio>1.0</PulleyRatio>
</Mechanical>
<!-- 编码器参数 -->
<Encoder>
<CountsPerRevolution>131072</CountsPerRevolution>
<CountsPerUnit>26214.4</CountsPerUnit>
<Direction>Positive</Direction>
</Encoder>
<!-- 运动参数 -->
<Motion>
<MaxSpeed>500.0</MaxSpeed>
<MaxAcceleration>1000.0</MaxAcceleration>
<MaxDeceleration>1000.0</MaxDeceleration>
<Jerk>10000.0</Jerk>
<HomeSpeed>50.0</HomeSpeed>
<JogSpeed>30.0</JogSpeed>
<CreepSpeed>10.0</CreepSpeed>
</Motion>
<!-- 限位配置 -->
<Limits>
<PositiveLimit>1000.0</PositiveLimit>
<NegativeLimit>0.0</NegativeLimit>
<SoftLimitEnable>true</SoftLimitEnable>
<HardLimitEnable>true</HardLimitEnable>
</Limits>
<!-- 回零配置 -->
<Homing>
<HomeMode>ActiveLimitHome</HomeMode>
<HomeDirection>Negative</HomeDirection>
<HomeOffset>10.0</HomeOffset>
<HomeSensorId>101</HomeSensorId>
</Homing>
</Axis>
```
### 5.2 旋转轴配置示例
```xml
<Axis>
<Id>4</Id>
<Name>Theta-Axis</Name>
<Type>Rotary</Type>
<MotorType>Servo</MotorType>
<ControllerId>1</ControllerId>
<AxisNumber>3</AxisNumber>
<Enable>true</Enable>
<!-- 机械参数 -->
<Mechanical>
<TravelRange>360.0</TravelRange>
<Unit>deg</Unit>
<GearRatio>10.0</GearRatio>
<LeadScrewPitch>0.0</LeadScrewPitch>
<PulleyRatio>1.0</PulleyRatio>
</Mechanical>
<!-- 编码器参数 -->
<Encoder>
<CountsPerRevolution>131072</CountsPerRevolution>
<CountsPerUnit>364.09</CountsPerUnit>
<Direction>Positive</Direction>
</Encoder>
<!-- 运动参数 -->
<Motion>
<MaxSpeed>180.0</MaxSpeed>
<MaxAcceleration>360.0</MaxAcceleration>
<MaxDeceleration>360.0</MaxDeceleration>
<Jerk>3600.0</Jerk>
<HomeSpeed>60.0</HomeSpeed>
<JogSpeed>30.0</JogSpeed>
<CreepSpeed>10.0</CreepSpeed>
</Motion>
<!-- 限位配置 -->
<Limits>
<PositiveLimit>360.0</PositiveLimit>
<NegativeLimit>0.0</NegativeLimit>
<SoftLimitEnable>false</SoftLimitEnable>
<HardLimitEnable>false</HardLimitEnable>
</Limits>
<!-- 回零配置 -->
<Homing>
<HomeMode>SensorHome</HomeMode>
<HomeDirection>Positive</HomeDirection>
<HomeOffset>0.0</HomeOffset>
<HomeSensorId>104</HomeSensorId>
</Homing>
</Axis>
```
## 5. 参数调整建议
### 5.1 运动参数调整
- **速度参数**:根据负载情况和设备刚性调整,避免机械振动
- **加速度/减速度**:过大可能导致机械冲击,过小会影响效率
- **加加速度(Jerk)**:平滑运动过渡,减少振动
- **回零参数**:回零速度不宜过快,确保定位准确性
### 5.2 安全参数
- **限位配置**:确保硬限位和软限位都正确设置,避免机械碰撞
- **方向设置**:确保运动方向正确,避免反方向运动造成危险
- **使能控制**:设置正确的伺服使能信号,确保安全运行
## 6. 常见问题与解决方案
### 6.1 运动精度问题
- 检查编码器参数设置是否正确
- 确认机械传动部分是否存在间隙或松动
- 调整速度和加速度参数,减少振动
### 6.2 回零异常
- 确认回零传感器安装位置和连接是否正确
- 检查回零模式设置是否与实际硬件匹配
- 调整回零速度和方向参数
### 6.3 运动不平滑
- 增加Jerk参数值,使速度变化更加平滑
- 检查机械系统是否有卡滞或摩擦过大的情况
- 调整PID参数(如果控制器支持)
### 6.4 限位触发
- 确认限位传感器连接和设置是否正确
- 检查软限位参数是否设置合理
- 确认轴的运动范围与实际机械结构匹配
\ No newline at end of file
# 相机配置说明
## 1. 概述
本文档详细说明SISO系统中相机设备的配置方法,包括配置文件格式、参数说明以及配置示例。相机配置文件采用JSON格式,存储在`DeviceLibrary/Config/`目录下。
## 2. 配置文件格式
相机配置文件采用JSON格式,每个相机对应一个配置文件,文件名格式为`Camera[相机标识].json`,例如`CameraA.json`
### 2.1 基本结构
```json
{
"CameraInfo": {
"CameraId": "CameraA",
"Model": "HIKVISION_MV-CA050-10GC",
"IpAddress": "192.168.1.10",
"Port": 8000,
"Manufacturer": "HIKVISION",
"FirmwareVersion": "V3.2.0"
},
"ImageSettings": {
"Width": 2592,
"Height": 2048,
"PixelFormat": "Mono8",
"AcquisitionMode": "Continuous",
"ExposureTime": 5000,
"Gain": 0.0,
"FrameRate": 25.0,
"TriggerMode": "Off"
},
"ROI": {
"Enable": false,
"OffsetX": 0,
"OffsetY": 0,
"Width": 2592,
"Height": 2048
},
"Processing": {
"EnableBinning": false,
"BinX": 1,
"BinY": 1,
"EnableDecimation": false,
"DecimationX": 1,
"DecimationY": 1
},
"Advanced": {
"BalanceRatioRed": 1.0,
"BalanceRatioGreen": 1.0,
"BalanceRatioBlue": 1.0,
"Gamma": 1.0,
"BlackLevel": 0,
"WhiteBalanceMode": "Off",
"Sharpness": 0.0
},
"Storage": {
"SaveRawImages": false,
"SaveProcessedImages": false,
"ImageSavePath": "Images",
"ImageFormat": "PNG"
}
}
```
## 3. 配置参数说明
### 3.1 CameraInfo 部分
| 参数 | 类型 | 说明 | 是否必需 |
|-----|------|-----|--------|
| CameraId | String | 相机唯一标识,必须与文件名对应 | 是 |
| Model | String | 相机型号 | 是 |
| IpAddress | String | 相机IP地址(对于网络相机) | 对于网络相机必需 |
| Port | Integer | 相机端口(对于网络相机) | 对于网络相机必需 |
| Manufacturer | String | 相机制造商 | 否 |
| FirmwareVersion | String | 相机固件版本 | 否 |
### 3.2 ImageSettings 部分
| 参数 | 类型 | 说明 | 是否必需 | 默认值 |
|-----|------|-----|--------|-------|
| Width | Integer | 图像宽度(像素) | 是 | 相机默认分辨率 |
| Height | Integer | 图像高度(像素) | 是 | 相机默认分辨率 |
| PixelFormat | String | 像素格式(Mono8, RGB8, BGR8等) | 是 | Mono8 |
| AcquisitionMode | String | 采集模式(Continuous, SingleFrame, MultiFrame) | 是 | Continuous |
| ExposureTime | Integer | 曝光时间(微秒) | 是 | 10000 |
| Gain | Double | 增益值(dB) | 是 | 0.0 |
| FrameRate | Double | 帧率(FPS) | 是 | 30.0 |
| TriggerMode | String | 触发模式(Off, On) | 是 | Off |
### 3.3 ROI 部分
| 参数 | 类型 | 说明 | 是否必需 | 默认值 |
|-----|------|-----|--------|-------|
| Enable | Boolean | 是否启用ROI | 否 | false |
| OffsetX | Integer | ROI起始点X坐标 | 否 | 0 |
| OffsetY | Integer | ROI起始点Y坐标 | 否 | 0 |
| Width | Integer | ROI宽度 | 否 | 图像宽度 |
| Height | Integer | ROI高度 | 否 | 图像高度 |
### 3.4 Processing 部分
| 参数 | 类型 | 说明 | 是否必需 | 默认值 |
|-----|------|-----|--------|-------|
| EnableBinning | Boolean | 是否启用Binning | 否 | false |
| BinX | Integer | X方向Binning系数 | 否 | 1 |
| BinY | Integer | Y方向Binning系数 | 否 | 1 |
| EnableDecimation | Boolean | 是否启用Decimation | 否 | false |
| DecimationX | Integer | X方向Decimation系数 | 否 | 1 |
| DecimationY | Integer | Y方向Decimation系数 | 否 | 1 |
### 3.5 Advanced 部分
| 参数 | 类型 | 说明 | 是否必需 | 默认值 |
|-----|------|-----|--------|-------|
| BalanceRatioRed | Double | 红色通道平衡比例 | 否 | 1.0 |
| BalanceRatioGreen | Double | 绿色通道平衡比例 | 否 | 1.0 |
| BalanceRatioBlue | Double | 蓝色通道平衡比例 | 否 | 1.0 |
| Gamma | Double | 伽马校正系数 | 否 | 1.0 |
| BlackLevel | Integer | 黑电平值 | 否 | 0 |
| WhiteBalanceMode | String | 白平衡模式(Off, Continuous, Once) | 否 | Off |
| Sharpness | Double | 锐度调整值 | 否 | 0.0 |
### 3.6 Storage 部分
| 参数 | 类型 | 说明 | 是否必需 | 默认值 |
|-----|------|-----|--------|-------|
| SaveRawImages | Boolean | 是否保存原始图像 | 否 | false |
| SaveProcessedImages | Boolean | 是否保存处理后图像 | 否 | false |
| ImageSavePath | String | 图像保存路径 | 否 | Images |
| ImageFormat | String | 图像保存格式(PNG, JPG, BMP等) | 否 | PNG |
## 4. 配置示例
### 4.1 网络相机配置示例
```json
{
"CameraInfo": {
"CameraId": "CameraA",
"Model": "HIKVISION_MV-CA050-10GC",
"IpAddress": "192.168.1.10",
"Port": 8000,
"Manufacturer": "HIKVISION",
"FirmwareVersion": "V3.2.0"
},
"ImageSettings": {
"Width": 2592,
"Height": 2048,
"PixelFormat": "Mono8",
"AcquisitionMode": "Continuous",
"ExposureTime": 10000,
"Gain": 0.0,
"FrameRate": 25.0,
"TriggerMode": "Off"
},
"ROI": {
"Enable": false,
"OffsetX": 0,
"OffsetY": 0,
"Width": 2592,
"Height": 2048
},
"Processing": {
"EnableBinning": false,
"BinX": 1,
"BinY": 1,
"EnableDecimation": false,
"DecimationX": 1,
"DecimationY": 1
},
"Advanced": {
"BalanceRatioRed": 1.0,
"BalanceRatioGreen": 1.0,
"BalanceRatioBlue": 1.0,
"Gamma": 1.0,
"BlackLevel": 0,
"WhiteBalanceMode": "Off",
"Sharpness": 0.0
},
"Storage": {
"SaveRawImages": false,
"SaveProcessedImages": false,
"ImageSavePath": "Images",
"ImageFormat": "PNG"
}
}
```
### 4.2 带ROI的相机配置示例
```json
{
"CameraInfo": {
"CameraId": "CameraB",
"Model": "HIKVISION_MV-CA020-10GC",
"IpAddress": "192.168.1.11",
"Port": 8000,
"Manufacturer": "HIKVISION",
"FirmwareVersion": "V3.1.0"
},
"ImageSettings": {
"Width": 1920,
"Height": 1200,
"PixelFormat": "RGB8",
"AcquisitionMode": "Continuous",
"ExposureTime": 5000,
"Gain": 0.0,
"FrameRate": 30.0,
"TriggerMode": "On"
},
"ROI": {
"Enable": true,
"OffsetX": 500,
"OffsetY": 300,
"Width": 1000,
"Height": 800
},
"Processing": {
"EnableBinning": false,
"BinX": 1,
"BinY": 1,
"EnableDecimation": false,
"DecimationX": 1,
"DecimationY": 1
},
"Advanced": {
"BalanceRatioRed": 1.2,
"BalanceRatioGreen": 1.0,
"BalanceRatioBlue": 0.9,
"Gamma": 1.2,
"BlackLevel": 5,
"WhiteBalanceMode": "Continuous",
"Sharpness": 0.1
},
"Storage": {
"SaveRawImages": false,
"SaveProcessedImages": true,
"ImageSavePath": "Images/CameraB",
"ImageFormat": "JPG"
}
}
```
## 5. 配置文件管理
### 5.1 配置文件位置
相机配置文件存储在以下位置:
```
DeviceLibrary/
└── Config/
├── CameraA.json
├── CameraB.json
└── ...
```
### 5.2 配置加载流程
1. 系统启动时,`Camera.cs`类会扫描`Config`目录下的所有相机配置文件
2. 根据配置文件中的信息初始化相应的相机设备
3. 如果配置文件不存在或格式错误,系统将使用默认配置
### 5.3 配置修改方法
1. 直接编辑对应的JSON配置文件
2. 通过系统的配置界面进行修改(如果有)
3. 修改完成后,需要重启系统才能使新配置生效
## 6. 常见问题与解决方案
### 6.1 相机无法连接
- 检查IP地址和端口是否正确配置
- 确认相机与计算机在同一网络中
- 验证相机是否已正确供电并处于工作状态
### 6.2 图像质量问题
- 调整曝光时间和增益参数
- 对于彩色相机,检查白平衡设置
- 考虑启用ROI功能,只关注感兴趣的区域
### 6.3 帧率不达标
- 降低图像分辨率
- 启用Binning或Decimation功能
- 检查网络带宽是否足够(对于网络相机)
### 6.4 配置文件无效
- 确认JSON格式是否正确,可以使用在线JSON验证工具检查
- 检查必需参数是否都已配置
- 确保文件名与`CameraId`字段匹配
\ No newline at end of file
# 设备通信配置说明
## 1. 概述
本文档详细说明SISO系统中设备通信的配置方法,包括通信协议、配置文件格式、参数说明以及配置示例。设备通信配置对于系统各组件间的正常协作至关重要,用户应根据实际网络环境和设备情况正确配置相关参数。
## 2. 通信架构
SISO系统采用分层通信架构,主要包括以下几种通信方式:
- **控制器通信**:与运动控制器之间的通信
- **设备通信**:与各类传感器、执行器的通信
- **网络通信**:与上位机或其他系统的网络通信
- **内部通信**:系统内部模块间的进程通信
## 3. 通信协议配置
### 3.1 控制器通信配置
#### 3.1.1 EtherCAT通信配置
```xml
<?xml version="1.0" encoding="utf-8" ?>
<EtherCATConfig>
<Master>
<Id>1</Id>
<Name>ECAT_Master</Name>
<Port>1</Port>
<CycleTime>1000</CycleTime> <!-- 单位: μs -->
<Priority>High</Priority>
</Master>
<Slaves>
<Slave>
<Id>1</Id>
<Name>Servo_Drive_1</Name>
<VendorId>0x00000000</VendorId>
<ProductCode>0x00000000</ProductCode>
<Alias>0</Alias>
<Position>0</Position>
<Config>
<PdoMapping>
<TxPdo>
<Entry>StatusWord</Entry>
<Entry>ActualPosition</Entry>
<Entry>ActualVelocity</Entry>
<Entry>ActualTorque</Entry>
</TxPdo>
<RxPdo>
<Entry>ControlWord</Entry>
<Entry>TargetPosition</Entry>
<Entry>TargetVelocity</Entry>
<Entry>TargetTorque</Entry>
</RxPdo>
</PdoMapping>
<CycleTime>1000</CycleTime>
</Config>
</Slave>
<!-- 更多从站配置... -->
</Slaves>
</EtherCATConfig>
```
#### 3.1.2 Modbus RTU通信配置
```json
{
"ModbusRtuConfig": {
"Port": "COM3",
"BaudRate": 115200,
"DataBits": 8,
"StopBits": 1,
"Parity": "None",
"Timeout": 1000,
"Slaves": [
{
"Id": 1,
"Name": "TemperatureSensor",
"FunctionCode": 4,
"StartingRegister": 0,
"RegisterCount": 2
},
{
"Id": 2,
"Name": "PressureSensor",
"FunctionCode": 4,
"StartingRegister": 0,
"RegisterCount": 2
}
]
}
}
```
#### 3.1.3 Modbus TCP通信配置
```json
{
"ModbusTcpConfig": {
"IpAddress": "192.168.1.100",
"Port": 502,
"Timeout": 1000,
"Slaves": [
{
"Id": 1,
"Name": "PLC_Controller",
"FunctionCode": 3,
"StartingRegister": 100,
"RegisterCount": 10
}
]
}
}
```
### 3.2 网络通信配置
#### 3.2.1 TCP/IP服务器配置
```json
{
"TcpServerConfig": {
"Port": 8080,
"MaxConnections": 10,
"BufferSize": 4096,
"Timeout": 30000,
"EnableSsl": false,
"AutoReconnect": true
}
}
```
#### 3.2.2 TCP/IP客户端配置
```json
{
"TcpClientConfig": {
"IpAddress": "192.168.1.200",
"Port": 8080,
"BufferSize": 4096,
"Timeout": 30000,
"AutoReconnect": true,
"ReconnectInterval": 5000
}
}
```
#### 3.2.3 WebSocket配置
```json
{
"WebSocketConfig": {
"Port": 8081,
"Path": "/ws",
"MaxConnections": 50,
"EnableSsl": false,
"HeartbeatInterval": 30000
}
}
```
## 4. 设备通信配置参数说明
### 4.1 EtherCAT配置参数
| 参数 | 类型 | 说明 | 是否必需 |
|-----|------|-----|--------|
| Master.Id | Integer | 主站ID | 是 |
| Master.Name | String | 主站名称 | 是 |
| Master.Port | Integer | 网络端口号 | 是 |
| Master.CycleTime | Integer | 通信周期时间(μs) | 是 |
| Master.Priority | String | 通信优先级 | 是 |
| Slave.Id | Integer | 从站ID | 是 |
| Slave.Name | String | 从站名称 | 是 |
| Slave.VendorId | Hex | 厂商ID | 是 |
| Slave.ProductCode | Hex | 产品代码 | 是 |
| Slave.Alias | Integer | 别名 | 否 |
| Slave.Position | Integer | 位置 | 是 |
### 4.2 Modbus配置参数
| 参数 | 类型 | 说明 | 是否必需 |
|-----|------|-----|--------|
| Port | String/Integer | 串口名称或TCP端口 | 是 |
| BaudRate | Integer | 波特率(RTU模式) | 是(RTU模式) |
| DataBits | Integer | 数据位(RTU模式) | 是(RTU模式) |
| StopBits | Integer | 停止位(RTU模式) | 是(RTU模式) |
| Parity | String | 校验位(RTU模式) | 是(RTU模式) |
| IpAddress | String | IP地址(TCP模式) | 是(TCP模式) |
| Timeout | Integer | 通信超时时间(ms) | 是 |
| Slave.Id | Integer | 从站ID | 是 |
| Slave.Name | String | 从站名称 | 是 |
| Slave.FunctionCode | Integer | 功能码 | 是 |
| Slave.StartingRegister | Integer | 起始寄存器地址 | 是 |
| Slave.RegisterCount | Integer | 寄存器数量 | 是 |
### 4.3 网络通信配置参数
| 参数 | 类型 | 说明 | 是否必需 |
|-----|------|-----|--------|
| Port | Integer | 网络端口号 | 是 |
| IpAddress | String | IP地址(客户端) | 是(客户端) |
| MaxConnections | Integer | 最大连接数 | 是 |
| BufferSize | Integer | 缓冲区大小 | 是 |
| Timeout | Integer | 超时时间(ms) | 是 |
| EnableSsl | Boolean | 是否启用SSL | 否 |
| AutoReconnect | Boolean | 是否自动重连 | 否 |
| ReconnectInterval | Integer | 重连间隔(ms) | 否 |
| Path | String | WebSocket路径 | 是(WebSocket) |
| HeartbeatInterval | Integer | 心跳间隔(ms) | 否(WebSocket) |
## 5. 配置文件管理
### 5.1 配置文件位置
配置文件通常存储在以下位置:
- 主配置目录: `/Config/Communication/`
- EtherCAT配置: `/Config/Communication/EtherCAT.xml`
- Modbus配置: `/Config/Communication/Modbus.json`
- 网络通信配置: `/Config/Communication/Network.json`
### 5.2 配置文件加载流程
1. 系统启动时,自动加载通信配置文件
2. 验证配置文件格式和参数有效性
3. 根据配置初始化通信模块
4. 建立与各设备的通信连接
5. 监控通信状态,处理异常情况
### 5.3 动态配置更新
系统支持运行时动态更新通信配置:
- 通过API接口更新配置
- 通过Web界面更新配置
- 配置更新后自动重新连接设备
## 6. 通信诊断与故障排除
### 6.1 通信状态监控
系统提供通信状态监控功能:
- 连接状态
- 数据传输率
- 错误率
- 延迟时间
### 6.2 常见通信问题及解决方案
#### 6.2.1 EtherCAT通信问题
| 问题 | 可能原因 | 解决方案 |
|-----|---------|--------|
| 从站无法连接 | 网络连接故障 | 检查网线连接和网络适配器设置 |
| 通信周期性中断 | 网络干扰 | 检查接地、使用屏蔽线缆、调整周期时间 |
| 数据传输错误 | PDO映射错误 | 重新配置PDO映射,确保与从站设备匹配 |
#### 6.2.2 Modbus通信问题
| 问题 | 可能原因 | 解决方案 |
|-----|---------|--------|
| 无法建立连接 | 串口参数不匹配 | 确认波特率、数据位、停止位和校验位设置正确 |
| 超时错误 | 从站响应缓慢 | 增加超时时间,检查从站设备状态 |
| 数据错误 | 寄存器地址错误 | 确认从站设备的寄存器映射关系 |
#### 6.2.3 网络通信问题
| 问题 | 可能原因 | 解决方案 |
|-----|---------|--------|
| 连接被拒绝 | 目标设备未运行或防火墙阻止 | 确认目标设备运行状态和防火墙设置 |
| 连接断开 | 网络不稳定 | 检查网络设备,启用自动重连功能 |
| 数据传输缓慢 | 网络拥塞 | 增加缓冲区大小,优化数据传输策略 |
## 7. 通信性能优化建议
### 7.1 实时通信优化
- 使用高优先级进程
- 减少非必要的系统服务
- 优化操作系统设置,提高实时性能
- 使用专用网卡进行实时通信
### 7.2 数据传输优化
- 减少传输数据量
- 合理设置通信周期
- 采用高效的数据压缩算法
- 使用批量传输代替频繁小数据传输
### 7.3 网络优化
- 使用交换机而非集线器
- 隔离实时通信网络
- 减少网络中的设备数量
- 避免网络拓扑复杂度过高
\ No newline at end of file
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
此文件类型无法预览
此文件的差异被折叠, 点击展开。
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!