fajiao
3 years ago
11 changed files with 116 additions and 200 deletions
@ -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
|
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 开启连接
|
|
||||
/// </summary>
|
|
||||
/// <returns></returns>
|
|
||||
public bool StartServer() |
|
||||
{ |
|
||||
_lightRelay = new LightRelay(_comName, _baudRate); |
|
||||
var ret = _lightRelay.StartServer(); |
|
||||
return ret; |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 关闭连接
|
|
||||
/// </summary>
|
|
||||
/// <returns></returns>
|
|
||||
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;
|
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 控制所有灯编码,1 为开启所有灯,2 为关闭所有灯
|
|
||||
/// </summary>
|
|
||||
private readonly List<string> _ctrlAllLightCodeList = new List<string>() { "", "01108050000204020F0804A0ED", "011080500002040200080490EE" }; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 开启某一路灯编码,不互斥,index 互相对应
|
|
||||
/// </summary>
|
|
||||
private readonly List<string> _openLightCodeList = new List<string>() { "", "01050000FF008C3A", "01050001FF00DDFA", "01050002FF002DFA", "01050003FF007C3A" }; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 关闭某一路灯编码,不互斥,index 互相对应
|
|
||||
/// </summary>
|
|
||||
private readonly List<string> _closeLightCodeList = new List<string>() { "", "010500000000CDCA", "0105000100009C0A", "0105000200006C0A", "0105000300003DCA" }; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 互锁编码,控制只有一路灯亮,index 互相对应
|
|
||||
/// </summary>
|
|
||||
private readonly List<string> _lockLightOnCodeList = new List<string>() { "", "0110805000020402010804C12E", "0110805000020402020804312E", "0110805000020402040804D12F", "0110805000020402080804112C" }; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 互锁编码,控制只有一路灯灭,index 互相对应
|
|
||||
/// </summary>
|
|
||||
private readonly List<string> _lockLightOffCodeList = new List<string>() { "", "01108050000204020E0804F12D", "01108050000204020D0804012D", "01108050000204020B0804E12C", "0110805000020402070804212F" }; |
|
||||
|
|
||||
#endregion Control Lights Code
|
|
||||
|
|
||||
#region Control Lights
|
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 开启所有灯
|
|
||||
/// </summary>
|
|
||||
/// <returns></returns>
|
|
||||
public bool OpenAllLight() |
|
||||
{ |
|
||||
var code = _ctrlAllLightCodeList[1]; |
|
||||
return _lightRelay.SendHex(code); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 关闭所有灯
|
|
||||
/// </summary>
|
|
||||
/// <returns></returns>
|
|
||||
public bool CloseAllLight() |
|
||||
{ |
|
||||
var code = _ctrlAllLightCodeList[2]; |
|
||||
return _lightRelay.SendHex(code); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 开启某一路灯
|
|
||||
/// </summary>
|
|
||||
/// <param name="index"></param>
|
|
||||
/// <returns></returns>
|
|
||||
public bool OpenLight(int index) |
|
||||
{ |
|
||||
var codeList = _openLightCodeList; |
|
||||
if (!IsIndexValid(codeList, index)) |
|
||||
return false; |
|
||||
var code = codeList[index]; |
|
||||
return _lightRelay.SendHex(code); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 关闭某一路灯
|
|
||||
/// </summary>
|
|
||||
/// <param name="index"></param>
|
|
||||
/// <returns></returns>
|
|
||||
public bool CloseLight(int index) |
|
||||
{ |
|
||||
var codeList = _closeLightCodeList; |
|
||||
if (!IsIndexValid(codeList, index)) |
|
||||
return false; |
|
||||
var code = codeList[index]; |
|
||||
return _lightRelay.SendHex(code); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 互斥开某一路灯
|
|
||||
/// </summary>
|
|
||||
/// <param name="index"></param>
|
|
||||
/// <returns></returns>
|
|
||||
public bool LockLightOn(int index) |
|
||||
{ |
|
||||
var codeList = _lockLightOnCodeList; |
|
||||
if (!IsIndexValid(codeList, index)) |
|
||||
return false; |
|
||||
var code = codeList[index]; |
|
||||
return _lightRelay.SendHex(code); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 互斥关某一路灯
|
|
||||
/// </summary>
|
|
||||
/// <param name="index"></param>
|
|
||||
/// <returns></returns>
|
|
||||
public bool LockLightOff(int index) |
|
||||
{ |
|
||||
var codeList = _lockLightOffCodeList; |
|
||||
if (!IsIndexValid(codeList, index)) |
|
||||
return false; |
|
||||
var code = codeList[index]; |
|
||||
return _lightRelay.SendHex(code); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 判断功能码是否可以使用
|
|
||||
/// </summary>
|
|
||||
/// <param name="codeList"></param>
|
|
||||
/// <param name="index"></param>
|
|
||||
/// <returns></returns>
|
|
||||
private bool IsIndexValid(List<string> codeList, int index) |
|
||||
{ |
|
||||
if (codeList == null) |
|
||||
return false; |
|
||||
if (index < 1 || index > codeList.Count - 1) |
|
||||
return false; |
|
||||
return true; |
|
||||
} |
|
||||
|
|
||||
#endregion Control Lights
|
|
||||
} |
|
||||
} |
|
@ -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" ] |
||||
|
} |
@ -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" ] |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
{ |
||||
|
"CtrlAllLightCodeList": [ "", "010F0500000401003EC3", "010F05000004010F7EC7" ], |
||||
|
"OpenLightCodeList": [ "" ], |
||||
|
"CloseLightCodeList": [ "" ], |
||||
|
"LockLightOnCodeList": [ "", "010F050000040101FF03", "010F050000040102BF02", "010F0500000401043F00", "010F0500000401083F05" ], |
||||
|
"LockLightOffCodeList": [ "", "010F05000004010EBF07", "010F05000004010DFF06", "010F05000004010B7F04", "010F0500000401077F01" ] |
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
{ |
||||
|
// 控制所有灯编码,1 为开启所有灯,2 为关闭所有灯 |
||||
|
"CtrlAllLightCodeList": [ "" ], |
||||
|
// 开启某一路灯编码,不互斥,index 互相对应 |
||||
|
"OpenLightCodeList": [ "" ], |
||||
|
// 关闭某一路灯编码,不互斥,index 互相对应 |
||||
|
"CloseLightCodeList": [ "" ], |
||||
|
// 互锁编码,控制只有一路灯亮,index 互相对应 |
||||
|
"LockLightOnCodeList": [ "" ], |
||||
|
// 互锁编码,控制只有一路灯灭,index 互相对应 |
||||
|
"LockLightOffCodeList": [ "" ] |
||||
|
} |
Loading…
Reference in new issue