Commit 8ebdcd5d LN

三色灯有亮灯时增加黄灯闪烁功能。

1 个父辈 11f9fdc6
......@@ -77,20 +77,24 @@ namespace SmartShelf.DeviceLibrary
/// </summary>
public static int CurrLedStatus = -1;
private static List<int> StatusLedDmx = new List<int>();
public static List<int> StatusLedDmx = new List<int>();
/// <summary>
/// 打开状态灯
/// </summary>
public static void OpenStatusLights(string color = "green")
public static void UpdateStatusLights(Dictionary<string,string> dataMap)
{
CloseStatusLights("");
foreach (LEDBaseModule module in deviceMap.Values)
Dictionary<string, List<Light>> lightsMap = new Dictionary<string, List<Light>>();
List<string> ipDmx = new List<string>(dataMap.Keys);
foreach (string key in ipDmx)
{
List<Light> sLed = new List<Light>();
foreach (int dmx in StatusLedDmx)
string color = dataMap[key];
string[] array = key.Split('_');
if (array.Length == 2)
{
string ip = array[0];
int dmx = Convert.ToInt32(array[1]);
LEDBaseModule module = GetLedModule(ip);
List<Light> sLed = new List<Light>();
for (int index = 0; index < module.Max_Light; index++)
{
if ("green".Equals(color))
......@@ -101,28 +105,56 @@ namespace SmartShelf.DeviceLibrary
else if ("yellow".Equals(color))
{
CurrLedStatus = 2;
sLed.Add(Light.BlueLight(dmx, index));
}
sLed.Add(Light.YellowLight(dmx, index));
}
else if ("red".Equals(color))
{
CurrLedStatus = 2;
sLed.Add(Light.RedLight(dmx, index));
}
else
{
CurrLedStatus = 0;
sLed.Add(Light.CloseLight(dmx, index));
}
}
SaveLightToMap(lightsMap, ip, sLed.ToArray());
}
module.LightOn(sLed.ToArray());
Thread.Sleep(100);
}
UpdateLightMap(lightsMap);
}
public static void UpdateLightMap(Dictionary<string, List<Light>> lightsMap )
{
foreach (string dip in lightsMap.Keys)
{
List<Light> lights = lightsMap[dip];
if (lights.Count > 0)
{
LEDManager.GetLedModule(dip).LightOff(lights.ToArray());
Thread.Sleep(50);
}
}
}
/// <summary>
/// 关闭状态灯
/// </summary>
/// <param name="color"></param>
public static void CloseStatusLights(string color = "")
public static void SaveLightToMap(Dictionary<string, List<Light>> lightsMap, string ip, Light[] lightArray)
{
CurrLedStatus = 0;
foreach (LEDBaseModule module in deviceMap.Values)
if (lightArray != null && lightArray.Length > 0)
{
foreach (int dmx in StatusLedDmx)
List<Light> lights = new List<Light>();
if (lightsMap.ContainsKey(ip))
{
module.AllLightOff(dmx);
lights = lightsMap[ip];
}
lights.AddRange(lightArray);
if (lightsMap.ContainsKey(ip))
{
lightsMap[ip] = lights;
}
else
{
lightsMap.Add(ip, lights);
}
}
}
......@@ -205,6 +237,10 @@ namespace SmartShelf.DeviceLibrary
public static byte defaultR = 0;
public static byte defaultG = 50;
public static byte defaultB = 0;
public static Light CloseLight(int dmxId, int index)
{
return new Light(dmxId, index, 0, 0, 0, 0);
}
public static Light DefaultLight(int dmxId, int index)
{
return new Light(dmxId, index, defaultR, defaultG, defaultB, 200);
......
......@@ -71,9 +71,9 @@ namespace SmartShelf.DeviceLibrary
Operation lineOperation = GetLineBoxStatus();
//获取亮灯的库位
string posId = "";
foreach (string key in StatusColorMap.Keys)
foreach (string key in PosIdColorMap.Keys)
{
if (!String.IsNullOrEmpty(StatusColorMap[key]))
if (!String.IsNullOrEmpty(PosIdColorMap[key]))
{
posId = posId + key + "|";
}
......@@ -252,6 +252,6 @@ namespace SmartShelf.DeviceLibrary
}
#endregion
}
}
......@@ -13,6 +13,12 @@ namespace SmartShelf.LoadCSVLibrary
public CSVAttribute(string fieldName)
{
FieldName = fieldName;
IsMust = true;
}
public CSVAttribute(string fieldName, bool ismust)
{
FieldName = fieldName;
IsMust = ismust;
}
private string fieldName;
......@@ -21,7 +27,9 @@ namespace SmartShelf.LoadCSVLibrary
get { return fieldName; }
set { fieldName = value; }
}
/// <summary>
/// 是否必须的
/// </summary>
public bool IsMust { get; set; }
}
}
......@@ -32,6 +32,21 @@ namespace SmartShelf.LoadCSVLibrary
return proCsvMap;
}
public static Dictionary<string, CSVAttribute> getAttributeMap(Type type)
{
Dictionary<string, CSVAttribute> proCsvMap = new Dictionary<string, CSVAttribute>();
PropertyInfo[] props = type.GetProperties();
foreach (PropertyInfo prop in props)
{
CSVAttribute att = (CSVAttribute)prop.GetCustomAttribute(typeof(CSVAttribute), false);
if (att != null)
{
proCsvMap.Add(att.FieldName, att);
}
}
return proCsvMap;
}
/// <summary>
/// 获取一个类所有的《字段,AttributeName列名》集合
/// </summary>
......@@ -124,7 +139,7 @@ namespace SmartShelf.LoadCSVLibrary
}
return titleIndex;
}
protected static Dictionary<string, int> GetTitleIndex(string lineValue, List<string> cvsTitleList)
protected static Dictionary<string, int> GetTitleIndex(string lineValue, List<string> cvsTitleList, Dictionary<string, CSVAttribute> csvAttMap)
{
Dictionary<string, int> titleIndex = new Dictionary<string, int>();
var array = lineValue.Split(',');
......@@ -143,8 +158,15 @@ namespace SmartShelf.LoadCSVLibrary
{
if (!titleIndex.ContainsKey(str))
{
LOGGER.Error("未找到必须列:" + str + ",加载数据失败!");
throw new CVSFieldNotMatchingExection("未找到必须列:" + str + ",加载数据失败!");
if (csvAttMap.ContainsKey(str))
{
if (csvAttMap[str].IsMust)
{
LOGGER.Error("未找到必须列:" + str + ",加载数据失败!");
throw new CVSFieldNotMatchingExection("未找到必须列:" + str + ",加载数据失败!");
}
}
}
}
}
......
......@@ -25,6 +25,33 @@ namespace SmartShelf.LoadCSVLibrary
[CSVAttribute("设备IP")]
public string DeviceIp { get; set; }
[CSVAttribute("指示灯区域ID",false)]
public string StatusLedDmxId { get; set; }
private int sledDmxId = -2;
public int GetStatusLedDmxId()
{
if (sledDmxId < -1)
{
if (String.IsNullOrEmpty(StatusLedDmxId))
{
sledDmxId = -1;
}
else
{
try
{
sledDmxId = Convert.ToInt32(StatusLedDmxId);
}
catch (Exception ex)
{
}
}
}
return sledDmxId;
}
private List<int> LedList = null;
public List<int> GetLedList()
......
......@@ -56,6 +56,7 @@ namespace SmartShelf.LoadCSVLibrary
Type type = typeof(T);
Dictionary<string, string> proTitleMap = getProAttributeMap(typeof(T));
Dictionary<string, CSVAttribute> csvAttMap = getAttributeMap(typeof(T));
if (proTitleMap.Count <= 4)
{
LOGGER.Error(typeof(T).ToString() + "只读取到" + proTitleMap.Count + "个属性");
......@@ -73,7 +74,7 @@ namespace SmartShelf.LoadCSVLibrary
var array = line.Split(Spilt_Char);
if (index == 0)
{
titleIndex = GetTitleIndex(line, cvsTitleList);
titleIndex = GetTitleIndex(line, cvsTitleList, csvAttMap);
}
else
{
......@@ -93,17 +94,31 @@ namespace SmartShelf.LoadCSVLibrary
string PositionNum = "";
foreach (string key in cvsTitleList)
{
int titIndex = titleIndex[key];
string value = array[titIndex];
string proName = propertyList[listIndex];
PropertyInfo prop = props.First(c => c.Name == proName);//获取同名属性
if (prop != null && value != "")
{//如果属性存在
prop.SetValue(bllIns, Convert.ChangeType(value, prop.PropertyType), null);//赋值****在这里需要考虑类型问题
if (titleIndex.ContainsKey(key))
{
int titIndex = titleIndex[key];
string value = array[titIndex];
if (prop != null && value != "")
{//如果属性存在
prop.SetValue(bllIns, Convert.ChangeType(value, prop.PropertyType), null);//赋值****在这里需要考虑类型问题
}
if (proName.Equals("PositionNum"))
{
PositionNum = value;
}
}
if (proName.Equals("PositionNum"))
else
{
PositionNum = value;
if (prop.PropertyType.Equals(typeof(int)))
{
prop.SetValue(bllIns, Convert.ChangeType(0, prop.PropertyType), null);//赋值****在这里需要考虑类型问题
}
else
{
prop.SetValue(bllIns, Convert.ChangeType("", prop.PropertyType), null);//赋值****在这里需要考虑类型问题
}
}
listIndex++;
}
......@@ -155,6 +170,7 @@ namespace SmartShelf.LoadCSVLibrary
Type type = typeof(T);
Dictionary<string, string> proTitleMap = getProAttributeMap(typeof(T));
Dictionary<string, CSVAttribute> csvAttMap = getAttributeMap(typeof(T));
if (proTitleMap.Count <= 4)
{
LOGGER.Error(typeof(T).ToString() + "只读取到" + proTitleMap.Count + "个属性");
......@@ -172,7 +188,7 @@ namespace SmartShelf.LoadCSVLibrary
var array = line.Split(',');
if (index == 0)
{
titleIndex = GetTitleIndex(line, cvsTitleList);
titleIndex = GetTitleIndex(line, cvsTitleList, csvAttMap);
}
else
{
......
......@@ -227,17 +227,17 @@ namespace SmartShelf
private void btnOpenSLed_Click(object sender, EventArgs e)
{
LEDManager.OpenStatusLights("green");
BOXManager.OpenStatusLights("green");
}
private void btnCloseSLed_Click(object sender, EventArgs e)
{
LEDManager.CloseStatusLights();
BOXManager.CloseStatusLights();
}
private void button5_Click(object sender, EventArgs e)
{
LEDManager.OpenStatusLights("yellow");
BOXManager.OpenStatusLights("yellow");
}
private void btOAll_Click(object sender, EventArgs e)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!