diff --git a/AutoWeightServer/App.config b/AutoWeightServer/App.config
index fc9af38..e0b37ec 100644
--- a/AutoWeightServer/App.config
+++ b/AutoWeightServer/App.config
@@ -40,6 +40,7 @@
+
diff --git a/AutoWeightServer/AutoWeightServer.csproj b/AutoWeightServer/AutoWeightServer.csproj
index 6ee2ad8..143a2f4 100644
--- a/AutoWeightServer/AutoWeightServer.csproj
+++ b/AutoWeightServer/AutoWeightServer.csproj
@@ -10,6 +10,7 @@
EC.AutoWeightServer
AutoWeightServer
v4.5.2
+ zh-Hans
512
true
@@ -192,7 +193,6 @@
-
@@ -328,6 +328,18 @@
Designer
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
diff --git a/AutoWeightServer/Center/DeviceCenter.cs b/AutoWeightServer/Center/DeviceCenter.cs
index 34fc2d5..83276cd 100644
--- a/AutoWeightServer/Center/DeviceCenter.cs
+++ b/AutoWeightServer/Center/DeviceCenter.cs
@@ -218,7 +218,8 @@ namespace EC.AutoWeightServer.Center
{
var com = ServerConfig.LightRelayCom;
var rate = ServerConfig.LightRelayBaudRate;
- LightManager = new Light2Manager(com, rate);
+ var name = ServerConfig.LightCodeName;
+ LightManager = new LightManager(com, rate, name);
LightManager.StartServer();
}
diff --git a/AutoWeightServer/IfManager/Light/Light2Manager.cs b/AutoWeightServer/IfManager/Light/Light2Manager.cs
deleted file mode 100644
index 3bab7ba..0000000
--- a/AutoWeightServer/IfManager/Light/Light2Manager.cs
+++ /dev/null
@@ -1,178 +0,0 @@
-using System.Collections.Generic;
-
-namespace EC.AutoWeightServer.IfManager.Light
-{
- public class Light2Manager : ILightManager
- {
- private LightRelay _lightRelay;
- private string _comName;
- private int _baudRate;
-
- public Light2Manager()
- {
- }
-
- public Light2Manager(string comName, int baudRate)
- {
- _comName = comName;
- _baudRate = baudRate;
- }
-
- #region Start & Stop Server
-
- ///
- /// 开启连接
- ///
- ///
- public bool StartServer()
- {
- _lightRelay = new LightRelay(_comName, _baudRate);
- var ret = _lightRelay.StartServer();
- return ret;
- }
-
- ///
- /// 关闭连接
- ///
- ///
- public bool StopServer()
- {
- _lightRelay?.StopServer();
- _lightRelay = null;
- return true;
- }
-
- public bool IsOpen()
- {
- return _lightRelay?.IsOpen() ?? false;
- }
-
- #endregion Start & Stop Server
-
- #region Control Lights Code
-
- //private int num = 0xFF;
-
- ///
- /// 控制所有灯编码,1 为开启所有灯,2 为关闭所有灯
- ///
- private readonly List _ctrlAllLightCodeList = new List() { "", "01108050000204020F0804A0ED", "011080500002040200080490EE" };
-
- ///
- /// 开启某一路灯编码,不互斥,index 互相对应
- ///
- private readonly List _openLightCodeList = new List() { "", "01050000FF008C3A", "01050001FF00DDFA", "01050002FF002DFA", "01050003FF007C3A" };
-
- ///
- /// 关闭某一路灯编码,不互斥,index 互相对应
- ///
- private readonly List _closeLightCodeList = new List() { "", "010500000000CDCA", "0105000100009C0A", "0105000200006C0A", "0105000300003DCA" };
-
- ///
- /// 互锁编码,控制只有一路灯亮,index 互相对应
- ///
- private readonly List _lockLightOnCodeList = new List() { "", "0110805000020402010804C12E", "0110805000020402020804312E", "0110805000020402040804D12F", "0110805000020402080804112C" };
-
- ///
- /// 互锁编码,控制只有一路灯灭,index 互相对应
- ///
- private readonly List _lockLightOffCodeList = new List() { "", "01108050000204020E0804F12D", "01108050000204020D0804012D", "01108050000204020B0804E12C", "0110805000020402070804212F" };
-
- #endregion Control Lights Code
-
- #region Control Lights
-
- ///
- /// 开启所有灯
- ///
- ///
- public bool OpenAllLight()
- {
- var code = _ctrlAllLightCodeList[1];
- return _lightRelay.SendHex(code);
- }
-
- ///
- /// 关闭所有灯
- ///
- ///
- public bool CloseAllLight()
- {
- var code = _ctrlAllLightCodeList[2];
- return _lightRelay.SendHex(code);
- }
-
- ///
- /// 开启某一路灯
- ///
- ///
- ///
- public bool OpenLight(int index)
- {
- var codeList = _openLightCodeList;
- if (!IsIndexValid(codeList, index))
- return false;
- var code = codeList[index];
- return _lightRelay.SendHex(code);
- }
-
- ///
- /// 关闭某一路灯
- ///
- ///
- ///
- public bool CloseLight(int index)
- {
- var codeList = _closeLightCodeList;
- if (!IsIndexValid(codeList, index))
- return false;
- var code = codeList[index];
- return _lightRelay.SendHex(code);
- }
-
- ///
- /// 互斥开某一路灯
- ///
- ///
- ///
- public bool LockLightOn(int index)
- {
- var codeList = _lockLightOnCodeList;
- if (!IsIndexValid(codeList, index))
- return false;
- var code = codeList[index];
- return _lightRelay.SendHex(code);
- }
-
- ///
- /// 互斥关某一路灯
- ///
- ///
- ///
- public bool LockLightOff(int index)
- {
- var codeList = _lockLightOffCodeList;
- if (!IsIndexValid(codeList, index))
- return false;
- var code = codeList[index];
- return _lightRelay.SendHex(code);
- }
-
- ///
- /// 判断功能码是否可以使用
- ///
- ///
- ///
- ///
- private bool IsIndexValid(List codeList, int index)
- {
- if (codeList == null)
- return false;
- if (index < 1 || index > codeList.Count - 1)
- return false;
- return true;
- }
-
- #endregion Control Lights
- }
-}
\ No newline at end of file
diff --git a/AutoWeightServer/IfManager/Light/LightManager.cs b/AutoWeightServer/IfManager/Light/LightManager.cs
index f025c1c..87b244d 100644
--- a/AutoWeightServer/IfManager/Light/LightManager.cs
+++ b/AutoWeightServer/IfManager/Light/LightManager.cs
@@ -1,4 +1,7 @@
-using System.Collections.Generic;
+using EC.Utils;
+using Newtonsoft.Json.Linq;
+using System.Collections.Generic;
+using System.IO;
namespace EC.AutoWeightServer.IfManager.Light
{
@@ -7,15 +10,19 @@ namespace EC.AutoWeightServer.IfManager.Light
private LightRelay _lightRelay;
private string _comName;
private int _baudRate;
+ private string _fileName;
public LightManager()
{
}
- public LightManager(string comName, int baudRate)
+ public LightManager(string comName, int baudRate, string fileName)
{
_comName = comName;
_baudRate = baudRate;
+ _fileName = fileName;
+
+ ReadLightCodeJson();
}
#region Start & Stop Server
@@ -54,27 +61,39 @@ namespace EC.AutoWeightServer.IfManager.Light
///
/// 控制所有灯编码,1 为开启所有灯,2 为关闭所有灯
///
- private readonly List _ctrlAllLightCodeList = new List() { "", "3301140000000048", "3301130000000047" };
+ private List _ctrlAllLightCodeList;
///
/// 开启某一路灯编码,不互斥,index 互相对应
///
- private readonly List _openLightCodeList = new List() { "", "3301120000000147", "3301120000000248", "3301120000000349", "330112000000044A" };
+ private List _openLightCodeList;
///
/// 关闭某一路灯编码,不互斥,index 互相对应
///
- private readonly List _closeLightCodeList = new List() { "", "3301110000000146", "3301110000000247", "3301110000000348", "3301110000000449" };
+ private List _closeLightCodeList;
///
/// 互锁编码,控制只有一路灯亮,index 互相对应
///
- private readonly List _lockLightOnCodeList = new List() { "", "33011500000E045B", "33011500000D045A", "33011500000B0458", "3301150000070454" };
+ private List _lockLightOnCodeList;
///
/// 互锁编码,控制只有一路灯灭,index 互相对应
///
- private readonly List _lockLightOffCodeList = new List() { "", "330115000001044E", "330115000002044F", "3301150000040451", "3301150000080455" };
+ private List _lockLightOffCodeList;
+
+ private bool ReadLightCodeJson()
+ {
+ if (!File.Exists(_fileName)) return false;
+ JObject obj = CommonUtil.ReadFileJson(_fileName);
+ _ctrlAllLightCodeList = obj["CtrlAllLightCodeList"].ToObject>();
+ _openLightCodeList = obj["OpenLightCodeList"].ToObject>();
+ _closeLightCodeList = obj["CloseLightCodeList"].ToObject>();
+ _lockLightOnCodeList = obj["LockLightOnCodeList"].ToObject>();
+ _lockLightOffCodeList = obj["LockLightOffCodeList"].ToObject>();
+ return true;
+ }
#endregion Control Lights Code
@@ -86,7 +105,11 @@ namespace EC.AutoWeightServer.IfManager.Light
///
public bool OpenAllLight()
{
- var code = _ctrlAllLightCodeList[1];
+ var codeList = _ctrlAllLightCodeList;
+ var index = 1;
+ if (!IsIndexValid(codeList, index))
+ return false;
+ var code = codeList[index];
return _lightRelay.SendHex(code);
}
@@ -96,7 +119,11 @@ namespace EC.AutoWeightServer.IfManager.Light
///
public bool CloseAllLight()
{
- var code = _ctrlAllLightCodeList[2];
+ var codeList = _ctrlAllLightCodeList;
+ var index = 2;
+ if (!IsIndexValid(codeList, index))
+ return false;
+ var code = codeList[index];
return _lightRelay.SendHex(code);
}
@@ -156,15 +183,6 @@ namespace EC.AutoWeightServer.IfManager.Light
return _lightRelay.SendHex(code);
}
- ///
- ///
- ///
- ///
- public bool CombineLight()
- {
- return true;
- }
-
///
/// 判断功能码是否可以使用
///
diff --git a/AutoWeightServer/Model/Config/ServerConfig.cs b/AutoWeightServer/Model/Config/ServerConfig.cs
index 67a0c8d..c1501b1 100644
--- a/AutoWeightServer/Model/Config/ServerConfig.cs
+++ b/AutoWeightServer/Model/Config/ServerConfig.cs
@@ -1,4 +1,5 @@
using System;
+using System.IO;
namespace EC.AutoWeightServer.Model.Config
{
@@ -13,6 +14,7 @@ namespace EC.AutoWeightServer.Model.Config
/// 相机
///
public static string CameraAddress1 { get; } = GetAppConfig("CAMERA_ADDRESS1");
+
public static string CameraAddress2 { get; } = GetAppConfig("CAMERA_ADDRESS2");
public static string CameraAddress3 { get; } = GetAppConfig("CAMERA_ADDRESS3");
public static string CameraAddress4 { get; } = GetAppConfig("CAMERA_ADDRESS4");
@@ -25,6 +27,7 @@ namespace EC.AutoWeightServer.Model.Config
/// 称重串口
///
public static string WtCom { get; } = GetAppConfig("WT_COM");
+
public static int WtBaudRate { get; } = FormatCom.ToInt(GetAppConfig("WT_BaudRate"));
public static int WtDiff { get; } = FormatCom.ToInt(GetAppConfig("WT_Diff"));
public static int WtInterval { get; } = FormatCom.ToInt(GetAppConfig("WT_Interval"));
@@ -35,13 +38,13 @@ namespace EC.AutoWeightServer.Model.Config
public static int WtTransmitFlag { get; } = FormatCom.ToInt(GetAppConfig("WT_Transmit_Flag"));
public static string WtTransmitCom { get; } = GetAppConfig("WT_Transmit_Com");
-
///
/// 指示灯继电器串口
///
public static string LightRelayCom { get; } = GetAppConfig("Light_Relay_COM");
public static int LightRelayBaudRate { get; } = FormatCom.ToInt(GetAppConfig("Light_Relay_BaudRate"));
+ public static string LightCodeName { get; } = Path.Combine(Environment.CurrentDirectory, "conf", GetAppConfig("Light_Code_Name"));
public static int LightInterval { get; } = FormatCom.ToInt(GetAppConfig("Light_Interval"));
public static int LightBlink { get; } = FormatCom.ToInt(GetAppConfig("Light_Blink"));
diff --git a/AutoWeightServer/conf/lightCode.json b/AutoWeightServer/conf/lightCode.json
new file mode 100644
index 0000000..b4da165
--- /dev/null
+++ b/AutoWeightServer/conf/lightCode.json
@@ -0,0 +1,7 @@
+{
+ "CtrlAllLightCodeList": [ "", "3301140000000048", "3301130000000047" ],
+ "OpenLightCodeList": [ "", "3301120000000147", "3301120000000248", "3301120000000349", "330112000000044A" ],
+ "CloseLightCodeList": [ "", "3301110000000146", "3301110000000247", "3301110000000348", "3301110000000449" ],
+ "LockLightOnCodeList": [ "", "33011500000E045B", "33011500000D045A", "33011500000B0458", "3301150000070454" ],
+ "LockLightOffCodeList": [ "", "330115000001044E", "330115000002044F", "3301150000040451", "3301150000080455" ]
+}
\ No newline at end of file
diff --git a/AutoWeightServer/conf/lightCode2.json b/AutoWeightServer/conf/lightCode2.json
new file mode 100644
index 0000000..b39b98b
--- /dev/null
+++ b/AutoWeightServer/conf/lightCode2.json
@@ -0,0 +1,7 @@
+{
+ "CtrlAllLightCodeList": [ "", "01108050000204020F0804A0ED", "011080500002040200080490EE" ],
+ "OpenLightCodeList": [ "", "01050000FF008C3A", "01050001FF00DDFA", "01050002FF002DFA", "01050003FF007C3A" ],
+ "CloseLightCodeList": [ "", "010500000000CDCA", "0105000100009C0A", "0105000200006C0A", "0105000300003DCA" ],
+ "LockLightOnCodeList": [ "", "0110805000020402010804C12E", "0110805000020402020804312E", "0110805000020402040804D12F", "0110805000020402080804112C" ],
+ "LockLightOffCodeList": [ "", "01108050000204020E0804F12D", "01108050000204020D0804012D", "01108050000204020B0804E12C", "0110805000020402070804212F" ]
+}
\ No newline at end of file
diff --git a/AutoWeightServer/conf/lightCode3.json b/AutoWeightServer/conf/lightCode3.json
new file mode 100644
index 0000000..5e39467
--- /dev/null
+++ b/AutoWeightServer/conf/lightCode3.json
@@ -0,0 +1,7 @@
+{
+ "CtrlAllLightCodeList": [ "", "010F0500000401003EC3", "010F05000004010F7EC7" ],
+ "OpenLightCodeList": [ "" ],
+ "CloseLightCodeList": [ "" ],
+ "LockLightOnCodeList": [ "", "010F050000040101FF03", "010F050000040102BF02", "010F0500000401043F00", "010F0500000401083F05" ],
+ "LockLightOffCodeList": [ "", "010F05000004010EBF07", "010F05000004010DFF06", "010F05000004010B7F04", "010F0500000401077F01" ]
+}
\ No newline at end of file
diff --git a/AutoWeightServer/conf/lightCodeTemplate.json b/AutoWeightServer/conf/lightCodeTemplate.json
new file mode 100644
index 0000000..ef1f2aa
--- /dev/null
+++ b/AutoWeightServer/conf/lightCodeTemplate.json
@@ -0,0 +1,12 @@
+{
+ // еƱ룬1 Ϊеƣ2 Ϊرе
+ "CtrlAllLightCodeList": [ "" ],
+ // ijһ·Ʊ룬⣬index Ӧ
+ "OpenLightCodeList": [ "" ],
+ // رijһ·Ʊ룬,index Ӧ
+ "CloseLightCodeList": [ "" ],
+ // 룬ֻһ·index Ӧ
+ "LockLightOnCodeList": [ "" ],
+ // 룬ֻһ·index Ӧ
+ "LockLightOffCodeList": [ "" ]
+}
\ No newline at end of file
diff --git a/EC.Utils/CommonUtil.cs b/EC.Utils/CommonUtil.cs
index 2e4ab40..6fb16c4 100644
--- a/EC.Utils/CommonUtil.cs
+++ b/EC.Utils/CommonUtil.cs
@@ -1,4 +1,7 @@
-using System;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
+using System.IO;
using System.Text.RegularExpressions;
namespace EC.Utils
@@ -190,5 +193,28 @@ namespace EC.Utils
}
return s;
}
+
+ ///
+ /// 读取JSON文件
+ ///
+ public static JObject ReadFileJson(string jsonFile)
+ {
+ try
+ {
+ using (StreamReader file = File.OpenText(jsonFile))
+ {
+ using (JsonTextReader reader = new JsonTextReader(file))
+ {
+ JObject jObject = (JObject)JToken.ReadFrom(reader);
+ return jObject;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.ToString());
+ return null;
+ }
+ }
}
}
\ No newline at end of file