private void LoadTagList2(ClsBACnetDevice device) { string[] arrayDeviceCode = device.IfId.Split(new char[] { ',' }, 3); if (arrayDeviceCode.Length < 3) { string[] newArrayCode = new string[3] { "", "", "" }; for (int idx = 0; idx < Math.Min(arrayDeviceCode.Length, newArrayCode.Length); idx++) { newArrayCode[idx] = arrayDeviceCode[idx] ?? ""; } arrayDeviceCode = newArrayCode; } DataSet dsData = GetTagList2(arrayDeviceCode[0], arrayDeviceCode[1], arrayDeviceCode[2]); foreach (DataRow nowRow in dsData.Tables["TagList"].Rows) { int nowTagId = Convert.ToInt32(nowRow["Tag_Id"].ToString()); int nowObjInstance; string strObjInstance = nowRow["Tag_objid2"].ToString(); if (int.TryParse(strObjInstance, out nowObjInstance) != true) { AppendToRichEditControl("ERROR (Obj Instance) : TagId= " + nowTagId.ToString() + ", Tag_objid2= " + strObjInstance); continue; } string strTagType1 = nowRow["Tag_Type"].ToString(); string strTagType2 = nowRow["Tag_objid3"].ToString(); BACnetObjectType nowObjType; if (strTagType2 == "1") { // Value 타입 switch (strTagType1) { case "01": case "02": nowObjType = BACnetObjectType.AV; break; case "03": case "04": nowObjType = BACnetObjectType.BV; break; case "07": case "08": nowObjType = BACnetObjectType.MSV; break; default: AppendToRichEditControl("ERROR (Obj Type) : TagId= " + nowTagId.ToString() + ", Tag_Type= " + strTagType1); continue; } } else { switch (strTagType1) { case "01": nowObjType = BACnetObjectType.AI; break; case "02": nowObjType = BACnetObjectType.AO; break; case "03": nowObjType = BACnetObjectType.BI; break; case "04": nowObjType = BACnetObjectType.BO; break; case "07": nowObjType = BACnetObjectType.MSI; break; case "08": nowObjType = BACnetObjectType.MSO; break; default: AppendToRichEditControl("ERROR (Obj Type) : TagId= " + nowTagId.ToString() + ", Tag_Type= " + strTagType1); continue; } } ClsTagItem nowTagItem = new ClsTagItem(nowTagId, nowObjType, nowObjInstance, device); device.Items.Add(nowTagItem); } }
/// <summary> /// 인터페이스 정보를 읽음 /// </summary> /// <returns></returns> private List <ClsBACnetDevice> GetInterfaceList2() { List <ClsBACnetDevice> rtn = null; string ifid = Program.applicationName.Substring(Program.applicationName.Length - 3, 3); int nIfId = Convert.ToInt32(ifid); DataSet dsInterface = GetDeviceDataFromInterfaceAndTag(nIfId.ToString()); rtn = new List <ClsBACnetDevice>(); try { int idxDevice = 0; Log.log(string.Format("IF Device CNT [{0}]", dsInterface.Tables[0].Rows.Count)); if (dsInterface.Tables[0].Rows.Count > 0) { foreach (DataRow nowRow in dsInterface.Tables[0].Rows) { string nowIfId = String.Format("{0},{1},{2}", nowRow["If_Id"], nowRow["Tag_objid4"], nowRow["Tag_objid"]); Log.log(string.Format("IF ID [{0}]", nowIfId)); IPAddress nowIPAddress; if (IPAddress.TryParse(nowRow["If_Ipaddress"].ToString(), out nowIPAddress) != true) { AppendToRichEditControl("ERROR : NO IPAddress : IfId= " + nowIfId + ", IPAddress= " + nowRow["If_Ipaddress"].ToString()); Log.log("ERROR : NO IPAddress : IfId= " + nowIfId + ", IPAddress= " + nowRow["If_Ipaddress"].ToString()); continue; } string strDNET = nowRow["Tag_objid4"].ToString().Trim(); string strDADR = nowRow["Tag_objid"].ToString().Trim(); // 동일한 BACnet IP로 장치가 여러개 일 때 각 장치의 주소 if (String.IsNullOrEmpty(strDNET) != true & String.IsNullOrEmpty(strDADR) != true) { ushort nowNET; if (ushort.TryParse(strDNET, out nowNET) != true) { AppendToRichEditControl("ERROR : NO DNET : IfId= " + nowIfId + ", Tag_objid4= " + strDNET); Log.log("ERROR : NO DNET : IfId= " + nowIfId + ", Tag_objid4= " + strDNET); continue; } //if (strDADR.Length % 2 != 0) //{ // AppendToRichEditControl("ERROR : Wrong DADR String Length : IfId= " + nowIfId + ", If_Value2= " + strDADR); // Log.log("ERROR : Wrong DADR String Length : IfId= " + nowIfId + ", If_Value2= " + strDADR); // continue; //} //else { // 161114 양만철 // 장치 주소를 10진수에서 16진수 변환 과정 수정 // byte[] nowADR = new byte[strDADR.Length / 2]; // // try // { // for (int idxHex = 0; idxHex < nowADR.Length; idxHex++) // { // string strHex = String.Concat(strDADR[idxHex * 2], strDADR[idxHex * 2 + 1]); // nowADR[idxHex] = Byte.Parse(strHex, System.Globalization.NumberStyles.HexNumber); // //nowADR[idxHex] = Convert.ToByte(strHex); // } // // } // catch (Exception ex) // { // AppendToRichEditControl("ERROR : Wrong DADR String : IfId= " + nowIfId + ", If_Value2= " + strDADR); // Log.log("ERROR : Wrong DADR String : IfId= " + nowIfId + ", If_Value2= " + strDADR); // continue; // } string[] arrayStrADR = strDADR.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); List <byte> listADR = new List <byte>(); foreach (string nowStrADR in arrayStrADR) { try { byte adr = byte.Parse(nowStrADR, System.Globalization.NumberStyles.HexNumber); listADR.Add(adr); } catch { listADR.Clear(); break; } } if (listADR.Count > 0) { /// TODO 161121 장치 주소를 DB에서 읽어와야 위와 같이 매번 수정 하는것을 방지함 /// ---> // 161114 대신증권 BACnet 장치 주소용 // byte[] nowADR = { 0x00, 0x00, 0x00, 0x00, 0x14, 0x09 }; //byte[] nowADR = { 0x00, 0x00, 0x00, 0x00, 0x14, 0x00 }; byte[] nowADR = listADR.ToArray(); // 161114 대신증권 BACnet 장치 주소 중 뒤 2자리만 필요하여 자름 // Ex: 2009 -> 09 //string addr = strDADR.Substring(2, 2); // 161114 문자열을 숫자로 변경 //nowADR[5] = (byte)Convert.ToInt16(addr); /// <--- 161121 여기까지 수정이 필요함 ClsBACnetDevice nowDevice = new ClsBACnetDevice(idxDevice, nowIfId, nowIPAddress, nowNET, nowADR); rtn.Add(nowDevice); idxDevice++; } else { AppendToRichEditControl("ERROR : Wrong DADR String : IfId= " + nowIfId + ", If_Value2= " + strDADR); Log.log("ERROR : Wrong DADR String : IfId= " + nowIfId + ", If_Value2= " + strDADR); continue; } } } else { ClsBACnetDevice nowDevice = new ClsBACnetDevice(idxDevice, nowIfId, nowIPAddress); rtn.Add(nowDevice); idxDevice++; } } // for } else { AppendToRichEditControl("ERROR : NO INTERFACE " + ifid); Log.log("ERROR : NO INTERFACE " + ifid); } string msgTItle = "단위 시스템(BACnet) : Device 갯수 " + idxDevice.ToString(); if (InvokeRequired) { lblTitle.BeginInvoke(new SelectIFNameEditCallback(SelectIFNameEdit), msgTItle); } else { SelectIFNameEdit(msgTItle); } } catch (Exception ex) { Log.log(Program.applicationName + " : " + ex.Message); } return(rtn); }