Bläddra i källkod

add gold power supplier

chenkui 1 månad sedan
förälder
incheckning
6b3c82ab53

+ 17 - 17
CyberX8_RT/Config/Devices/PowerSupplierCfg-Simulator.xml

@@ -1,59 +1,59 @@
 <?xml version="1.0" encoding="utf-8"?>
 <PowerSupplierConfig>
   <PowerSupplierDeviceConfig Name="Power1" IpAddress="127.0.0.1" Port="820" Type="1" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power1-1" Address="1" />
+    <Device Name="Power1-1" Address="1"  UnitSetScale="1000000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
-  <PowerSupplierDeviceConfig Name="Power2" IpAddress="127.0.0.1" Port="821" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power2-1" Address="1" />
+  <!--<PowerSupplierDeviceConfig Name="Power2" IpAddress="127.0.0.1" Port="821" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
+    <Device Name="Power2-1" Address="1"  UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
   <PowerSupplierDeviceConfig Name="Power3" IpAddress="127.0.0.1" Port="822" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power3-1" Address="1" />
+    <Device Name="Power3-1" Address="1"  UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
   <PowerSupplierDeviceConfig Name="Power4" IpAddress="127.0.0.1" Port="823" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power4-1" Address="1" />
+    <Device Name="Power4-1" Address="1"  UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
   
   <PowerSupplierDeviceConfig Name="Power5" IpAddress="127.0.0.1" Port="824" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power5-1" Address="1" />
+    <Device Name="Power5-1" Address="1"  UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
   
   <PowerSupplierDeviceConfig Name="Power6" IpAddress="127.0.0.1" Port="825" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power6-1" Address="1" />
+    <Device Name="Power6-1" Address="1"  UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
   
   <PowerSupplierDeviceConfig Name="Power7" IpAddress="127.0.0.1" Port="826" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power7-1" Address="1" />
+    <Device Name="Power7-1" Address="1" UnitSetScale="1000" UnitScale="10000"  />
   </PowerSupplierDeviceConfig>
   
   <PowerSupplierDeviceConfig Name="Power8" IpAddress="127.0.0.1" Port="827" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power8-1" Address="1" />
+    <Device Name="Power8-1" Address="1"  UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
 
 	<PowerSupplierDeviceConfig Name="Power9" IpAddress="127.0.0.1" Port="828" Type="0" SendTimeout="2000" RecvTimeout="2000">
-		<Device Name="Power9-1" Address="1" />
+		<Device Name="Power9-1" Address="1"  UnitSetScale="1000" UnitScale="10000" />
 	</PowerSupplierDeviceConfig>
 
 	<PowerSupplierDeviceConfig Name="Power10" IpAddress="127.0.0.1" Port="829" Type="0" SendTimeout="2000" RecvTimeout="2000">
-		<Device Name="Power10-1" Address="1" />
+		<Device Name="Power10-1" Address="1"  UnitSetScale="1000" UnitScale="10000" />
 	</PowerSupplierDeviceConfig>
 
 	<PowerSupplierDeviceConfig Name="Power11" IpAddress="127.0.0.1" Port="831" Type="0" SendTimeout="2000" RecvTimeout="2000">
-		<Device Name="Power11-1" Address="1" />
+		<Device Name="Power11-1" Address="1"  UnitSetScale="1000" UnitScale="10000" />
 	</PowerSupplierDeviceConfig>
 
 	<PowerSupplierDeviceConfig Name="Power12" IpAddress="127.0.0.1" Port="832" Type="0" SendTimeout="2000" RecvTimeout="2000">
-		<Device Name="Power12-1" Address="1" />
+		<Device Name="Power12-1" Address="1"  UnitSetScale="1000" UnitScale="10000" />
 	</PowerSupplierDeviceConfig>
 
 	<PowerSupplierDeviceConfig Name="Power13" IpAddress="127.0.0.1" Port="833" Type="0" SendTimeout="2000" RecvTimeout="2000">
-		<Device Name="Power13-1" Address="1" />
+		<Device Name="Power13-1" Address="1"  UnitSetScale="1000" UnitScale="10000" />
 	</PowerSupplierDeviceConfig>
 
 	<PowerSupplierDeviceConfig Name="Power14" IpAddress="127.0.0.1" Port="834" Type="0" SendTimeout="2000" RecvTimeout="2000">
-		<Device Name="Power14-1" Address="1" />
+		<Device Name="Power14-1" Address="1"  UnitSetScale="1000" UnitScale="10000" />
 	</PowerSupplierDeviceConfig>
   
   <PowerSupplierDeviceConfig Name="CMMPower1" IpAddress="127.0.0.1" Port="835" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="CMMPower1-1" Address="1" />
