# 🔌 充电桩实时数据功能说明 ## ✅ 已完成的修改 ### 1. 数据模型更新(ChargeStation.cs) 添加了实时电压和电流字段: ```csharp /// /// 实时电压 (V) - 当前充电时的实际电压 /// [DisplayName("实时电压(V)")] public double RealTimeVoltage { get; set; } /// /// 实时电流 (A) - 当前充电时的实际电流 /// [DisplayName("实时电流(A)")] public double RealTimeCurrent { get; set; } ``` ### 2. 列表显示更新 #### ❌ 移除的列: - **功率(W)** - 功率列已移除 #### ✅ 新增的列: - **实时电压(V)** - 显示充电桩当前实际电压 - **实时电流(A)** - 显示充电桩当前实际电流 #### 列表结构(更新后): ``` ┌────────┬──────┬────────┬──────────┬────┬────────┬────────┬──────────┬──────────┬────┬────┬──────┬────┐ │ 编号 │ 名称 │ 类型 │ IP地址 │端口│ 电压(V)│ 电流(A)│实时电压(V)│实时电流(A)│状态│启用│站点ID│备注│ ├────────┼──────┼────────┼──────────┼────┼────────┼────────┼──────────┼──────────┼────┼────┼──────┼────┤ │CS12345 │1号桩 │标准 │192.168..│502 │220.0 │32.0 │215.5 │28.3 │充电│是 │1001 │... │ │CS12346 │2号桩 │快速 │192.168..│502 │380.0 │63.0 │0.0 │0.0 │空闲│是 │1002 │... │ └────────┴──────┴────────┴──────────┴────┴────────┴────────┴──────────┴──────────┴────┴────┴──────┴────┘ ``` ### 3. 界面更新 #### ❌ 移除的按钮: - **新增按钮** - 已从界面移除 #### ✅ 保留的按钮(重新排列): - **保存** - 位置调整到最左侧(20, 20),尺寸 100×50 - **删除** - 位置调整到中间(150, 20),尺寸 100×50 - **取消** - 位置调整到右侧(280, 20),尺寸 100×50 ``` ┌──────────────────────────────────┐ │ │ │ [ 保存 ] [ 删除 ] [ 取消 ]│ │ (蓝色) (红色) (默认) │ │ │ └──────────────────────────────────┘ ``` ### 4. 编辑区保留功能 **设置电压和电流功能完全保留**: ``` ┌─────────────────────────────────┐ │ 充电桩信息 │ ├─────────────────────────────────┤ │ │ │ 名称: [1号充电桩 ] │ │ 类型: [标准充电桩 ▼] │ │ IP地址:[192.168.1.100 ] │ │ 端口: [502 ▲▼] │ │ │ │ 电压(V):[220.0 ▲▼] │ ← 额定电压(设置值) │ 电流(A):[32.0 ▲▼] │ ← 额定电流(设置值) │ │ │ 状态: [空闲 ▼] │ │ ☑ 启用充电桩 │ │ ... │ └─────────────────────────────────┘ ``` --- ## 📊 字段说明 ### 电压和电流的区别 | 字段 | 类型 | 说明 | 用途 | |------|------|------|------| | **Voltage** | 额定电压 | 充电桩的设计电压(固定值) | 充电桩参数配置 | | **Current** | 额定电流 | 充电桩的设计电流(固定值) | 充电桩参数配置 | | **RealTimeVoltage** | 实时电压 | 当前实际工作电压(动态值) | 实时监控显示 | | **RealTimeCurrent** | 实时电流 | 当前实际工作电流(动态值) | 实时监控显示 | ### 典型场景示例 #### 场景1:充电桩空闲时 ``` 额定电压:220.0V 额定电流:32.0A 实时电压:0.0V ← 未在充电,实时值为0 实时电流:0.0A ← 未在充电,实时值为0 状态:空闲 ``` #### 场景2:充电桩充电中 ``` 额定电压:220.0V 额定电流:32.0A 实时电压:215.5V ← 实际充电电压 实时电流:28.3A ← 实际充电电流 状态:充电中 实时功率:6098.65W (215.5V × 28.3A) ``` #### 场景3:充电桩故障 ``` 额定电压:220.0V 额定电流:32.0A 实时电压:180.2V ← 电压异常偏低 实时电流:5.1A ← 电流异常偏低 状态:故障 告警:电压低于额定值20% ``` --- ## 💻 代码实现 ### 1. 创建充电桩时初始化 ```csharp var station = new ChargeStation { Name = "1号充电桩", Type = ChargeStationType.Standard, IpAddress = "192.168.1.100", Port = 502, // 额定参数(固定) Voltage = 220.0, Current = 32.0, // 实时参数(初始为0) RealTimeVoltage = 0.0, RealTimeCurrent = 0.0, Status = ChargeStationStatus.Idle }; ``` ### 2. 更新实时数据(模拟PLC数据) ```csharp /// /// 更新充电桩实时数据 /// public void UpdateRealTimeData(string stationId, double voltage, double current) { var dataService = ChargeStationDataService.Instance; var station = dataService.GetStationById(stationId); if (station != null) { station.RealTimeVoltage = voltage; station.RealTimeCurrent = current; dataService.UpdateStation(station, out string errorMsg); // 检查异常 CheckVoltageCurrentAbnormal(station); } } /// /// 检查电压电流是否异常 /// private void CheckVoltageCurrentAbnormal(ChargeStation station) { // 充电中才检查 if (station.Status == ChargeStationStatus.Charging) { // 电压偏差超过20% double voltageDiff = Math.Abs(station.RealTimeVoltage - station.Voltage) / station.Voltage; if (voltageDiff > 0.2) { Diagnosis.Log($"充电桩 {station.Name} 电压异常: " + $"额定{station.Voltage}V, 实时{station.RealTimeVoltage}V", "ChargeStation", true); } // 电流偏差超过20% double currentDiff = Math.Abs(station.RealTimeCurrent - station.Current) / station.Current; if (currentDiff > 0.2) { Diagnosis.Log($"充电桩 {station.Name} 电流异常: " + $"额定{station.Current}A, 实时{station.RealTimeCurrent}A", "ChargeStation", true); } } } ``` ### 3. 充电开始时设置实时数据 ```csharp /// /// 开始充电 /// public void StartCharging(string stationId, int carId) { var dataService = ChargeStationDataService.Instance; var station = dataService.GetStationById(stationId); if (station != null) { // 更新状态 station.Status = ChargeStationStatus.Charging; // 初始化实时数据(初始值约为额定值的90%) station.RealTimeVoltage = station.Voltage * 0.9; station.RealTimeCurrent = station.Current * 0.9; dataService.UpdateStation(station, out _); Diagnosis.Log($"车辆 {carId} 开始充电: " + $"充电桩 {station.Name}, " + $"实时电压 {station.RealTimeVoltage:F1}V, " + $"实时电流 {station.RealTimeCurrent:F1}A", "ChargeStation", true); } } ``` ### 4. 充电结束时清零实时数据 ```csharp /// /// 停止充电 /// public void StopCharging(string stationId, int carId) { var dataService = ChargeStationDataService.Instance; var station = dataService.GetStationById(stationId); if (station != null) { // 更新状态 station.Status = ChargeStationStatus.Idle; // 清零实时数据 station.RealTimeVoltage = 0.0; station.RealTimeCurrent = 0.0; dataService.UpdateStation(station, out _); Diagnosis.Log($"车辆 {carId} 充电完成: 充电桩 {station.Name}", "ChargeStation", true); } } ``` ### 5. 从PLC读取实时数据 ```csharp /// /// 从PLC读取充电桩实时数据 /// public void ReadRealTimeDataFromPLC() { var dataService = ChargeStationDataService.Instance; var stations = dataService.GetAllStations() .Where(s => s.Status == ChargeStationStatus.Charging) .ToList(); foreach (var station in stations) { try { // 从PLC读取实时电压和电流 // 这里需要根据实际PLC通信协议实现 double voltage = ReadVoltageFromPLC(station.IpAddress, station.Port); double current = ReadCurrentFromPLC(station.IpAddress, station.Port); // 更新实时数据 station.RealTimeVoltage = voltage; station.RealTimeCurrent = current; dataService.UpdateStation(station, out _); } catch (Exception ex) { Diagnosis.Log($"读取充电桩 {station.Name} 实时数据失败: {ex.Message}", "ChargeStation", true); } } } // 这些方法需要根据实际PLC协议实现 private double ReadVoltageFromPLC(string ip, int port) { // TODO: 实现PLC通信读取电压 return 0.0; } private double ReadCurrentFromPLC(string ip, int port) { // TODO: 实现PLC通信读取电流 return 0.0; } ``` --- ## 🔄 数据更新流程 ### 完整充电流程 ``` 1. 车辆到达充电站 └─> 分配空闲充电桩 └─> 状态: Idle → Reserved 2. 开始充电 └─> 状态: Reserved → Charging └─> 设置实时数据初始值 ├─> RealTimeVoltage = Voltage * 0.9 └─> RealTimeCurrent = Current * 0.9 3. 充电中(定时更新) └─> 每3-5秒从PLC读取实时数据 ├─> 更新 RealTimeVoltage ├─> 更新 RealTimeCurrent └─> 检查异常并告警 4. 充电完成 └─> 状态: Charging → Idle └─> 清零实时数据 ├─> RealTimeVoltage = 0.0 └─> RealTimeCurrent = 0.0 ``` --- ## 📋 JSON数据格式 保存到文件的数据包含实时字段: ```json { "StationId": "CS20240115123456", "Name": "1号充电桩", "Type": 0, "IpAddress": "192.168.1.100", "Port": 502, "Voltage": 220.0, "Current": 32.0, "RealTimeVoltage": 215.5, "RealTimeCurrent": 28.3, "Status": 1, "Enabled": true, "SiteId": 1001, "Remarks": "南区1号充电桩", "CreatedTime": "2024-01-15T12:34:56", "ModifiedTime": "2024-01-15T14:20:30" } ``` --- ## ✅ 使用检查清单 - [x] 数据模型添加实时电压和电流字段 - [x] 列表移除功率列 - [x] 列表添加实时电压和实时电流列 - [x] 界面移除新增按钮 - [x] 按钮重新排列 - [x] 保留设置电压和电流功能 - [x] 列表正确显示实时数据 - [x] 无编译错误 --- ## 📝 总结 ### ✅ 完成的功能 1. **数据模型** - 添加实时电压和电流字段 2. **列表显示** - 移除功率列,添加实时数据列 3. **界面优化** - 移除新增按钮,重新排列其他按钮 4. **功能保留** - 设置电压和电流功能完全保留 ### 💡 后续集成建议 1. **与PLC通信集成** - 实现从PLC读取实时电压和电流 - 定时更新实时数据(建议3-5秒) 2. **异常监控** - 实时监控电压电流偏差 - 超过阈值时触发告警 3. **数据统计** - 记录充电过程的电压电流曲线 - 分析充电效率和异常情况 4. **可视化展示** - 实时数据图表显示 - 历史数据趋势分析 **现在您可以在充电桩管理界面中查看实时电压和电流数据了!** 🎉