using System; using System.Collections.Generic; namespace HDL_ON.UI.UI2.Intelligence.Automation { public class LogicMethod { /// /// 生成逻辑sid方法 /// public static string NewSid() { string logicId = ""; try { string sOidBeginsWith = "000101";//厂商 + 通讯方式 DateTime dt = DateTime.Now; DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(2020, 1, 1)); long m = (long)((dt - startTime).TotalMilliseconds / 10); string sTimeSpan = "00000000"; byte[] arry = new byte[4]; arry[0] = (byte)(m & 0xFF); arry[1] = (byte)((m & 0xFF00) >> 8); arry[2] = (byte)((m & 0xFF0000) >> 16); arry[3] = (byte)((m >> 24) & 0xFF); sTimeSpan = arry[0].ToString("X2") + arry[1].ToString("X2") + arry[2].ToString("X2") + arry[3].ToString("X2"); if (sTimeSpan.Length > 8) { sTimeSpan = sTimeSpan.Substring(0, 8); } else { sTimeSpan = "00000000"; } logicId = sOidBeginsWith + sTimeSpan; logicId += "0A"; logicId += "0A01"; //0A01 物模型为逻辑, 0001 表示 1 号逻辑功能 int iTopLogicId = 1; Random random = new Random(); iTopLogicId = random.Next(0, 255); iTopLogicId += random.Next(0, 255); logicId += iTopLogicId.ToString("X4");//逻辑号 两个byte logicId += "1100"; } catch { return logicId; } return logicId; } /// /// 封装Dictionary对象 /// /// Dictionary类 /// 健 /// 值 public static void dictionary(Dictionary dic, string key, string value) { if (dic.ContainsKey(key)) //判断是否存在键值 { //键存在移除 dic.Remove(key); } //添加键值 dic.Add(key, value); } public static void InputCondition() { } } }