-  </PowerSupplierDeviceConfig>
+    <Device Name="CMMPower1-1" Address="1"  UnitSetScale="1000" UnitScale="10000" />
+  </PowerSupplierDeviceConfig>-->
 </PowerSupplierConfig>

+ 12 - 12
CyberX8_RT/Config/Devices/PowerSupplierCfg.xml

@@ -1,30 +1,30 @@
 <?xml version="1.0" encoding="utf-8"?>
 <PowerSupplierConfig>
-  <PowerSupplierDeviceConfig Name="Power1" IpAddress="10.0.10.101" Port="820" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power1-1" Address="1" />
+  <PowerSupplierDeviceConfig Name="Power1" IpAddress="10.0.10.101" Port="820" Type="0" SendTimeout="2000" RecvTimeout="2000" > 
+    <Device Name="Power1-1" Address="1" UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
   <PowerSupplierDeviceConfig Name="Power2" IpAddress="10.0.10.102" Port="820" Type="1" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power2-1" Address="1" />
+    <Device Name="Power2-1" Address="1" UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
   <PowerSupplierDeviceConfig Name="Power3" IpAddress="10.0.10.103" Port="820" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power3-1" Address="1" />
+    <Device Name="Power3-1" Address="1" UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
   <PowerSupplierDeviceConfig Name="Power4" IpAddress="10.0.10.104" Port="820" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power4-1" Address="1" />
+    <Device Name="Power4-1" Address="1" UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
   <PowerSupplierDeviceConfig Name="Power5" IpAddress="10.0.10.105" Port="820" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power5-1" Address="1" />
+    <Device Name="Power5-1" Address="1" UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
-  <PowerSupplierDeviceConfig Name="Power6" IpAddress="10.0.10.106" Port="820" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power6-1" Address="1" />
+  <PowerSupplierDeviceConfig Name="Power6" IpAddress="10.0.10.106" Port="820" Type="0" SendTimeout="2000" RecvTimeout="2000" > 
+    <Device Name="Power6-1" Address="1" UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
   <PowerSupplierDeviceConfig Name="Power7" IpAddress="10.0.10.107" Port="820" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power7-1" Address="1" />
+    <Device Name="Power7-1" Address="1" UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
-  <PowerSupplierDeviceConfig Name="Power8" IpAddress="10.0.10.108" Port="820" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="Power8-1" Address="1" />
+  <PowerSupplierDeviceConfig Name="Power8" IpAddress="10.0.10.108" Port="820" Type="0" SendTimeout="2000" RecvTimeout="2000" > 
+    <Device Name="Power8-1" Address="1" UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
   <PowerSupplierDeviceConfig Name="CMMPower1" IpAddress="127.0.10.1"  Port="505" Type="0" SendTimeout="2000" RecvTimeout="2000"> 
-    <Device Name="CMMPower1-1" Address="2" />
+    <Device Name="CMMPower1-1" Address="2" UnitSetScale="1000" UnitScale="10000" />
   </PowerSupplierDeviceConfig>
 </PowerSupplierConfig>

+ 5 - 4
CyberX8_RT/Config/System.sccfg

@@ -212,10 +212,11 @@
 		</configs>
 	</configs>
 	<configs name="Log" nameView="Log">
-		<config default="false" name="EnableLinmotLog" nameView="EnableLinmotLog" description="是否启用Linmot日志" max="" min="" paramter="" tag="" unit="" type="Bool" />
-		<config default="false" name="EnableResistivityLog" nameView="EnableResistivityLog" description="是否启用Resistivity日志" max="" min="" paramter="" tag="" unit="" type="Bool" />
-		<config default="false" name="EnableTemperatureLog" nameView="EnableTemperatureLog" description="是否启用Temperature日志" max="" min="" paramter="" tag="" unit="" type="Bool" />
-		<config default="false" name="EnableBarcodeReaderLog" nameView="Enalbe BarcodeReader log" description="是否启用BarcodeReader日志" max="" min="" paramter="" tag="" unit="" type="Bool" />
+		<config default="false" name="EnableLinmotLog" nameView="EnableLinmotLog" description="enable linmot log" max="" min="" paramter="" tag="" unit="" type="Bool" />
+		<config default="false" name="EnableResistivityLog" nameView="EnableResistivityLog" description="enable Resistivity log" max="" min="" paramter="" tag="" unit="" type="Bool" />
+		<config default="false" name="EnableTemperatureLog" nameView="EnableTemperatureLog" description="enable Temperature log" max="" min="" paramter="" tag="" unit="" type="Bool" />
+		<config default="false" name="EnablePowerSupplierLog" nameView="EnablePowerSupplierLog" description="enable Temperature log" max="" min="" paramter="" tag="" unit="" type="Bool" />
+		<config default="false" name="EnableBarcodeReaderLog" nameView="EnalbeBarcodeReaderlog" description="enable BarcodeReader log" max="" min="" paramter="" tag="" unit="" type="Bool" />
 	</configs>
 	<configs name="Metal" nameView="Metal">
 		<config default="10000" name="CellFlowFaultHoldOffTime" nameView="CellFlowFaultHoldOffTime" description="Cell Flow fault Hold Off time" max="50000" min="0" paramter="" tag="" unit="ms" type="Integer"></config>

