public object itemREAD(OPCItem item) { object ItemValues; object Qualities; object TimeStamps; item.Read(1, out ItemValues, out Qualities, out TimeStamps); return(ItemValues); }
/// <summary> /// 获取节点的所有值,显示在listview中 /// </summary> private void ShowListView() { if (!CreateGroup()) { return; } object value; object quality; object timestamp; //itmHandlerClient = 1234; OPCBrowser opcbrowser = ServerConnect.KepServer.CreateBrowser(); list = RecurBrowse(opcbrowser); for (int i = 0; i < list.Count; i++) { KepItem = KepItems.AddItem(list[i], itmHandlerClient); itmHandlerServer = KepItem.ServerHandle; KepItem.Read((short)OPCDataSource.OPCDevice, out value, out quality, out timestamp); lv = new ListViewItem(list[i]); lv.SubItems.Add(Convert.ToString(value)); lv.SubItems.Add(quality.ToString()); lv.SubItems.Add(timestamp.ToString()); listView1.Items.Add(lv); } }
////读取标签值 private static string[,] readitemvalue() { OPCItem OPC_item; try { int a = opc_group.OPCItems.Count; string[,] itemvalue = new string[a, 6]; // if (groupadd == true) { for (int i = 1; i < opc_group.OPCItems.Count; i++) { OPC_item = opc_group.OPCItems.Item(i); string strID = OPC_item.ItemID; //if (strID == "CPU224.Input.I00") { object quantity; object time; object dya; OPC_item.Read(1, out dya, out quantity, out time); foreach (var aaa in allservers) { itemvalue[i - 1, 0] = (string)aaa; } itemvalue[i - 1, 1] = strID; itemvalue[i - 1, 2] = quantity.ToString(); itemvalue[i - 1, 3] = Convert.ToDateTime(time).AddHours(8).ToString("yyyy-MM-dd HH:mm"); itemvalue[i - 1, 4] = dya.ToString(); itemvalue[i - 1, 5] = i.ToString(); } } } return(itemvalue); } catch (Exception ex) { MessageBox.Show("获取标签值失败\n" + ex.Message); OPC_item = null; opc_group = null; OPC_server.Disconnect(); connected = false; groupadd = false; string[,] a = new string[1, 6]; a[0, 0] = ""; a[0, 1] = ""; a[0, 2] = ""; a[0, 3] = ""; a[0, 4] = ""; a[0, 5] = ""; return(a); } }
/// <summary> /// 通过itemname来获取相应的value值和时间并展示在listview中 /// </summary> /// <param name="node"></param> public void ShowData(string node) { itemNames.Add(node); //itmHandlerClient = ++itmHandlerClient; KepItem = KepItems.AddItem(node, itmHandlerClient); itmHandlerServer = KepItem.ServerHandle; KepItem.Read(1, out value, out quality, out timestamp); listView1.BeginUpdate(); lv = new ListViewItem(node); lv.Name = node; lv.SubItems.Add(Convert.ToString(value)); lv.SubItems.Add(quality.ToString()); lv.SubItems.Add(timestamp.ToString()); listView1.Items.Add(lv); listView1.EndUpdate(); }
public bool TagCheck(string tag) { try { OPCItem opcItme = objGroup.OPCItems.AddItem(tag, 0); //byte Thread.Sleep(100); object ItemValues; object Qualities; object TimeStamps; //同步读的临时变量:值、质量、时间戳 opcItme.Read(1, out ItemValues, out Qualities, out TimeStamps); //同步读,第一 ConnDispose(); return(true); } catch { ConnDispose(); return(false); } }
/// <summary> /// 实时计时器的响应函数,会调用脉冲频率 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> //void intime_Tick(object sender, EventArgs e) //{ // Todo_in(pulsedata); //} /// <summary> /// 实时读取波形数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void boxing_Tick(object sender, EventArgs e) { object value; object quality; object timeStamp; if (connecteds) { item_chuan.Read((short)OPCDataSource.OPCCache, out value, out quality, out timeStamp); chuandata = (byte[])value; } else { chuandata = new byte[] { 0x00, 0x00, 0x00, 0x00 }; } Todo_chuan(chuandata); }
public string ReadDataByTag(OPCItem item, string tag) { object PValue; object PQuality; object PTimeStamp; string res = ""; try { item.Read(1, out PValue, out PQuality, out PTimeStamp); if (Convert.ToInt32(PQuality) != 0) { if (Convert.ToString(PValue) == "True") { res = "1"; } else if (Convert.ToString(PValue) == "False") { res = "0"; } else { res = Convert.ToString(PValue).Trim(); } if (res == "System.Int16[]") { res = ObjectToString(PValue).Trim(); } } else if (Convert.ToInt32(PQuality) == 0) { res = null; } } catch (Exception err) { string errtxt = string.Format("读取一级数据{0}出现错误:{1}", tag, err.Message); Logger.logwrite(errtxt); Logger.logwrite(errtxt, "OPC"); initOPC(); res = OPC_ERROR_FLAG; } return(res); }
/// <summary> /// 读取PLC中的值 /// </summary> /// <param name="itemName"></param> /// <returns></returns> public PlcValue GetPlcValue(string itemName) { lock (o1) { PlcValue plc = new PlcValue(); OPCItem opcitem = dic[itemName]; if (opcitem != null) { object Value, Quality, TimeStamp; opcitem.Read(1, out Value, out Quality, out TimeStamp); plc.objectTimeStamp = TimeStamp; plc.Quality = Quality; plc.Value = Value; plc.ClientHandle = opcitem.ClientHandle; } return(plc); } }
public string ReadNodeLabel(string name) { MonitorOPCItem(name); if (clientHandleDict.ContainsKey(name)) { OPCItem item = opcAGroup.OPCItems.GetOPCItem(clientHandleDict[name].ServerHandler); if (item.Value != null) { return(item.Value.ToString()); } else { object value, quality, timestamp; item.Read(1, out value, out quality, out timestamp); return(value.ToString()); } } return(string.Empty); }
/// <summary> /// 使用同步方法读取宁波监控点位置 /// </summary> public void ReadNBTag() { if (validTagFlagNB) { object value, quality, timeStamp; try { monitorItemNB.Read(1, out value, out quality, out timeStamp); } catch (Exception ex) { WriteMsg("读取宁波点位值失败:" + ex.Message); ReadFailureOpNB(); return; } if (quality != null && quality.ToString() == MES_DATA_GOOD_QUALITY) { WriteMsg("成功获取宁波点位值:" + value + " 时间:" + DateTime.Parse(timeStamp.ToString()).AddHours(8).ToString("G")); //若曾达到失败起始值,则提醒恢复正常 if (readFailureCountNB >= configInfo.MinAlertCount) { string smsContent = string.Format("宁波监控点位在读取失败{0}次后恢复正常.", readFailureCountNB); SendSmsMessage(smsContent); } //只要任何读到正常值,则将报警计数置为0 readFailureCountNB = 0; } else { WriteMsg("获取宁波点位质量属性为Bad:" + quality.ToString()); ReadFailureOpNB(); } } else { WriteMsg("宁波点位名无效"); } }
public void ReadCurrentValue(out object aValue, out int aQuality, out DateTime aReadTime) { if (!IsActive) { throw new OpcValueException( "OPC параметр не активирован, но предпринята попытка чтения: " + Name); } object value; object quality; object timeStamp; try { opcItem.Read((short)Source, out value, out quality, out timeStamp); } catch (Exception ex) { throw new OpcValueException(string.Format("Ошибка при чтении " + "значения тега {0}: {1}", Name, ex.Message)); } aValue = value; aQuality = Convert.ToInt32(quality); aReadTime = Convert.ToDateTime(timeStamp); }
public bool Read(string groupName, string itemID, out object result) { bool re = false; result = null; try { // Console.WriteLine("{0},{1}", groupName, itemID); OPCGroup myGroup = myServer.OPCGroups.GetOPCGroup(groupName); if (myGroup == null) { return(false); } // Console.WriteLine("开始读OPC Item:{0}", itemID); OPCItem myItem = myGroup.OPCItems.Item(itemID); if (myItem == null) { return(false); } object quality = 0; object timeStamp = 0; short source = (short)OPCDataSource.OPCDevice; OPCItem item = myGroup.OPCItems.Item(itemID); myItem = myGroup.OPCItems.GetOPCItem(item.ServerHandle); myItem.Read(source, out result, out quality, out timeStamp); return(true); } catch (System.Exception ex) { Console.WriteLine("发生异常:{0},{1},{2}", groupName, itemID, ex.ToString()); return(false); } }
public override object Read(string itemName) { OPCItem item = GetItem(itemName); return(item.Read()); }