using iWareCcTest.Properties;
using iWareCommon.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace iWareCc.Util
{
public class OPCHelper
{
// ///
// /// 读取指定地址的OPC的值
// ///
// /// 需要读取的地址列表
// /// 输入地址对应的值
// public static List OPCRead(List ItemNames)
// {
// //输入地址为空时输出空
// if (ItemNames == null || ItemNames.Count == 0)
// {
// return null;
// }
// int count = ItemNames.Count;
// List readRtn = new List();//设置返回值数组
// try
// {
// using (var srv = new OPCXML_DataAccess())
// {
// ReadRequestItemList ItemLists = new ReadRequestItemList();
// ItemLists.Items = new ReadRequestItem[count];
// for (int i = 0; i < count; i++)
// {
// ItemLists.Items[i] = new ReadRequestItem();
// ItemLists.Items[i].ItemPath = "";
// ItemLists.Items[i].ItemName = ItemNames[i];
// }
// RequestOptions opt = new RequestOptions();
// ReplyItemList ItemValues = new ReplyItemList(); ;
// OPCError[] Errors;
// opt.ReturnItemTime = true;
// srv.Read(opt, ItemLists, out ItemValues, out Errors);
// foreach (var p in ItemValues.Items)
// {
// readRtn.Add(p.Value);
// }
// }
// }
// catch (Exception ex)
// {
// LogTextHelper.WriteLine(Resources.LogDir, "在类{0}中执行方法{1}时出现异常:{2}", "OPCHelper", "OPCRead", ex.Message);
// }
// return readRtn;
// }
// ///
// /// 单值写入OPCServer
// ///
// /// 地址块
// /// 值
// /// 是否写入成功
// public static bool OPCWritePoint(string ItemName, object value)
// {
// try
// {
// using (var srv = new OPCXML_DataAccess())
// {
// WriteRequestItemList ItemLists = new WriteRequestItemList();
// ItemLists.Items = new ItemValue[1];
// ItemLists.Items[0] = new ItemValue();
// ItemLists.Items[0].ItemPath = "";
// ItemLists.Items[0].ItemName = ItemName;
// ItemLists.Items[0].Value = value;
// ItemLists.Items[0].TimestampSpecified = false;
// RequestOptions opt = new RequestOptions();
// ReplyItemList ItemValues = new ReplyItemList();
// OPCError[] Errors;
// opt.ReturnItemTime = true;
// ReplyBase replay = srv.Write(opt, ItemLists, true, out ItemValues, out Errors);
// return !serverState.failed.Equals(replay.ServerState) && !serverState.commFault.Equals(replay.ServerState);
// }
// }
// catch (Exception ex)
// {
// LogTextHelper.WriteLine(Resources.LogDir, "在类{0}中执行方法{1}时出现异常:{2}", "OPCHelper", "OPCWritePoint", ex.Message);
// return false;
// }
// }
// ///
// /// 写入准入信息
// ///
// ///
// ///
// public static bool SSJLicences(int ssj_Number)
// {
// string LOCALSERVER = "S7:[S7 connection_1]";
// string StackerWrite = "DB540,";
// string WRITE_SSJ_1_Allow = LOCALSERVER + StackerWrite + "B17";//1号输送机入库许可
// string WRITE_SSJ_2_Allow = LOCALSERVER + StackerWrite + "B18";//2号输送机入库许可
// string WRITE_SSJ_3_Allow = LOCALSERVER + StackerWrite + "B19";//3号输送机入库许可
// if (ssj_Number == 1)
// {
// return OPCWritePoint(WRITE_SSJ_1_Allow, 1);
// }
// else if (ssj_Number == 2)
// {
// return OPCWritePoint(WRITE_SSJ_2_Allow, 1);
// }
// else
// {
// return OPCWritePoint(WRITE_SSJ_3_Allow, 1);
// }
// }
// ///
// /// 集合值写入OPC服务器
// ///
// /// 地址块集合
// /// 地址块对应的值
// /// 是否写入成功
// public static bool OPCWriteSerial(List ItemNames, List values)
// {
// try
// {
// using (var srv = new OPCXML_DataAccess())
// {
// int count = ItemNames.Count;
// WriteRequestItemList ItemLists = new WriteRequestItemList();
// ItemLists.Items = new ItemValue[count];
// for (int i = 0; i < count; i++)
// {
// ItemLists.Items[i] = new ItemValue();
// ItemLists.Items[i].ItemPath = "";
// ItemLists.Items[i].ItemName = ItemNames[i];
// ItemLists.Items[i].Value = values[i];
// ItemLists.Items[i].TimestampSpecified = false;
// }
// RequestOptions opt = new RequestOptions();
// ReplyItemList ItemValues = new ReplyItemList();
// OPCError[] Errors;
// opt.ReturnItemTime = true;
// ReplyBase replay = srv.Write(opt, ItemLists, true, out ItemValues, out Errors);
// return !serverState.failed.Equals(replay.ServerState) && !serverState.commFault.Equals(replay.ServerState);
// }
// }
// catch (Exception ex)
// {
// LogTextHelper.WriteLine(Resources.LogDir, "在类{0}中执行方法{1}时出现异常:{2}", "OPCHelper", "OPCWriteSerial", ex.Message);
// return false;
// }
// }
}
}