using AutoMapper.Internal; using CapMachine.Core; using CapMachine.Wpf.Dtos; using CapMachine.Wpf.Models; using CapMachine.Wpf.Models.Tag; using CapMachine.Wpf.Models.Tag.Cell; using CapMachine.Wpf.PrismEvent; using HslCommunication; using HslCommunication.Profinet.Melsec; using HslCommunication.Profinet.Siemens; using Org.BouncyCastle.Utilities; using Prism.Events; using Prism.Mvvm; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Timers; using System.Windows; using static CapMachine.Wpf.Models.ComEnum; namespace CapMachine.Wpf.Services { /// /// 机器实时数据服务 /// public class MachineRtDataService : BindableBase { /// /// 事件聚合器 /// private IEventAggregator _EventAggregator { get; set; } public AlarmService AlarmService { get; } public ConfigService ConfigService { get; } public CanDriveService CanDriveService { get; } public CanFdDriveService CanFdDriveService { get; } public LinDriveService LinDriveService { get; } public SysRunService SysRunService { get; } /// /// PLCScanTask扫描Task /// private static Task PLCScanTask { get; set; } /// /// ScanTask扫描Task /// private static Task ScanTask { get; set; } /// /// 西门子连接驱动程序 /// public SiemensS7Net SiemensDrive { get; set; } /// /// 三菱连接驱动程序 /// public MelsecMcNet MelsecMcNetDrive { get; set; } private bool _LinkState; /// /// PLC连接状态 /// public bool LinkState { get { return _LinkState; } set { _LinkState = value; RaisePropertyChanged(); } } /// /// 周期定时器 /// private System.Timers.Timer CycleTimer { get; set; } /// /// 界面更新数据 /// private bool IsValueShow { get; set; } = true; /// /// 系统拓展数据 /// public SysExdInfo CurSysExdInfo { get; set; } /// /// 布尔拓展信息 /// public SysExdBoolInfo SysExdBoolInfos { get; set; } ///// ///// Tag数据集合 ///// //public List ListRtDataModel { get; set; } /// /// 标签管理中心 /// public TagManager TagManger { get; set; } = new TagManager(); /// /// 扫描线程使能 /// public bool ThreadEnable { get; set; } = true; /// /// 历史数据 /// public List HistoryData { get; set; } = new List(); /// /// 手自动切换的条件 /// public AutoHandSwtichCondition AutoHandSwtichConditionState { get; set; } = new AutoHandSwtichCondition(); /// /// 实例化函数 /// /// public MachineRtDataService(IEventAggregator eventAggregator, AlarmService alarmService, ConfigService configService, CanDriveService canDriveService, CanFdDriveService canFdDriveService, LinDriveService linDriveService, SysRunService sysRunService)//, AlarmService alarmService { //ConcurrentDictionary keyValuePairs = new ConcurrentDictionary(); //Stopwatch stopwatch = new Stopwatch(); ////第一次计时 //stopwatch.Start(); //启动Stopwatch //stopwatch.Stop(); //停止Stopwatch //Console.WriteLine("Add Elapsed output runTime:{0}", stopwatch.Elapsed.ToString()); //MelsecMcNetDrive. //事件服务 _EventAggregator = eventAggregator; AlarmService = alarmService; ConfigService = configService; CanDriveService = canDriveService; CanFdDriveService = canFdDriveService; LinDriveService = linDriveService; SysRunService = sysRunService; //秒触发一次 CycleTimer = new System.Timers.Timer(500); CycleTimer.Elapsed += RecoredCycleAction; CycleTimer.AutoReset = true; CycleTimer.Enabled = true; #region 标签管理 #region 标签管理 // 从配置文件加载标签 string tagConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TagConfig", "SysTags.json"); try { TagManger.LoadTagsFromConfig(tagConfigPath); Debug.WriteLine("已成功从配置文件加载标签"); } catch (Exception ex) { // 处理异常,如记录日志 Debug.WriteLine($"加载标签配置文件失败: {ex.Message}"); // 可以在这里添加备用的手动添加标签的代码 } #endregion //TagManger.LoadTagsFromConfig("E:\\MyTest\\VS2022\\CapMachine\\CapMachine\\CapMachine.Wpf\\TagConfig\\ShortTags.json"); //TagManger.AddTag(new ShortValueTag() //{ // Id = 10, // Name = "转速[rpm]", // NameNoUnit = "转速", // EnName = "Speed", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "rpm", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15000", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 0 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 20, // Name = "排气压力[BarA]", // NameNoUnit = "排气压力", // EnName = "ExPress", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 100, // Unit = "BarA", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15002", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 2 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 30, // Name = "吸气压力[BarA]", // NameNoUnit = "吸气压力", // EnName = "InhPress", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 100, // Unit = "BarA", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15004", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 4 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 40, // Name = "吸气温度[℃]", // NameNoUnit = "吸气温度", // EnName = "InhTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15006", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 6 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 50, // Name = "COND1温度[℃]", // NameNoUnit = "COND1温度", // EnName = "Cond1Temp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15008", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 8 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 60, // Name = "润滑油压力[BarA]", // NameNoUnit = "润滑油压力", // EnName = "LubePress", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 100, // Unit = "BarA", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15010", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 10 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 70, // Name = "COND2压力[BarA]", // NameNoUnit = "COND2压力", // EnName = "Cond2Press", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 100, // Unit = "BarA", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15012", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 12 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 80, // Name = "OCR[%]", // NameNoUnit = "OCR", // EnName = "OCR", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "%", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15014", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 14 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 90, // Name = "HV[V]", // NameNoUnit = "HV[V]", // EnName = "HV", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "V", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15016", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 16 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 100, // Name = "HV[A]", // NameNoUnit = "HV[A]", // EnName = "HVCur", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 100, // Unit = "A", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15018", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 18 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 110, // Name = "HV[W]", // NameNoUnit = "HV[W]", // EnName = "HVPw", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "W", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15020", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 20 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 120, // Name = "LV[V]", // NameNoUnit = "LV[V]", // EnName = "LV", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "V", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15022", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 22 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 130, // Name = "LV[A]", // NameNoUnit = "LV[A]", // EnName = "LVCur", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 100, // Unit = "A", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15024", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 24 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 140, // Name = "环境温度[℃]", // NameNoUnit = "环境温度", // EnName = "EnvTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15026", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 26 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 150, // Name = "环境湿度[%]", // NameNoUnit = "环境湿度", // EnName = "EnvRH", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "%", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15028", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 28 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 160, // Name = "OS1温度[℃]", // NameNoUnit = "OS1温度", // EnName = "OS1Temp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15030", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 30 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 170, // Name = "OS2温度[℃]", // NameNoUnit = "OS2温度", // EnName = "OS2Temp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15032", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 32 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 180, // Name = "COND2温度[℃]", // NameNoUnit = "COND2温度", // EnName = "Cond2Temp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15034", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 34 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 190, // Name = "EVAP出口温度[℃]", // NameNoUnit = "EVAP出口温度", // EnName = "EVAPExpTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15036", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 36 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 200, // Name = "冷媒流量[L/min]", // NameNoUnit = "冷媒流量", // EnName = "VRV", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "L/min", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15038", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 38 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 210, // Name = "润滑油流量[L/min]", // NameNoUnit = "润滑油流量", // EnName = "LubeFlow", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "L/min", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15040", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 40 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 220, // Name = "排气温度[℃]", // NameNoUnit = "排气温度", // EnName = "ExTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15042", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 42 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 230, // Name = "膨胀阀前压力[BarA]", // NameNoUnit = "膨胀阀前压力", // EnName = "TxvFrPress", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 100, // Unit = "BarA", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15044", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 44 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 240, // Name = "膨胀阀前温度[℃]", // NameNoUnit = "膨胀阀前温度", // EnName = "TxvFrTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15046", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 46 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 250, // Name = "EVAP出口压力[BarA]", // NameNoUnit = "EVAP出口压力", // EnName = "EVAPExpPress", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 100, // Unit = "BarA", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15048", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 48 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 260, // Name = "腔内压力[BarA]", // NameNoUnit = "腔内压力", // EnName = "IntrplPress", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 100, // Unit = "BarA", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15050", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 50 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 270, // Name = "压缩机表面温度[℃]", // NameNoUnit = "压缩机表面温度", // EnName = "CapSurfTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15052", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 52 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 280, // Name = "PTC流量[L/min]", // NameNoUnit = "PTC流量", // EnName = "PTCFlow", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "L/min", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15054", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 54 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 290, // Name = "PTC入水温度[℃]", // NameNoUnit = "PTC入水温度", // EnName = "PTCEntTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15056", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 56 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 300, // Name = "PTC出水温度[℃]", // NameNoUnit = "PTC出水温度", // EnName = "PTCExpTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15058", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 58 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 310, // Name = "通讯Cmp母线电流[A]", // NameNoUnit = "通讯Cmp母线电流", // EnName = "ComCapBusCur", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 100, // Unit = "A", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15060", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 60 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 320, // Name = "通讯Cmp母线电压[V]", // NameNoUnit = "通讯Cmp母线电压", // EnName = "ComCapBusVol", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "V", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15062", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 62 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 330, // Name = "通讯Cmp逆变器温度[℃]", // NameNoUnit = "通讯Cmp逆变器温度", // EnName = "ComCapInvTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15064", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 64 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 340, // Name = "通讯Cmp相电流[A]", // NameNoUnit = "通讯Cmp相电流", // EnName = "ComCapPhCur", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 100, // Unit = "A", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15066", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 66 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 350, // Name = "通讯Cmp功率[W]", // NameNoUnit = "通讯Cmp功率", // EnName = "ComCapPw", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "W", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15068", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 68 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 360, // Name = "通讯Cmp芯片温度[℃]", // NameNoUnit = "通讯Cmp芯片温度", // EnName = "ComCapChipTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15070", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 70 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 370, // Name = "通讯PTC入水温度[℃]", // NameNoUnit = "通讯PTC入水温度", // EnName = "ComPTCEntTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15072", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 72 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 380, // Name = "通讯PTC出水温度[℃]", // NameNoUnit = "通讯PTC出水温度", // EnName = "ComPTCExpTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 10, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15074", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 74 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 390, // Name = "通讯PTC峰值电流[A]", // NameNoUnit = "通讯PTC峰值电流", // EnName = "ComPTCPeakCur", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "A", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15076", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 76 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 400, // Name = "通讯PTC母线电流[A]", // NameNoUnit = "通讯PTC母线电流", // EnName = "ComPTCBusCur", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 100, // Unit = "A", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15078", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 78 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 410, // Name = "通讯PTC膜温[℃]", // NameNoUnit = "通讯PTC膜温", // EnName = "ComPTCFlmTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15080", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 80 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 420, // Name = "通讯PTC模块温度[℃]", // NameNoUnit = "通讯PTC模块温度", // EnName = "ComPTCMdTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15082", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 82 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 430, // Name = "液冷媒流量[kg/h]", // NameNoUnit = "液冷媒流量", // EnName = "LiqRefFlow", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "kg/h", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15084", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 84 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 440, // Name = "干度流量[kg/h]", // NameNoUnit = "干度流量", // EnName = "DryFlow", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "kg/h", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15086", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 86 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 450, // Name = "H5吸气混合器温度[℃]", // NameNoUnit = "H5吸气混合器温度", // EnName = "H5InhMixTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15088", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 88 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 460, // Name = "COND循环水温[℃]", // NameNoUnit = "COND循环水温", // EnName = "CONDCirWaterTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15090", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 90 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 470, // Name = "SUBCOOL出口温度[℃]", // NameNoUnit = "SUBCOOL出口温度", // EnName = "SubcoolOutTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15092", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 92 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 480, // Name = "吸气混合器出口温度[℃]", // NameNoUnit = "吸气混合器出口温度", // EnName = "InhMixOutTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15094", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 94 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 490, // Name = "H1出口温度[℃]", // NameNoUnit = "H1出口温度", // EnName = "H1OutTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15096", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 96 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 500, // Name = "S.C循环水温[℃]", // NameNoUnit = "S.C循环水温", // EnName = "SCCirWaterTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15098", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 98 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 510, // Name = "EVAP循环水温[℃]", // NameNoUnit = "EVAP循环水温", // EnName = "EvapCirWaterTemp", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "℃", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15100", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 100 }, //}); //TagManger.AddTag(new ShortValueTag() //{ // Id = 520, // Name = "吸气混合器出口压力[BarA]", // NameNoUnit = "吸气混合器出口压力", // EnName = "InhMixOutPress", // Group = "采集", // MinValue = 0, // MaxValue = 10000, // IsMeter = false, // DecimalPoint = 0, // Precision = 1, // Unit = "BarA", // DataType = TagDataType.Short, // RWInfo = RWInfo.PLCRead, // PVModel = new MeterValueAttrCell() { Address = "VW15102", EngValue = 0, EngValueStr = "", Block = "PV", BlockIndex = 102 }, //}); #endregion ListHandSwitchData = new List() { new HandSwitchData(){Name="自动",ActionAddress="M0.0",StateAddress="M0.0" }, new HandSwitchData(){Name="抽真空",ActionAddress="M0.1",StateAddress="V15.2" }, //new HandSwitchData(){Name="复位",ActionAddress="M0.2",StateAddress="M0.2" },放到上侧的按钮区域了 //new HandSwitchData(){Name="消音",ActionAddress="M0.3",StateAddress="M0.3" },放到上侧的按钮区域了 new HandSwitchData(){Name="HV电源",ActionAddress="M1.1",StateAddress="Q0.1" }, new HandSwitchData(){Name="HV启动",ActionAddress="M1.2",StateAddress="Q0.6" }, new HandSwitchData(){Name="LV电源",ActionAddress="M1.3",StateAddress="Q0.2" }, new HandSwitchData(){Name="水泵",ActionAddress="M1.4",StateAddress="Q0.3" }, new HandSwitchData(){Name="冷凝器电加热",ActionAddress="M1.5",StateAddress="Q0.4" }, new HandSwitchData(){Name="吸气混合器电加热",ActionAddress="M1.6",StateAddress="Q0.5" }, new HandSwitchData(){Name="吸排气球阀",ActionAddress="M1.7",StateAddress="Q0.7" }, new HandSwitchData(){Name="试验箱",ActionAddress="M2.0",StateAddress="V15.0" }, new HandSwitchData(){Name="水SEV1",ActionAddress="M2.1",StateAddress="Q1.0" }, new HandSwitchData(){Name="水SEV2",ActionAddress="M2.2",StateAddress="Q1.1" }, new HandSwitchData(){Name="HCV1",ActionAddress="M2.3",StateAddress="Q1.2" }, new HandSwitchData(){Name="HCV2",ActionAddress="M2.4",StateAddress="Q1.3" }, new HandSwitchData(){Name="ECV1",ActionAddress="M2.5",StateAddress="Q1.4" }, new HandSwitchData(){Name="ECV2",ActionAddress="M2.6",StateAddress="Q1.5" }, new HandSwitchData(){Name="使能",ActionAddress="M2.7",StateAddress="V15.1" }, }; InitialPLCCom(); //拓展的参数信息 CurSysExdInfo = new SysExdInfo(SiemensDrive); SysExdBoolInfos = new SysExdBoolInfo(SiemensDrive); //PubRtDataStart(); } #region 手自动的操作 //// ///// 手自动切换集合数据 ///// public List ListHandSwitchData { get; set; } /// /// 程序复位 /// /// public bool SysReset() { return true; //取消XXX var FindData = ListHandSwitchData.Where(a => a.Name == "复位"); if (FindData.Count() > 0) { var Result = SiemensDrive.Write(FindData.First().ActionAddress, true); if (Result.IsSuccess) { return true; } else { return false; } } return false; } /// /// 程序消音 /// /// public bool SysMute() { return true; //取消XXX var FindData = ListHandSwitchData.Where(a => a.Name == "消音"); if (FindData.Count() > 0) { var Result = SiemensDrive.Write(FindData.First().ActionAddress, true); if (Result.IsSuccess) { return true; } else { return false; } } return false; } /// /// 程序Start /// /// public bool SysStart() { return true; //取消XXX //var Result = SiemensDrive.Write("M0.4", true); //if (Result.IsSuccess) //{ // return true; //} //else //{ // return false; //} } /// /// 程序结束 /// /// public bool SysEnd() { return true; //取消XXX var Result = SiemensDrive.Write("M0.7", true); if (Result.IsSuccess) { return true; } else { return false; } } /// /// 程序暂停 /// 取反 /// /// public bool SysPause() { return true; //取消XXX var StateResult = SiemensDrive.ReadBool("M0.6"); if (StateResult.IsSuccess) { if (StateResult.Content == true) { var Result = SiemensDrive.Write("M0.6", false); if (Result.IsSuccess) { return true; } else { return false; } } else { var Result = SiemensDrive.Write("M0.6", true); if (Result.IsSuccess) { return true; } else { return false; } } } return false; } #endregion /// /// UI更新 /// /// /// /// private void RecoredCycleAction(object? sender, ElapsedEventArgs e) { //IsValueShow = !IsValueShow; } /// /// 初始化PLC通信 /// private void InitialPLCCom() { var IPInfo = ConfigHelper.GetValue("PLCIP"); SiemensDrive = new SiemensS7Net(SiemensPLCS.S200Smart, IPInfo); // 连接对象 OperateResult connect = SiemensDrive.ConnectServer(); if (!connect.IsSuccess)//连接失败 { LinkState = false; Console.WriteLine("connect failed:" + connect.Message); MessageBox.Show($"PLC连接失败:{IPInfo}"); //return; } else//连接成功 { LinkState = true; } //扫描线程成功 RtScanDeviceStart(); } public const string ConstShortType = "Int16"; public const string ConstUShortType = "UInt16"; public const string ConstIntType = "Int32"; public const string ConstUIntType = "UInt32"; public const string ConstLongType = "Int64"; public const string ConstULongType = "UInt64"; public const string ConstByteType = "Byte"; public const string ConstCharType = "Char"; public const string ConstFloatType = "Single"; public const string ConstDoubleType = "Double"; public const string ConstDecimalType = "Decimal"; public const string ConstBoolType = "Boolean"; //private Random random = new Random(); private int IsShowCount = 0; private OperateResult OperateResultShort { get; set; } /// /// SV数据 /// private OperateResult OperateResultSVShort { get; set; } /// /// MV数据 /// private OperateResult OperateResultMVShort { get; set; } private Random Random { get; set; } = new Random(); /// /// 报警结果集合 /// private OperateResult OperateResultAlarm { get; set; } /// /// 压缩机使能信号 /// 压缩机使能信号 /// 压缩机速度控制 /// 压缩机功率限制 /// 加热器使能信号 ///加热器功率给定 ///水流量信号给定 ///加热器目标水温 /// private OperateResult OperateResultValue { get; set; } /// /// CAP的使能状态 /// private OperateResult OperateResultCapEnable { get; set; } /// /// 时间诊断 /// private Stopwatch DiagnosticsTime { get; set; } = new Stopwatch(); /// /// PV整块读取数据 /// private OperateResult OperateResultBlockPVRead { get; set; } /// /// PLC扫描线程 /// private void RtScanDeviceStart() { PLCScanTask = Task.Run(async () => { Stopwatch stopwatch = new Stopwatch(); while (ThreadEnable) { await Task.Delay(100); //await Task.CompletedTask; DiagnosticsTime.Reset(); DiagnosticsTime.Start(); try { //stopwatch.Start(); //启动Stopwatch //CANLIN数据读取到TagManger.DicTags数据中心中,上面的操作是itemWrite反写到PLC中 foreach (var itemCanLinGroup in TagManger.DicTags) { //转速特殊处理,因为在数据集合中叫做【转速】,在CANLIN中叫做【通讯Cmp转速】 if (itemCanLinGroup.Value.NameNoUnit == "转速") { switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin) { case CanLinEnum.Can: //通信转速 Dbc中间配置名称的转速数据读取出来 给PLC 取消XXX if (TagManger.TryGetPVModel(itemCanLinGroup.Key, out MeterValueAttrCell? CanpVModel)) { CanpVModel!.EngValue = CanDriveService.GetDbcSpeedValueBySpeedName("通讯Cmp转速"); SiemensDrive.Write(CanpVModel!.ReWritePLCAddress!, (short)CanDriveService.GetDbcSpeedValueBySpeedName("通讯Cmp转速")); //pVModel.EngSrcValue = 0; } break; case CanLinEnum.CANFD: //通信转速 Dbc中间配置名称的转速数据读取出来 给PLC 取消XXX if (TagManger.TryGetPVModel(itemCanLinGroup.Key, out MeterValueAttrCell? CanfdpVModel)) { CanfdpVModel!.EngValue = CanFdDriveService.GetDbcSpeedValueBySpeedName("通讯Cmp转速"); SiemensDrive.Write(CanfdpVModel!.ReWritePLCAddress!, (short)CanFdDriveService.GetDbcSpeedValueBySpeedName("通讯Cmp转速")); //pVModel.EngSrcValue = 0; } break; case CanLinEnum.Lin: //通信转速 Dbc中间配置名称的转速数据读取出来 给PLC 取消XXX if (TagManger.TryGetPVModel(itemCanLinGroup.Key, out MeterValueAttrCell? LinpVModel)) { LinpVModel!.EngValue = LinDriveService.GetLdfSpeedValueBySpeedName("通讯Cmp转速"); SiemensDrive.Write(LinpVModel!.ReWritePLCAddress!, (short)LinDriveService.GetLdfSpeedValueBySpeedName("通讯Cmp转速")); } break; default: break; } //找到后继续下一个 continue; } //只处理CANLIN的数据 if (itemCanLinGroup.Value.Group == "压缩机") { //尝试获取模型信息 if (TagManger.TryGetCapPVModelByShortValueTag(itemCanLinGroup.Key, out MeterValueAttrCell? pVModel)) { //没有这个地址则跳过 if (String.IsNullOrEmpty(pVModel!.ReWritePLCAddress)) continue; switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin) { case CanLinEnum.Can: //取得压缩机的CANLIN数据到数据集合中 pVModel!.EngValue = CanDriveService.GetDbcValueByName(itemCanLinGroup.Value.NameNoUnit); //写入到PLC中 SiemensDrive.Write(pVModel!.ReWritePLCAddress!, (short)(CanDriveService.GetDbcValueByName(itemCanLinGroup.Value.NameNoUnit) * itemCanLinGroup.Value.Precision)); break; case CanLinEnum.CANFD: //取得压缩机的CANLIN数据到数据集合中 pVModel!.EngValue = CanFdDriveService.GetDbcValueByName(itemCanLinGroup.Value.NameNoUnit); //写入到PLC中 SiemensDrive.Write(pVModel!.ReWritePLCAddress!, (short)(CanFdDriveService.GetDbcValueByName(itemCanLinGroup.Value.NameNoUnit) * itemCanLinGroup.Value.Precision)); break; case CanLinEnum.Lin: //取得压缩机的CANLIN数据 pVModel!.EngValue = LinDriveService.GetLdfValueByName(itemCanLinGroup.Value.NameNoUnit); //写入到PLC中 SiemensDrive.Write(pVModel!.ReWritePLCAddress!, (short)(LinDriveService.GetLdfValueByName(itemCanLinGroup.Value.NameNoUnit) * itemCanLinGroup.Value.Precision)); break; case CanLinEnum.No: break; default: break; } } } } //PV批量读取 OperateResultBlockPVRead = SiemensDrive.Read("VW15000", 200); if (OperateResultBlockPVRead.IsSuccess) { foreach (var itemBlockReadTag in TagManger.DicTags) { if (itemBlockReadTag.Key.Contains("转速")) { //转速不需要PLC读取 continue; } //需要从PLC读取的标签才算 if ((itemBlockReadTag.Value.RWInfo == RWInfo.PLCRead || itemBlockReadTag.Value.RWInfo == RWInfo.Control) && TagManger.TryGetPVModel(itemBlockReadTag.Key, out MeterValueAttrCell pVModel)) { //地址为空的话则下一个 if (string.IsNullOrEmpty(pVModel!.Address)) continue; //给PvModel的原始属性赋值 pVModel!.EngSrcValue = SiemensDrive.ByteTransform.TransInt16(OperateResultBlockPVRead.Content, pVModel.BlockIndex); } } //通信状态 LinkState = true; } else { //通信状态 LinkState = false; } ////读取报警信息 取消报警XXX //OperateResultAlarm = SiemensDrive.ReadBool("V0.0", 15); //if (OperateResultAlarm.IsSuccess) //{ // foreach (var item in AlarmService.ListAlarmRunCell) // { // item.UpdateBoolValue(OperateResultAlarm.Content[item.Index]); // } //} //压缩机使能信号实时赋值 OperateResultValue = SiemensDrive.ReadInt16("VW14000", 30); if (OperateResultValue.IsSuccess) { //压缩机使能信号实时赋值 switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin) { case CanLinEnum.Can: //获取PLC的使能状态,更新到CAN的使能状态 CanDriveService.UpdateCapEnableCmdData(OperateResultValue.Content[0] == 0 ? false : true); break; case CanLinEnum.CANFD: //获取PLC的使能状态,更新到CAN的使能状态 CanFdDriveService.UpdateCapEnableCmdData(OperateResultValue.Content[0] == 0 ? false : true); break; case CanLinEnum.Lin: //获取PLC的使能状态,更新到LIN的使能状态 LinDriveService.UpdateCapEnableCmdData(OperateResultValue.Content[0] == 0 ? false : true); break; default: break; } //压缩机速度实时赋值 switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin) { case CanLinEnum.Can: //获取PLC的使能状态,更新到CAN的使能状态 CanDriveService.UpdateSpeedCmdData(OperateResultValue.Content[1]); break; case CanLinEnum.CANFD: //获取PLC的使能状态,更新到CAN的使能状态 CanFdDriveService.UpdateSpeedCmdData(OperateResultValue.Content[1]); break; case CanLinEnum.Lin: //获取PLC的使能状态,更新到LIN的使能状态 LinDriveService.UpdateSpeedCmdData(OperateResultValue.Content[1]); break; default: break; } //压缩机压缩机功率限制实时赋值 switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin) { case CanLinEnum.Can: //获取PLC的功率限制,更新到CAN的功率限制 CanDriveService.UpdateCapPwLimitCmdData(OperateResultValue.Content[2]); break; case CanLinEnum.CANFD: //获取PLC的功率限制,更新到CAN的功率限制 CanFdDriveService.UpdateCapPwLimitCmdData(OperateResultValue.Content[2]); break; case CanLinEnum.Lin: //获取PLC的功率限制,更新到LIN的功率限制 LinDriveService.UpdateCapPwLimitCmdData(OperateResultValue.Content[2]); break; default: break; } //压缩机 PTC使能 实时赋值 switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin) { case CanLinEnum.Can: //获取PLC的 PTC使能,更新到CAN的 PTC使能 CanDriveService.UpdateCapPTCEnableCmdData(OperateResultValue.Content[10] == 0 ? false : true); break; case CanLinEnum.CANFD: //获取PLC的 PTC使能,更新到CAN的 PTC使能 CanFdDriveService.UpdateCapPTCEnableCmdData(OperateResultValue.Content[10] == 0 ? false : true); break; case CanLinEnum.Lin: //获取PLC的 PTC使能,更新到LIN的 PTC使能 LinDriveService.UpdateCapPTCEnableCmdData(OperateResultValue.Content[10] == 0 ? false : true); break; default: break; } //压缩机 PTC功率 实时赋值 switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin) { case CanLinEnum.Can: //获取PLC的 PTC功率,更新到CAN的 PTC功率 CanDriveService.UpdateCapPTCPwCmdData(OperateResultValue.Content[11]); break; case CanLinEnum.CANFD: //获取PLC的 PTC功率,更新到CAN的 PTC功率 CanFdDriveService.UpdateCapPTCPwCmdData(OperateResultValue.Content[11]); break; case CanLinEnum.Lin: //获取PLC的 PTC功率,更新到LIN的 PTC功率 LinDriveService.UpdateCapPTCPwCmdData(OperateResultValue.Content[11]); break; default: break; } //压缩机 PTC水流量信号 实时赋值 switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin) { case CanLinEnum.Can: //获取PLC的 PTC水流量信号,更新到CAN的 PTC水流量信号 CanDriveService.UpdateCapPTCFlowCmdData(OperateResultValue.Content[12] * 1.0 / 100); break; case CanLinEnum.CANFD: //获取PLC的 PTC水流量信号,更新到CAN的 PTC水流量信号 CanFdDriveService.UpdateCapPTCFlowCmdData(OperateResultValue.Content[12] * 1.0 / 100); break; case CanLinEnum.Lin: //获取PLC的 PTC水流量信号,更新到LIN的 PTC水流量信号 LinDriveService.UpdateCapPTCFlowCmdData(OperateResultValue.Content[12] * 1.0 / 100); break; default: break; } //压缩机 PTC水温 实时赋值 switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin) { case CanLinEnum.Can: //获取PLC的 PTC水温,更新到CAN的 PTC水温 CanDriveService.UpdateCapPTCWaterTempCmdData(OperateResultValue.Content[13]); break; case CanLinEnum.CANFD: //获取PLC的 PTC水温,更新到CAN的 PTC水温 CanFdDriveService.UpdateCapPTCWaterTempCmdData(OperateResultValue.Content[13]); break; case CanLinEnum.Lin: //获取PLC的 PTC水温,更新到LIN的 PTC水温 LinDriveService.UpdateCapPTCWaterTempCmdData(OperateResultValue.Content[13]); break; default: break; } } //循环读取手自动切换 //foreach (var item in ListHandSwitchData) //{ // item.StateOperateResult = SiemensDrive.ReadBool(item.StateAddress); // if (item.StateOperateResult.IsSuccess) // { // item.State = item.StateOperateResult.Content; // //根据PLC得到执行的步骤数据,更新到CAN和LIN的数据 // if (item.Name!.Equals("使能")) // { // switch (ConfigService.CanLinRunStateModel.CurSysSelectedCanLin) // { // case CanLinEnum.Can: // //获取PLC的使能状态,更新到CAN的使能状态 // CanDriveService.UpdateCapEnableCmdData(item.State); // break; // case CanLinEnum.Lin: // //获取PLC的使能状态,更新到LIN的使能状态 // LinDriveService.UpdateCapEnableCmdData(item.State); // break; // default: // break; // } // } // } //} ////拓展信息的展示 取消XXX //foreach (var itemQuickTag in CurSysExdInfo.QuickTags) //{ // itemQuickTag.OperateResultSource = SiemensDrive.Read(itemQuickTag.ValueAddress, itemQuickTag.ByteLength); //} //CurSysExdInfo.SumRunTime(); ////布尔拓展信息的展示 取消XXX //foreach (var itemQuickTag in SysExdBoolInfos.QuickTags) //{ // itemQuickTag.OperateResultSource = SiemensDrive.Read(itemQuickTag.ValueAddress, itemQuickTag.ByteLength); //} } catch (Exception ex) { //LogService.Info($"时间:{DateTime.Now.ToString()}-【Meter】-{ex.Message}"); } DiagnosticsTime.Stop(); ConfigService.PlcCycleTime = (int)DiagnosticsTime.Elapsed.TotalMilliseconds; //Console.WriteLine($"扫描时间:{DiagnosticsTime.Elapsed.TotalMilliseconds.ToString()}"); } }); } private Random random = new Random(); /// ///发布实时数据 /// private void PubRtDataStart() { ScanTask = Task.Run(async () => { while (ThreadEnable) { try { await Task.Delay(1000); //_EventAggregator.GetEvent().Publish(new List() //{ // new Models.ChartRtValue(){Name="EVA风量",Value=random.NextDouble()*100,Unit="℃"}, // new Models.ChartRtValue(){Name="中间轴转速",Value=random.NextDouble()*100,Unit="℃"}, // new Models.ChartRtValue(){Name="加热电力",Value=random.NextDouble()*100,Unit="℃"}, // new Models.ChartRtValue(){Name="加湿电力",Value=random.NextDouble()*100,Unit="℃"}, // new Models.ChartRtValue(){Name="EMPCV电流",Value=random.NextDouble()*100,Unit="℃"}, // new Models.ChartRtValue(){Name="INJ压力",Value=random.NextDouble()*100,Unit="℃"}, // new Models.ChartRtValue(){Name="冷媒流量",Value=random.NextDouble()*100,Unit="℃"}, //}); } catch (Exception ex) { } } }); } } }