public void GatewayManager_Set_TagValue(cls_ProcRecv_CollectData ProcRecv_CollectData) { string _GateWayID = ProcRecv_CollectData.GateWayID; string _DeviceID = ProcRecv_CollectData.Device_ID; cls_Gateway_Info Gateway = GatewayManager.gateway_list.Where(p => p.gateway_id == _GateWayID).FirstOrDefault(); if (Gateway != null) { cls_Device_Info Device = Gateway.device_info.Where(p => p.device_name == _DeviceID).FirstOrDefault(); if (Device != null) { Tuple <string, string> _tag = null; while (ProcRecv_CollectData.Prod_EDC_Data.TryDequeue(out _tag)) { if (Device.tag_info.ContainsKey(_tag.Item1)) { cls_Tag tag = Device.tag_info[_tag.Item1]; tag.Value = _tag.Item2; Device.tag_info.AddOrUpdate(_tag.Item1, tag, (key, oldvalue) => tag); } } } else { // NLogManager.Logger.LogError("Service", GetType().Name, MethodInfo.GetCurrentMethod().Name, string.Format("Device {0} Not Exist, So Skip Update Tag Value", _DeviceID)); } } else { // NLogManager.Logger.LogError("Service", GetType().Name, MethodInfo.GetCurrentMethod().Name, string.Format("Gateway {0} Not Exist, So Skip Update Tag Value", _GateWayID)); } }
public string GatewayCommand_Json(string _Cmd_Type, string _Report_Interval, string _Trace_ID, string _GateWayID, string _DeviceID) { cls_Gateway_Info Gateway = GatewayManager.gateway_list.Where(p => p.gateway_id == _GateWayID).FirstOrDefault(); if (Gateway == null) { return(null); } else { cls_Device_Info Device = Gateway.device_info.Where(p => p.device_name == _DeviceID).FirstOrDefault(); if (Device == null) { return(null); } else { cls_Collect collect_cmd = new cls_Collect(_Cmd_Type, _Report_Interval, _Trace_ID, Device); return(JsonConvert.SerializeObject(collect_cmd, Newtonsoft.Json.Formatting.Indented)); } } }
public cls_Collect(string _Cmd_Type, string _Report_Interval, string _Trace_ID, cls_Device_Info _DeviceInfo) { Cmd_Type = _Cmd_Type; Report_Interval = _Report_Interval; Trace_ID = _Trace_ID; //-------運算使用 ------ char[] delimiterChars = { '.', ':' }; int first_colon_index = -1; int first_dot_index = -1; foreach (KeyValuePair <string, cls_Tag> kvp in _DeviceInfo.tag_info) { cls_Collect_Tag temp = new cls_Collect_Tag(); temp.DATA_NAME = kvp.Value.TagName; temp.DATA_TYPE = "BLOCK";// kvp.Value.Expression; string[] Split_Words = kvp.Value.UUID_Address.Split(delimiterChars); temp.DATA_ADDR = Split_Words[0]; switch (kvp.Value.Expression) { case "BIT": temp.DATA_LENGTH = "1"; break; case "UINT": temp.DATA_LENGTH = "1"; break; case "SINT": temp.DATA_LENGTH = "1"; break; case "ULONG": temp.DATA_LENGTH = "2"; break; case "SLONG": temp.DATA_LENGTH = "2"; break; case "ASC": //---- Address 用法 W1000:3000 first_colon_index = kvp.Value.UUID_Address.IndexOf(":"); first_dot_index = kvp.Value.UUID_Address.IndexOf("."); if ((first_colon_index > -1) && first_dot_index == -1) // W1000:3000 { int start = int.Parse(Split_Words[0].Replace("W", "").Replace("w", "")); int end = int.Parse(Split_Words[1].Replace("W", "").Replace("w", "")); int diff = (end - start) + 1; if (diff > 0) { temp.DATA_LENGTH = diff.ToString(); } else { temp.DATA_LENGTH = "1"; } } else { temp.DATA_LENGTH = "1"; } break; default: temp.DATA_LENGTH = "1"; break; } Address_Info.Add(temp); } }