+ 15 - 18
CyberX8_RT/Devices/PowerSupplier/CellPowerSupplier.cs

@@ -40,10 +40,6 @@ namespace CyberX8_RT.Devices.PowerSupplier
         private const string POWER_STATUS = "PowerStatus";
         private const string POWER_CONTROL = "PowerControl";
         private const string POWER_RUN_MODEL = "PowerRunModel";
-        private const int CURRENT_UNIT_SCALE = 10000;
-        private const int CURRENT_DEVICE_UNIT_SCALE = 1000;
-        private const int VOLTAGE_DEVICE_SCALE = 10000;
-        private const int STEP_VOLTAGE_SCALE = 1000;
         #endregion
 
         #region 内部变量
@@ -105,6 +101,14 @@ namespace CyberX8_RT.Devices.PowerSupplier
         /// 连接成功时间
         /// </summary>
         private DateTime _connectTime = DateTime.Now;
+        /// <summary>
+        /// 读取数值比例
+        /// </summary>
+        private int _unitScale = 10000;
+        /// <summary>
+        /// 设置数值比例
+        /// </summary>
+        private int _unitSetScale = 1000;
         #endregion
 
         #region 属性
@@ -167,6 +171,8 @@ namespace CyberX8_RT.Devices.PowerSupplier
                 {
                     LOG.WriteLog(eEvent.ERR_POWERSUPPLIER, Module, $"{Module} channel is invalid");
                 }
