注塑喷涂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

115 lines
2.9 KiB

using OPCAutomation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace PunchAndWeld
{
public class OPCHelper
{
public OPCServer opcServer;
public OPCGroups opcGroups;
public OPCGroup opcGroup1;
public OPCItems opcItems1;
public OPCItem[] opcItemm1;
public OPCGroup opcGroup2;
public OPCItems opcItems2;
public OPCItem[] opcItemm2;
public string[] ItemIDs;
public object ItemValues;
public object Qualities;
public object TimeStamps;
public bool Connected = false;
public bool CreateServer()
{
try
{
opcServer = new OPCServer();
}
catch(Exception ex)
{
LogHelper.WriteErrLogBase(ex.ToString(), "CreateServer");
return false;
}
return true;
}
public bool ConnectServer(string strHostIP, string strHostName)
{
try
{
opcServer.Connect(strHostName, strHostIP);
}
catch
{
return false;
}
return true;
}
public void SetGroupProperty(OPCGroup opcGroup, int updateRate)
{
opcGroup.IsActive = true;
opcGroup.DeadBand = 0;
opcGroup.UpdateRate = updateRate;
opcGroup.IsSubscribed = true;
}
public string ReadSingleValueFromOPC1(int i)
{
object ItemValues;
object Qualities;
object TimeStamps;
opcItemm1[i].Read(1, out ItemValues, out Qualities, out TimeStamps);
if ((ItemValues != null) && (Qualities.ToString() != "Good"))
{
return ItemValues.ToString();
}
else
{
return "";
}
}
public int ReadSingleValueFromOPC2(int i)
{
object ItemValues;
object Qualities;
object TimeStamps;
opcItemm1[i].Read(1, out ItemValues, out Qualities, out TimeStamps);
if ((ItemValues != null) && (Qualities.ToString() != "Good"))
{
return Convert.ToInt32(ItemValues.ToString());
}
else
{
return 0;
}
}
public string ReadSingleValueFromOPC3(int i)
{
object ItemValues;
object Qualities;
object TimeStamps;
opcItemm2[i].Read(1, out ItemValues, out Qualities, out TimeStamps);
if ((ItemValues != null) && (Qualities.ToString() != "Good"))
{
return ItemValues.ToString();
}
else
{
return "";
}
}
}
}