|
@@ -1,18 +1,27 @@
|
|
|
-using Aitex.Core.RT.DataCenter;
|
|
|
+using Aitex.Common.Util;
|
|
|
+using Aitex.Core.RT.ConfigCenter;
|
|
|
+using Aitex.Core.RT.DataCenter;
|
|
|
+using Aitex.Core.RT.Log;
|
|
|
+using Aitex.Core.Util;
|
|
|
using CyberX8_Core;
|
|
|
using MECF.Framework.Common.CommonData;
|
|
|
using MECF.Framework.Common.CommonData.PowerSupplier;
|
|
|
+using MECF.Framework.Common.Device.PowerSupplier;
|
|
|
+using MECF.Framework.Common.Device.Wago;
|
|
|
using MECF.Framework.Common.Net;
|
|
|
using MECF.Framework.Common.Utilities;
|
|
|
using MECF.Framework.Simulator.Core.Driver;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
+using System.Reflection;
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Timers;
|
|
|
+using System.Xml.Linq;
|
|
|
|
|
|
namespace CyberX8_Simulator.Devices
|
|
|
{
|
|
@@ -24,6 +33,7 @@ namespace CyberX8_Simulator.Devices
|
|
|
private const short STEP_PERIOD_START_ADDRESS = 0x1640;
|
|
|
private const short GOLD_CURRENT_SETTING_ADDRESS = 0x6102;
|
|
|
private const short GOLD_STEP_PERIOD_ADDRESS = 0x77D0;
|
|
|
+ private const short GOLD_STEP_PERIOD_START_ADDRESS = 0x7C50;
|
|
|
|
|
|
/// <summary>
|
|
|
/// 电源状态(00-cv输出,01-cc输出)
|
|
@@ -41,6 +51,7 @@ namespace CyberX8_Simulator.Devices
|
|
|
private int _currentLength = 0;
|
|
|
private DateTime _currentTime = DateTime.Now;
|
|
|
private bool _isGoldPower = false;
|
|
|
+ private int _currentSetScale;
|
|
|
|
|
|
private System.Timers.Timer _timer;
|
|
|
/// <summary>
|
|
@@ -72,8 +83,50 @@ namespace CyberX8_Simulator.Devices
|
|
|
_timer = new System.Timers.Timer();
|
|
|
_timer.Interval = 1000;
|
|
|
_timer.Elapsed += Timer_Elapsed;
|
|
|
+ InitializeParamater(port);
|
|
|
+ }
|
|
|
+ private void InitializeParamater(int port)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string oldXmlPath = PathManager.GetCfgDir();
|
|
|
+ string newXmlPath = oldXmlPath.Replace("CyberX8_Simulator", "CyberX8_RT") + "Devices\\PowerSupplierCfg-Simulator.xml";
|
|
|
+ PowerSupplierDeviceConfigCfg cfg = CustomXmlSerializer.Deserialize<PowerSupplierDeviceConfigCfg>(new FileInfo(newXmlPath));
|
|
|
+ if (cfg != null)
|
|
|
+ {
|
|
|
+ foreach (PowerSupplierDeviceConfig config in cfg.PowerSupplierDeviceConfigs)
|
|
|
+ {
|
|
|
+ if(config.Port != port)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ foreach (PowerSupplierDevice device in config.Devices)
|
|
|
+ {
|
|
|
+ if (device != null)
|
|
|
+ {
|
|
|
+ if (config.Type == 1 && device.UnitSetScale > device.UnitScale) //金槽电源
|
|
|
+ {
|
|
|
+ _currentSetScale = device.UnitSetScale / device.UnitScale;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _currentSetScale = device.UnitScale / device.UnitSetScale;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ LOG.WriteLog(eEvent.ERR_POWERSUPPLIER, "PowerSupplier", "Load power supplier xml failed");
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
|
|
{
|
|
|
if(_currentStep>=_cycle*_endStep)
|
|
@@ -93,7 +146,14 @@ namespace CyberX8_Simulator.Devices
|
|
|
_currentTime = DateTime.Now;
|
|
|
_currentLength = (int)(_powerSupplierDatas[_currentStep].Hour * 3600 + _powerSupplierDatas[_currentStep].Minute * 60 +
|
|
|
_powerSupplierDatas[_currentStep].Second);
|
|
|
- _powerSupplierDic[1].Current = (int)(_powerSupplierDatas[_currentStep].Current*10);
|
|
|
+ if (_isGoldPower)
|
|
|
+ {
|
|
|
+ _powerSupplierDic[1].Current = (int)(_powerSupplierDatas[_currentStep].Current);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _powerSupplierDic[1].Current = (int)(_powerSupplierDatas[_currentStep].Current * _currentSetScale);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -191,11 +251,11 @@ namespace CyberX8_Simulator.Devices
|
|
|
if (_isGoldPower)
|
|
|
{
|
|
|
int count = byteTransform.TransInt32(_powerSupplierSetPoint, 0);
|
|
|
- _powerSupplierDic[channel].Current = count / 100;
|
|
|
+ _powerSupplierDic[channel].Current = count / _currentSetScale;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- _powerSupplierDic[channel].Current = _powerSupplierDic[channel].CurrentSetting * 10;
|
|
|
+ _powerSupplierDic[channel].Current = _powerSupplierDic[channel].CurrentSetting * _currentSetScale;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -224,7 +284,7 @@ namespace CyberX8_Simulator.Devices
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- else if(command==0x10)
|
|
|
+ else if(command==0x10) //写多个寄存器
|
|
|
{
|
|
|
short startAddress = byteTransform.TransInt16(data, 8);
|
|
|
short length = byteTransform.TransInt16(data, 10);
|
|
@@ -259,14 +319,45 @@ namespace CyberX8_Simulator.Devices
|
|
|
_timer.Start();
|
|
|
OnWriteMessage(CreateWriteResponse(flag, channel, command, startAddress, length));
|
|
|
}
|
|
|
- else if(startAddress == GOLD_CURRENT_SETTING_ADDRESS)
|
|
|
+ else if(startAddress == GOLD_CURRENT_SETTING_ADDRESS) //设置电流 32位变量
|
|
|
{
|
|
|
+ _isGoldPower = true;
|
|
|
byte[] vauleData = new byte[4]; //0,1是高位,2,3是低位
|
|
|
Array.Copy(data, 13, vauleData, 0, 4);
|
|
|
_powerSupplierSetPoint = vauleData;
|
|
|
int count = byteTransform.TransInt32(vauleData, 0);
|
|
|
UpdateChannelGoldCurrent(flag, channel, command, (short)count);
|
|
|
}
|
|
|
+ else if(startAddress == GOLD_STEP_PERIOD_ADDRESS) //设置步阶数据 32位变量
|
|
|
+ {
|
|
|
+ _powerSupplierDatas.Clear();
|
|
|
+ int listCount = length / 12;
|
|
|
+ for (int i = 0; i < listCount; i++)
|
|
|
+ {
|
|
|
+ PowerSupplierStepPeriodData powerSupplierData = new PowerSupplierStepPeriodData();
|
|
|
+ powerSupplierData.Voltage = byteTransform.TransInt32(data, 13 + i * 24);
|
|
|
+ powerSupplierData.Current = byteTransform.TransInt32(data, 17 + i * 24) / _currentSetScale;
|
|
|
+ powerSupplierData.Hour = byteTransform.TransUInt16(data, 23 + i * 24);
|
|
|
+ powerSupplierData.Minute = byteTransform.TransUInt16(data, 27 + i * 24);
|
|
|
+ powerSupplierData.Second = byteTransform.TransUInt16(data, 31 + i * 24);
|
|
|
+ powerSupplierData.Microsecond = byteTransform.TransUInt16(data, 35 + i * 24);
|
|
|
+ _powerSupplierDatas.Add(powerSupplierData);
|
|
|
+ }
|
|
|
+ OnWriteMessage(CreateWriteResponse(flag, channel, command, startAddress, length));
|
|
|
+ }
|
|
|
+ else if (startAddress == GOLD_STEP_PERIOD_START_ADDRESS) //启动步阶数据 32位变量
|
|
|
+ {
|
|
|
+ _startStep = (byte)byteTransform.TransInt32(data, 13);
|
|
|
+ _endStep = (byte)byteTransform.TransInt32(data, 17);
|
|
|
+ _cycle = (byte)byteTransform.TransInt32(data, 21);
|
|
|
+ _currentLength = (_powerSupplierDatas[0].Hour * 3600 + _powerSupplierDatas[0].Minute * 60 +
|
|
|
+ _powerSupplierDatas[0].Second);
|
|
|
+ _powerSupplierDic[1].Current = (int)(_powerSupplierDatas[0].Current);
|
|
|
+ _currentTime = DateTime.Now;
|
|
|
+ _currentStep = 0;
|
|
|
+ _timer.Start();
|
|
|
+ OnWriteMessage(CreateWriteResponse(flag, channel, command, startAddress, length));
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|