+                _unitScale = _deviceParameter.UnitScale;
+                _unitSetScale= _deviceParameter.UnitSetScale;
             }
             else
             {
@@ -211,7 +217,7 @@ namespace CyberX8_RT.Devices.PowerSupplier
                 {
                     if (double.TryParse(value.ToString(), out double doubleValue))
                     {
-                        property.SetValue(PowerSupplierData, doubleValue / CURRENT_DEVICE_UNIT_SCALE);
+                        property.SetValue(PowerSupplierData, doubleValue / _unitSetScale);
                     }
                     else
                     {
@@ -222,7 +228,7 @@ namespace CyberX8_RT.Devices.PowerSupplier
                 {
                     if (double.TryParse(value.ToString(), out double doubleValue))
                     {
-                        property.SetValue(PowerSupplierData, doubleValue / CURRENT_UNIT_SCALE);
+                        property.SetValue(PowerSupplierData, doubleValue / _unitScale);
                     }
                     else
                     {
@@ -233,7 +239,7 @@ namespace CyberX8_RT.Devices.PowerSupplier
                 {
                     if (double.TryParse(value.ToString(), out double doubleValue))
                     {
-                        property.SetValue(PowerSupplierData, doubleValue / VOLTAGE_DEVICE_SCALE);
+                        property.SetValue(PowerSupplierData, doubleValue / _unitScale);
                     }
                     else
                     {
@@ -345,15 +351,6 @@ namespace CyberX8_RT.Devices.PowerSupplier
             _sendDateTime = DateTime.Now;
             PowerSupplierDeviceConfigManager.Instance.GetChannelCurrentAndVoltage(Module, _channel);
         }
-        /// <summary>
-        /// 获取比例后的数值
-        /// </summary>
-        /// <param name="value"></param>
-        /// <returns></returns>
-        private double GetAfterScaledValue(int value)
-        {
-            return (double)value / (CURRENT_UNIT_SCALE);
-        }
 
         #region Operation
         /// <summary>
@@ -510,7 +507,7 @@ namespace CyberX8_RT.Devices.PowerSupplier
         public bool SetCurrent(double current)
         {
             PowerSupplierDeviceConfigManager.Instance.SetPowerRunmodelControl(Module, _channel, (byte)PowerRunModelEnum.Normal);
-            int setPoint = (int)Math.Round(CURRENT_DEVICE_UNIT_SCALE * current, 0);
+            int setPoint = (int)Math.Round(_unitSetScale * current, 0);
             bool result= PowerSupplierDeviceConfigManager.Instance.SetChannelCurrent(Module, _channel, setPoint);
             _sendDateTime = DateTime.Now;
             if (result)
@@ -597,7 +594,7 @@ namespace CyberX8_RT.Devices.PowerSupplier
         {
             List<PowerSupplierStepPeriodData> powerSupplierStepPeriodDatas = (List<PowerSupplierStepPeriodData>)args[1];
 
-            bool result=PowerSupplierDeviceConfigManager.Instance.SetStepPeriod(Module, _channel, powerSupplierStepPeriodDatas,STEP_VOLTAGE_SCALE,CURRENT_DEVICE_UNIT_SCALE);
+            bool result=PowerSupplierDeviceConfigManager.Instance.SetStepPeriod(Module, _channel, powerSupplierStepPeriodDatas,_unitSetScale);
             _sendDateTime = DateTime.Now;
             if (result)
             {

+ 0 - 1
Framework/Common/Common.csproj

@@ -267,7 +267,6 @@
     <Compile Include="Device\PowerSupplier\PowerSupplierFlag.cs" />
     <Compile Include="Device\PowerSupplier\PowerSupplierGoldModbusDevice.cs" />
     <Compile Include="Device\PowerSupplier\PowerSupplierSerialPortModbusDevice.cs" />
-    <Compile Include="Device\PowerSupplier\PowerSupplierTcpGoldModbusMessage.cs" />
     <Compile Include="Device\PowerSupplier\PowerSupplierTcpModbusMessage.cs" />
     <Compile Include="Device\PowerSupplier\PowerSupplierMessage.cs" />
     <Compile Include="Device\PowerSupplier\PowerSupplierModbusDevice.cs" />

+ 1 - 1
Framework/Common/Device/PowerSupplier/IPowerSupplierDevice.cs

@@ -77,7 +77,7 @@ namespace MECF.Framework.Common.Device.PowerSupplier
         /// <param name="name"></param>
         /// <param name="channel"></param>
         /// <param name="stepPeriodDatas"></param>
-        bool SetStepPeriod(byte channel, List<PowerSupplierStepPeriodData> stepPeriodDatas, int voltageScale, int currentScale);
+        bool SetStepPeriod(byte channel, List<PowerSupplierStepPeriodData> stepPeriodDatas, int scale);
         /// <summary>
         /// 启动步阶
         /// </summary>

+ 6 - 0
Framework/Common/Device/PowerSupplier/PowerSupplierDevice.cs

@@ -27,6 +27,12 @@ namespace MECF.Framework.Common.Device.PowerSupplier
 
         [XmlAttribute(AttributeName = "Address", Form = XmlSchemaForm.Unqualified, DataType = "string")]
         public string Address { get { return _address;} set { _address = value; InvokePropertyChanged(nameof(Address)); } }
+
+        [XmlAttribute(AttributeName = "UnitSetScale", Form = XmlSchemaForm.Unqualified, DataType = "int")]
+        public int UnitSetScale { get; set; }
+
+        [XmlAttribute(AttributeName = "UnitScale", Form = XmlSchemaForm.Unqualified, DataType = "int")]
+        public int UnitScale { get; set; }
         #endregion
     }
 }

+ 2 - 2
Framework/Common/Device/PowerSupplier/PowerSupplierDeviceConfigManager.cs

@@ -235,11 +235,11 @@ namespace MECF.Framework.Common.Device.PowerSupplier
         /// <param name="name"></param>
         /// <param name="channel"></param>
         /// <param name="stepPeriodDatas"></param>
-        public bool SetStepPeriod(string name,byte channel,List<PowerSupplierStepPeriodData> stepPeriodDatas,int voltageScale,int currentScale)
+        public bool SetStepPeriod(string name,byte channel,List<PowerSupplierStepPeriodData> stepPeriodDatas,int scale)
         {
             if (_nameModbusDeviceDic.ContainsKey(name))
             {
-                return _nameModbusDeviceDic[name].SetStepPeriod(channel, stepPeriodDatas,voltageScale,currentScale);
+                return _nameModbusDeviceDic[name].SetStepPeriod(channel, stepPeriodDatas,scale);
             }
             return false;
         }

+ 19 - 8
Framework/Common/Device/PowerSupplier/PowerSupplierGoldModbusDevice.cs

@@ -1,4 +1,5 @@
 using Aitex.Core.RT.Log;
+using Aitex.Core.RT.SCCore;
 using Aitex.Core.Util;
 using DocumentFormat.OpenXml.InkML;
 using MECF.Framework.Common.CommonData.PowerSupplier;
@@ -13,7 +14,7 @@ using System.Threading.Tasks;
 
 namespace MECF.Framework.Common.Device.PowerSupplier
 {
-    public class PowerSupplierGoldModbusDevice : JetMessageTcpClient<PowerSupplierTcpGoldModbusMessage, PowerSupplierCommand>,IPowerSupplierDevice
+    public class PowerSupplierGoldModbusDevice : JetMessageTcpClient<PowerSupplierTcpModbusMessage, PowerSupplierCommand>,IPowerSupplierDevice
     {
         #region 常量 
         private const short CURRENT_SETTING_ADDRESS = 0x6102;
@@ -56,6 +57,8 @@ namespace MECF.Framework.Common.Device.PowerSupplier
             ReconnectInterval = 3000;
             ConnectTimeout = 1000;
             _name = name;
+            Name = _name;
+            EventId = eEvent.INFO_POWERSUPPLIER;
         }
         /// <summary>
         /// 连接
@@ -120,7 +123,7 @@ namespace MECF.Framework.Common.Device.PowerSupplier
         /// </summary>
         /// <param name="channel"></param>
         /// <param name="stepDatas"></param>
-        public bool SetStepPeriod(byte channel, List<PowerSupplierStepPeriodData> stepDatas, int voltageScale,int currentScale)
+        public bool SetStepPeriod(byte channel, List<PowerSupplierStepPeriodData> stepDatas, int scale)
         {
             PowerSupplierCommand command = new PowerSupplierCommand();
             command.Channel = channel;
@@ -131,10 +134,10 @@ namespace MECF.Framework.Common.Device.PowerSupplier
             for (int i = 0; i < stepDatas.Count; i++)
             {
                 PowerSupplierStepPeriodData data = stepDatas[i];
-                command.Datas[0 + STEP_PERIOD_LENGTH * i] = (ushort)(data.Voltage * voltageScale/0xffff);
-                command.Datas[1 + STEP_PERIOD_LENGTH * i] = (ushort)(data.Voltage * voltageScale %0xffff);
-                command.Datas[2 + STEP_PERIOD_LENGTH * i] = (ushort)(Math.Round(stepDatas[i].Current * currentScale, 0)/0xffff);
-                command.Datas[3 + STEP_PERIOD_LENGTH * i] = (ushort)(Math.Round(stepDatas[i].Current * currentScale, 0) % 0xffff);
+                command.Datas[0 + STEP_PERIOD_LENGTH * i] = (ushort)(Math.Round(data.Voltage * scale,0)/0x10000);
+                command.Datas[1 + STEP_PERIOD_LENGTH * i] = (ushort)(Math.Round(data.Voltage * scale,0) %0x10000);
+                command.Datas[2 + STEP_PERIOD_LENGTH * i] = (ushort)(Math.Round(data.Current * scale, 0)/0x10000);
+                command.Datas[3 + STEP_PERIOD_LENGTH * i] = (ushort)(Math.Round(data.Current * scale, 0) % 0x10000);
                 command.Datas[4 + STEP_PERIOD_LENGTH * i] = 0;
                 command.Datas[5 + STEP_PERIOD_LENGTH * i] = stepDatas[i].Hour;
                 command.Datas[6 + STEP_PERIOD_LENGTH * i] = 0;
@@ -180,8 +183,8 @@ namespace MECF.Framework.Common.Device.PowerSupplier
             command.Address = (ushort)(CURRENT_SETTING_ADDRESS);
             command.RegisterCount = 4;//2N N-寄存器地址数据
             ushort[] ushorts = new ushort[2];
-            ushorts[0] = (ushort)(currentValue / 0xFFFF);//高位
-            ushorts[1] = (ushort)(currentValue % 0xFFFF);//低位
+            ushorts[0] = (ushort)(currentValue / 0x10000);//高位
+            ushorts[1] = (ushort)(currentValue % 0x10000);//低位
             command.Datas = ushorts;
             return SetOperation(command);
         }
@@ -301,6 +304,10 @@ namespace MECF.Framework.Common.Device.PowerSupplier
         /// <returns></returns>
         private bool SetOperation(PowerSupplierCommand command)
         {
+            if (SC.ContainsItem("Log.EnablePowerSupplierLog"))
+            {
+                LogEnabled = SC.GetValue<bool>("Log.EnablePowerSupplierLog");
+            }
             if (Connected)
             {
                 NetResult netResult = SetData(command);
@@ -337,6 +344,10 @@ namespace MECF.Framework.Common.Device.PowerSupplier
         /// <param name="command"></param>
         private void ApplyDataOperation(PowerSupplierCommand command)
         {
+            if (SC.ContainsItem("Log.EnablePowerSupplierLog"))
+            {
+                LogEnabled = SC.GetValue<bool>("Log.EnablePowerSupplierLog");
+            }
             if (!Connected)
             {
                 NetResult connectResult = Connect();

+ 14 - 3
Framework/Common/Device/PowerSupplier/PowerSupplierModbusDevice.cs

@@ -1,4 +1,5 @@
 using Aitex.Core.RT.Log;
+using Aitex.Core.RT.SCCore;
 using Aitex.Core.Util;
 using DocumentFormat.OpenXml.InkML;
 using MECF.Framework.Common.CommonData.PowerSupplier;
@@ -56,6 +57,8 @@ namespace MECF.Framework.Common.Device.PowerSupplier
             ReconnectInterval = 3000;
             ConnectTimeout = 1000;
             _name = name;
+            Name = _name;
+            EventId = eEvent.INFO_POWERSUPPLIER;
         }
         /// <summary>
         /// 连接
@@ -120,7 +123,7 @@ namespace MECF.Framework.Common.Device.PowerSupplier
         /// </summary>
         /// <param name="channel"></param>
         /// <param name="stepDatas"></param>
-        public bool SetStepPeriod(byte channel, List<PowerSupplierStepPeriodData> stepDatas, int voltageScale, int currentScale)
+        public bool SetStepPeriod(byte channel, List<PowerSupplierStepPeriodData> stepDatas, int scale)
         {
             PowerSupplierCommand command = new PowerSupplierCommand();
             command.Channel = channel;
@@ -131,8 +134,8 @@ namespace MECF.Framework.Common.Device.PowerSupplier
             for (int i = 0; i < stepDatas.Count; i++)
             {
                 PowerSupplierStepPeriodData data = stepDatas[i];
-                command.Datas[0 + STEP_PERIOD_LENGTH * i] = (ushort)(data.Voltage * voltageScale);
-                command.Datas[1 + STEP_PERIOD_LENGTH * i] = (ushort)Math.Round(stepDatas[i].Current * currentScale, 0);
+                command.Datas[0 + STEP_PERIOD_LENGTH * i] = (ushort)Math.Round(data.Voltage * scale,0);
+                command.Datas[1 + STEP_PERIOD_LENGTH * i] = (ushort)Math.Round(stepDatas[i].Current * scale, 0);
                 command.Datas[2 + STEP_PERIOD_LENGTH * i] = stepDatas[i].Hour;
                 command.Datas[3 + STEP_PERIOD_LENGTH * i] = stepDatas[i].Minute;
                 command.Datas[4 + STEP_PERIOD_LENGTH * i] = stepDatas[i].Second;
@@ -289,6 +292,10 @@ namespace MECF.Framework.Common.Device.PowerSupplier
         /// <returns></returns>
         private bool SetOperation(PowerSupplierCommand command)
         {
+            if (SC.ContainsItem("Log.EnablePowerSupplierLog"))
+            {
+                LogEnabled = SC.GetValue<bool>("Log.EnablePowerSupplierLog");
+            }
             if (Connected)
             {
                 NetResult netResult = SetData(command);
@@ -325,6 +332,10 @@ namespace MECF.Framework.Common.Device.PowerSupplier
         /// <param name="command"></param>
         private void ApplyDataOperation(PowerSupplierCommand command)
         {
+            if (SC.ContainsItem("Log.EnablePowerSupplierLog"))
+            {
+                LogEnabled = SC.GetValue<bool>("Log.EnablePowerSupplierLog");
+            }
             if (!Connected)
             {
                 NetResult connectResult = Connect();

+ 0 - 189
Framework/Common/Device/PowerSupplier/PowerSupplierTcpGoldModbusMessage.cs

@@ -1,189 +0,0 @@
-using Aitex.Core.Utilities;
-using log4net.Core;
-using MECF.Framework.Common.Net;
-using MECF.Framework.Common.Utilities;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.Remoting.Messaging;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace MECF.Framework.Common.Device.PowerSupplier
-{
-    public class PowerSupplierTcpGoldModbusMessage : INetMessage<PowerSupplierCommand>
-    {
-        #region 属性
-        public int ProtocolHeadBytesLength { get; set; } = 6;
-
-        public int ErrorCode { get; set; }
-
-        public string ErrorMsg { get; set; }
-
-        public byte[] HeadBytes { get; set; }
-        public byte[] ContentBytes { get; set; }
-        public byte[] SendBytes { get; set; }
-        #endregion
-
-        #region 内部变量
-        IByteTransform byteTransform=new BigEndianByteTransformBase();
-        #endregion
-
-        public bool CheckDataLegal()
-        {
-            //第二个字节高位为0x80,设备报错
-            if((ContentBytes[1]&0x80)==0x80)
-            {
-                ErrorCode = (int)NetErrorCode.DeviceError;
-                ErrorMsg = GetDeviceMessage(ContentBytes[2]);
-                return false;
-            }
-            //数据长度不一致
-            if (ContentBytes[1] == 0x03)
-            {
-                byte contentLength = ContentBytes[2];
-                if (ContentBytes.Length - 3 != contentLength)
-                {
-                    ErrorCode = (int)NetErrorCode.InvalidData;
-                    ErrorMsg = EnumUtil.GetEnumDescription(NetErrorCode.InvalidData);
-                    return false;
-                }
-            }
-            return true;
-        }
-        /// <summary>
-        /// 设备错误信息
-        /// </summary>
-        /// <returns></returns>
-        private string GetDeviceMessage(byte deviceErrorCode)
-        {
-            switch(deviceErrorCode)
-            {
-                case 0x01:
-                    return "Invalid Function";
-                case 0x02:
-                    return "Invalid Address";
-                case 0x03:
-                    return "Invalid Data";
-                case 0x04:
-                    return "Slave Device Error";
-                case 0x05:
-                    return "Error Confirm";
-                case 0x06:
-                    return "Slave Device Busy";
-                default:
-                    return "Unkown Error Code";
-            }
-        }
-
-        public bool CheckHeadBytesLegal()
-        {
-            //地址与指令同时一致
-            return SendBytes[0] == HeadBytes[0] && SendBytes[1] == HeadBytes[1] && HeadBytes[2] == 0x00 && HeadBytes[3]==0x00;
-        }
-
-
-        public bool ConfirmResponseResult()
-        {
-            //指令码与发送指令码一致
-            if (HeadBytes[1] == SendBytes[1])
-            {
-                return true;
-            }
-            return false;
-        }
-
-        public PowerSupplierCommand Decode() 
-        {
-            PowerSupplierCommand command = new PowerSupplierCommand();
-            if (ContentBytes[1] == 0x03)
-            {
-                int registerCount = ContentBytes[2] / 2;
-                command.Datas = byteTransform.TransUInt16(ContentBytes, 3, registerCount);
-            }
-            return command;
-        }
-
-        public int GetContentLengthByHeadBytes()
-        {
-            return byteTransform.TransInt16(HeadBytes, 4);
-        }
-
-        public int GetHeadBytesIdentity()
-        {
-            return byteTransform.TransInt16(HeadBytes, 0);
-        }
-
-        public byte[] Code(PowerSupplierCommand data) 
-        {
-            byte[] byt = null; 
-            //读取指令
-            if(data.CommandCode==0x03)
-            {
-                byt= new byte[12];
-                //事务处理标识
-                Array.Copy(PowerSupplierFlag.Instance.GenerateDataFlagBuffer(byteTransform),0, byt, 0, 2);
-                //固定码0x0000
-                byt[2] = 0x00;
-                byt[3] = 0x00;
-                //数据长度
-                byt[4] = 0x00;
-                byt[5] = 0x06;
-                //通道
-                byt[6] = data.Channel;
-                //指令
-                byt[7] = data.CommandCode;
-                Array.Copy(byteTransform.GetBytes(data.Address), 0, byt, 8, 2);
-                Array.Copy(byteTransform.GetBytes(data.RegisterCount), 0, byt, 10, 2);
-            }
-            //写单个寄存器地址
-            else if(data.CommandCode==0x06)
-            {
-                byt = new byte[12];
-                //事务处理标识
-                Array.Copy(PowerSupplierFlag.Instance.GenerateDataFlagBuffer(byteTransform), 0, byt, 0, 2);
-                //固定码0x0000
-                byt[2] = 0x00;
-                byt[3] = 0x00;
-                //数据长度
-                byt[4] = 0x00;
-                byt[5] = 0x06;
-                //通道
-                byt[6] = data.Channel;
-                //指令
-                byt[7] = data.CommandCode;
-                Array.Copy(byteTransform.GetBytes(data.Address), 0, byt, 8, 2);
-                Array.Copy(byteTransform.GetBytes(data.Datas[0]), 0, byt, 10, 2);
-            }
-            else if(data.CommandCode==0x10)
-            {
-                byt = new byte[6+7+2*data.Datas.Length];
-                //事务处理标识
-                Array.Copy(PowerSupplierFlag.Instance.GenerateDataFlagBuffer(byteTransform), 0, byt, 0, 2);
-                //固定码0x0000
-                byt[2] = 0x00;
-                byt[3] = 0x00;
-                //数据长度
-                byt[4] = 0x00;
-                byt[5] = 0x06;
-                //通道
-                byt[6] = data.Channel;
-                //指令
-                byt[7] = data.CommandCode;
-                Array.Copy(byteTransform.GetBytes(data.Address), 0, byt, 8, 2);
-                Array.Copy(byteTransform.GetBytes(data.RegisterCount), 0, byt, 10, 2);
-                byt[12] = (byte)(2 * data.Datas.Length);
-                for (int i = 0; i < data.Datas.Length; i++)
-                {
-                    Array.Copy(byteTransform.GetBytes(data.Datas[i]), 0, byt, 13+i*2, 2);
-                }
-            }
-            return byt;
-        }
-
-        public void SetProtocolHeadBytesLength()
-        {            
-        }
-    }
-}

+ 1 - 1
Framework/Common/Device/PowerSupplier/PowerSupplierTcpModbusMessage.cs

@@ -166,7 +166,7 @@ namespace MECF.Framework.Common.Device.PowerSupplier
                 byt[3] = 0x00;
                 //数据长度
                 byt[4] = 0x00;
-                byt[5] = 0x06;
+                byt[5] = (byte)(7+2*data.Datas.Length);
                 //通道
                 byt[6] = data.Channel;
                 //指令

+ 32 - 1
Framework/Common/Net/JetTcpClient.cs

@@ -1,5 +1,6 @@
 using Aitex.Core.RT.Log;
 using Aitex.Core.Utilities;
+using DocumentFormat.OpenXml.ExtendedProperties;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -29,6 +30,9 @@ namespace MECF.Framework.Common.Net
         private object _closeLocker = new object();
         private AutoResetEvent _connectAutoResetEvent=new AutoResetEvent(false);
         private Socket _socket = null;
+        private bool _logEnabled;
+        private string _name;
+        private eEvent _eventId;
         #endregion
 
         #region 属性
@@ -52,6 +56,18 @@ namespace MECF.Framework.Common.Net
         /// 连接状态
         /// </summary>
         public bool Connected { get { return _connected; } }
+        /// <summary>
+        /// 是否启用LOG
+        /// </summary>
+        public bool LogEnabled { set { _logEnabled=value; }}
+        /// <summary>
+        /// 名称
+        /// </summary>
+        public string Name { set { _name=value; } }
+        /// <summary>
+        /// 事件Id
+        /// </summary>
+        public eEvent EventId { set { _eventId = value; } }
         #endregion
         /// <summary>
         /// 构造函数
@@ -193,7 +209,20 @@ namespace MECF.Framework.Common.Net
                 }
             }
         }
-
+        /// <summary>
+        /// 写日志
+        /// </summary>
+        /// <param name="bytes"></param>
+        /// <param name="logType"></param>
+        private void WriteInfoLog(byte[] bytes,int logType)
+        {
+            if (_logEnabled)
+            {
+                string str = string.Join(" ", Array.ConvertAll(bytes, x => x.ToString("X2")));
+                string type = logType == 0 ? "receive" : "send";
+                LOG.WriteBackgroundLog(_eventId, _name, $"{type} {str}");
+            }
+        }
         /// <summary>
         /// 发送数据
         /// </summary>
@@ -217,6 +246,7 @@ namespace MECF.Framework.Common.Net
                 try
                 {
                     _socket.Send(data);
+                    WriteInfoLog(data, 1);
                     Monitor.Exit(_sendLocker);
                     return NetResult.CreateSuccessResult();
                 }
@@ -262,6 +292,7 @@ namespace MECF.Framework.Common.Net
                         buffer = new byte[length];
                     }
                     _socket.Receive(buffer, length, SocketFlags.None);
+                    WriteInfoLog(buffer, 0);
                     Monitor.Exit(_receiveLocker);
                     return NetResult.CreateSuccessResult<byte[]>(buffer);
                 }