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.
548 lines
21 KiB
548 lines
21 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using OPCPLC;
|
|
using System.Threading;
|
|
|
|
namespace EQUIPINTERFACETEST
|
|
{
|
|
public class FS_FJC_Test
|
|
{
|
|
public void Test()
|
|
{
|
|
|
|
OPCPLCAutomation gtxConnection = new OPCPLC.OPCPLCAutomation();
|
|
|
|
//opcServer服务器IP
|
|
string opcServerIP = "10.122.216.65";
|
|
|
|
//opcServer服务名称
|
|
string opcServerName = "Kepware.KEPServerEX.V4";
|
|
|
|
gtxConnection.GetListOPCServers(opcServerIP);
|
|
//连接Opc服务
|
|
gtxConnection.ConnectRemoteServer(opcServerName, opcServerIP);
|
|
|
|
gtxConnection.CreateGroup("GetData");
|
|
|
|
|
|
|
|
int clientHandleValue = 2;
|
|
int v = gtxConnection.AddKepItem("Channel1.NF_ZDH_IP56.ZDH_Parameter57", clientHandleValue);
|
|
|
|
while (true)
|
|
{
|
|
Thread.Sleep(5000);
|
|
|
|
|
|
var moldnumber = gtxConnection.ReadtagValue(v);
|
|
if (moldnumber != null)
|
|
{
|
|
Console.WriteLine(System.DateTime.Now.ToLongTimeString() + "输出 " + moldnumber.ToString());
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine(System.DateTime.Now.ToLongTimeString() + "输出 " + "null");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public void GetValueTest()
|
|
{
|
|
|
|
OPCPLCAutomation gtxConnection = new OPCPLC.OPCPLCAutomation();
|
|
|
|
//opcServer服务器IP
|
|
string opcServerIP = "127.0.0.1";
|
|
|
|
//opcServer服务名称
|
|
string opcServerName = "Kepware.KEPServerEX.V4";
|
|
|
|
gtxConnection.GetListOPCServers(opcServerIP);
|
|
//连接Opc服务
|
|
gtxConnection.ConnectRemoteServer(opcServerName, opcServerIP);
|
|
|
|
gtxConnection.CreateGroup("GetData");
|
|
|
|
|
|
|
|
Dictionary<string, int> dict = new Dictionary<string, int>();
|
|
|
|
string tagTitle = "Channel1.NF_ZDH_IP166.ZDH_Parameter";
|
|
|
|
for (int i = 1; i < 58; i++)
|
|
{
|
|
|
|
if (i == 56)
|
|
continue;
|
|
string tag = tagTitle + i.ToString().PadLeft(2, '0');
|
|
int v = gtxConnection.AddKepItem(tag, i);
|
|
//var moldnumber = gtxConnection.ReadtagValue(v);
|
|
//if (moldnumber != null)
|
|
//{
|
|
// Console.WriteLine("Channel1.NF_ZDH_IP166.ZDH_Parameter" + i.ToString().PadLeft(2, '0') + "输出 " + moldnumber.ToString());
|
|
//}
|
|
//else
|
|
//{
|
|
// Console.WriteLine("Channel1.NF_ZDH_IP166.ZDH_Parameter" + i.ToString().PadLeft(2, '0') + "输出 " + "null");
|
|
//}
|
|
|
|
dict.Add(tag, v);
|
|
}
|
|
|
|
while (true)
|
|
{
|
|
|
|
Thread.Sleep(10000);
|
|
WriteLog.Write(System.DateTime.Now.ToLongTimeString());
|
|
|
|
Console.WriteLine(System.DateTime.Now.ToLongTimeString());
|
|
|
|
byte[] barcode1 = new byte[17];
|
|
|
|
int index = 0;
|
|
|
|
for (int i = 1; i < 58; i++)
|
|
{
|
|
if (i < 23 || i > 39)
|
|
continue;
|
|
|
|
string tag = tagTitle + i.ToString().PadLeft(2, '0');
|
|
int v = dict[tag];
|
|
|
|
var moldnumber = gtxConnection.ReadtagValue(v);
|
|
|
|
if (moldnumber != null)
|
|
{
|
|
// Console.WriteLine(tag + "输出 " + moldnumber.ToString());
|
|
// WriteLog.Write(tag + "输出 " + moldnumber.ToString());
|
|
barcode1[index] = byte.Parse(moldnumber.ToString());
|
|
|
|
if (i == 39)
|
|
{
|
|
Console.WriteLine(tag + "输出 " + System.Text.Encoding.GetEncoding("GB2312").GetString(barcode1).Substring(0, 15));
|
|
WriteLog.Write(tag + "输出 " + System.Text.Encoding.GetEncoding("GB2312").GetString(barcode1).Substring(0, 15));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (i == 39)
|
|
{
|
|
Console.WriteLine(tag + "输出null");
|
|
WriteLog.Write(tag + "输出null");
|
|
}
|
|
}
|
|
index++;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Test165()
|
|
{
|
|
|
|
OPCPLCAutomation gtxConnection = new OPCPLC.OPCPLCAutomation();
|
|
|
|
//opcServer服务器IP
|
|
//string opcServerIP = "10.122.216.65";
|
|
string opcServerIP = "127.0.0.1";
|
|
|
|
//opcServer服务名称
|
|
string opcServerName = "Kepware.KEPServerEX.V4";
|
|
|
|
gtxConnection.GetListOPCServers(opcServerIP);
|
|
//连接Opc服务
|
|
gtxConnection.ConnectRemoteServer(opcServerName, opcServerIP);
|
|
|
|
gtxConnection.CreateGroup("GetData");
|
|
|
|
|
|
Dictionary<string, int> dict = new Dictionary<string, int>();
|
|
|
|
string tagTitle = "Channel1.NF_ZDH_IP166.ZDH_Parameter";
|
|
|
|
for (int i = 1; i < 59; i++)
|
|
{
|
|
|
|
if (i == 56)
|
|
continue;
|
|
string tag = tagTitle + i.ToString().PadLeft(2, '0');
|
|
int v = gtxConnection.AddKepItem(tag, i);
|
|
//var moldnumber = gtxConnection.ReadtagValue(v);
|
|
//if (moldnumber != null)
|
|
//{
|
|
// Console.WriteLine("Channel1.NF_ZDH_IP166.ZDH_Parameter" + i.ToString().PadLeft(2, '0') + "输出 " + moldnumber.ToString());
|
|
//}
|
|
//else
|
|
//{
|
|
// Console.WriteLine("Channel1.NF_ZDH_IP166.ZDH_Parameter" + i.ToString().PadLeft(2, '0') + "输出 " + "null");
|
|
//}
|
|
|
|
dict.Add(tag, v);
|
|
}
|
|
|
|
while (true)
|
|
{
|
|
|
|
Thread.Sleep(3000);
|
|
WriteLog.Write(System.DateTime.Now.ToLongTimeString());
|
|
|
|
Console.WriteLine(System.DateTime.Now.ToLongTimeString());
|
|
|
|
byte[] barcode1 = new byte[17];
|
|
|
|
int index = 0;
|
|
|
|
for (int i = 1; i < 59; i++)
|
|
{
|
|
#region
|
|
if (i < 23 || i > 39)
|
|
continue;
|
|
|
|
string tag = tagTitle + i.ToString().PadLeft(2, '0');
|
|
int v = dict[tag];
|
|
|
|
var moldnumber = gtxConnection.ReadtagValue(v);
|
|
|
|
if (moldnumber != null)
|
|
{
|
|
// Console.WriteLine(tag + "输出 " + moldnumber.ToString());
|
|
// WriteLog.Write(tag + "输出 " + moldnumber.ToString());
|
|
barcode1[index] = byte.Parse(moldnumber.ToString());
|
|
|
|
if (i == 39)
|
|
{
|
|
Console.WriteLine(tag + "输出 " + System.Text.Encoding.GetEncoding("GB2312").GetString(barcode1).Substring(0, 15));
|
|
WriteLog.Write(tag + "输出 " + System.Text.Encoding.GetEncoding("GB2312").GetString(barcode1).Substring(0, 15));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (i == 39)
|
|
{
|
|
Console.WriteLine(tag + "输出null");
|
|
WriteLog.Write(tag + "输出null");
|
|
}
|
|
}
|
|
index++;
|
|
|
|
|
|
#endregion
|
|
}
|
|
|
|
|
|
for (int j = 1; j < 59; j++)
|
|
{
|
|
if ((j >= 23 && j <= 39)||j==56)
|
|
continue;
|
|
|
|
string tag = tagTitle + j.ToString().PadLeft(2, '0');
|
|
int v = dict[tag];
|
|
|
|
var moldnumber = gtxConnection.ReadtagValue(v);
|
|
|
|
if (tag.Contains("ZDH_Parameter01"))
|
|
{
|
|
Console.WriteLine("FrequencyHz=" + moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter02"))
|
|
{
|
|
Console.WriteLine("SetVibrationTimes="+ (Convert.ToDouble(moldnumber) / 10).ToString("0.0"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter03"))
|
|
{
|
|
Console.WriteLine("ActualVibrationTimes ="+ (Convert.ToDouble(moldnumber) / 10).ToString("0.0"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter04"))
|
|
{
|
|
Console.WriteLine("SetCoolingTimes ="+ (Convert.ToDouble(moldnumber) / 10).ToString("0.0"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter05"))
|
|
{
|
|
Console.WriteLine("ActualCoolingTimes = "+(Convert.ToDouble(moldnumber) / 10).ToString("0.0"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter06"))
|
|
{
|
|
UInt32 uvalues6 = UInt32.Parse(moldnumber.ToString());
|
|
Int32 ivale6 = (Int32)uvalues6;
|
|
//((Int32)ItemValues.GetValue(6)).ToString();
|
|
Console.WriteLine("SetWeldingSize = "+((ivale6 / 100.00)).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter07"))
|
|
{
|
|
UInt32 uvalues7 = UInt32.Parse(moldnumber.ToString());
|
|
Int32 ivale7 = (Int32)uvalues7;
|
|
Console.WriteLine("ActualWeldingSize ="+ ((ivale7 / 100.00)).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter08"))
|
|
{
|
|
UInt32 uvalues8 = UInt32.Parse(moldnumber.ToString());
|
|
Int32 ivale8 = (Int32)uvalues8;
|
|
Console.WriteLine("SetLifting ="+ ((ivale8 / 100.00)).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter09"))
|
|
{
|
|
UInt32 uvalues9 = UInt32.Parse(moldnumber.ToString());
|
|
Int32 ivale9 = (Int32)uvalues9;
|
|
Console.WriteLine("ActualLifting ="+ ((ivale9 / 100.00)).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter10"))
|
|
{
|
|
UInt32 uvalues10 = UInt32.Parse(moldnumber.ToString());
|
|
Int32 ivale10 = (Int32)uvalues10;
|
|
Console.WriteLine("Referencepoint = "+((ivale10 / 100.00)).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter11"))
|
|
{
|
|
Console.WriteLine("SetFriction = "+(Convert.ToDouble(moldnumber) / 100).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter12"))
|
|
{
|
|
Console.WriteLine("ActualFriction ="+ (Convert.ToDouble(moldnumber) / 100).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter13"))
|
|
{
|
|
Console.WriteLine("SetWelding ="+ (Convert.ToDouble(moldnumber) / 100).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter14"))
|
|
{
|
|
Console.WriteLine("ActualWelding ="+ (Convert.ToDouble(moldnumber) / 100).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter15"))
|
|
{
|
|
Console.WriteLine("UpwardBar = "+moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter16"))
|
|
{
|
|
Console.WriteLine("DropBar ="+ moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter17"))
|
|
{
|
|
Console.WriteLine("SetFrictionBar ="+ moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter18"))
|
|
{
|
|
Console.WriteLine("ActualFrictionBar ="+ moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter19"))
|
|
{
|
|
Console.WriteLine("SetWeldingBar ="+ moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter20"))
|
|
{
|
|
Console.WriteLine("ActualWeldingBar ="+ moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter21"))
|
|
{
|
|
Console.WriteLine("SetCoolingBar ="+ moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter22"))
|
|
{
|
|
Console.WriteLine("ActualCoolingBar ="+ moldnumber.ToString());
|
|
}
|
|
|
|
|
|
|
|
//闫永刚 2016:4:7 获取模具号
|
|
if (tag.Contains("ZDH_Parameter57"))
|
|
{
|
|
Console.WriteLine("MoldNumber ="+ moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter58"))
|
|
{
|
|
Console.WriteLine("ColorValue ="+ Convert.ToInt32(moldnumber));
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public void Test166()
|
|
{
|
|
OPCPLCAutomation gtxConnection = new OPCPLC.OPCPLCAutomation();
|
|
|
|
//opcServer服务器IP
|
|
string opcServerIP = "127.0.0.1";
|
|
|
|
//opcServer服务名称
|
|
string opcServerName = "Kepware.KEPServerEX.V4";
|
|
|
|
gtxConnection.GetListOPCServers(opcServerIP);
|
|
//连接Opc服务
|
|
gtxConnection.ConnectRemoteServer(opcServerName, opcServerIP);
|
|
|
|
gtxConnection.CreateGroup("GetData");
|
|
|
|
|
|
|
|
Dictionary<string, int> dict = new Dictionary<string, int>();
|
|
|
|
string tagTitle = "Channel1.NF_ZDH_IP166.ZDH_Parameter";
|
|
|
|
for (int i = 1; i < 59; i++)
|
|
{
|
|
|
|
if (i == 56)
|
|
continue;
|
|
string tag = tagTitle + i.ToString().PadLeft(2, '0');
|
|
int v = gtxConnection.AddKepItem(tag, i);
|
|
//var moldnumber = gtxConnection.ReadtagValue(v);
|
|
//if (moldnumber != null)
|
|
//{
|
|
// Console.WriteLine("Channel1.NF_ZDH_IP166.ZDH_Parameter" + i.ToString().PadLeft(2, '0') + "输出 " + moldnumber.ToString());
|
|
//}
|
|
//else
|
|
//{
|
|
// Console.WriteLine("Channel1.NF_ZDH_IP166.ZDH_Parameter" + i.ToString().PadLeft(2, '0') + "输出 " + "null");
|
|
//}
|
|
|
|
dict.Add(tag, v);
|
|
}
|
|
|
|
while (true)
|
|
{
|
|
|
|
Thread.Sleep(3000);
|
|
WriteLog.Write(System.DateTime.Now.ToLongTimeString());
|
|
|
|
Console.WriteLine(System.DateTime.Now.ToLongTimeString());
|
|
|
|
|
|
for (int j = 1; j < 23; j++)
|
|
{
|
|
if ((j >= 23 && j <= 39) || j == 56)
|
|
continue;
|
|
|
|
string tag = tagTitle + j.ToString().PadLeft(2, '0');
|
|
int v = dict[tag];
|
|
|
|
var moldnumber = gtxConnection.ReadtagValue(v);
|
|
|
|
if (tag.Contains("ZDH_Parameter01"))
|
|
{
|
|
Console.WriteLine("FrequencyHz=" + moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter02"))
|
|
{
|
|
Console.WriteLine("SetVibrationTimes=" + (Convert.ToDouble(moldnumber) / 10).ToString("0.0"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter03"))
|
|
{
|
|
Console.WriteLine("ActualVibrationTimes =" + (Convert.ToDouble(moldnumber) / 10).ToString("0.0"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter04"))
|
|
{
|
|
Console.WriteLine("SetCoolingTimes =" + (Convert.ToDouble(moldnumber) / 10).ToString("0.0"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter05"))
|
|
{
|
|
Console.WriteLine("ActualCoolingTimes = " + (Convert.ToDouble(moldnumber) / 10).ToString("0.0"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter06"))
|
|
{
|
|
UInt32 uvalues6 = UInt32.Parse(moldnumber.ToString());
|
|
Int32 ivale6 = (Int32)uvalues6;
|
|
//((Int32)ItemValues.GetValue(6)).ToString();
|
|
Console.WriteLine("SetWeldingSize = " + ((ivale6 / 100.00)).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter07"))
|
|
{
|
|
UInt32 uvalues7 = UInt32.Parse(moldnumber.ToString());
|
|
Int32 ivale7 = (Int32)uvalues7;
|
|
Console.WriteLine("ActualWeldingSize =" + ((ivale7 / 100.00)).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter08"))
|
|
{
|
|
UInt32 uvalues8 = UInt32.Parse(moldnumber.ToString());
|
|
Int32 ivale8 = (Int32)uvalues8;
|
|
Console.WriteLine("SetLifting =" + ((ivale8 / 100.00)).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter09"))
|
|
{
|
|
UInt32 uvalues9 = UInt32.Parse(moldnumber.ToString());
|
|
Int32 ivale9 = (Int32)uvalues9;
|
|
Console.WriteLine("ActualLifting =" + ((ivale9 / 100.00)).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter10"))
|
|
{
|
|
UInt32 uvalues10 = UInt32.Parse(moldnumber.ToString());
|
|
Int32 ivale10 = (Int32)uvalues10;
|
|
Console.WriteLine("Referencepoint = " + ((ivale10 / 100.00)).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter11"))
|
|
{
|
|
Console.WriteLine("SetFriction = " + (Convert.ToDouble(moldnumber) / 100).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter12"))
|
|
{
|
|
Console.WriteLine("ActualFriction =" + (Convert.ToDouble(moldnumber) / 100).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter13"))
|
|
{
|
|
Console.WriteLine("SetWelding =" + (Convert.ToDouble(moldnumber) / 100).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter14"))
|
|
{
|
|
Console.WriteLine("ActualWelding =" + (Convert.ToDouble(moldnumber) / 100).ToString("0.00"));
|
|
}
|
|
if (tag.Contains("ZDH_Parameter15"))
|
|
{
|
|
Console.WriteLine("UpwardBar = " + moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter16"))
|
|
{
|
|
Console.WriteLine("DropBar =" + moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter17"))
|
|
{
|
|
Console.WriteLine("SetFrictionBar =" + moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter18"))
|
|
{
|
|
Console.WriteLine("ActualFrictionBar =" + moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter19"))
|
|
{
|
|
Console.WriteLine("SetWeldingBar =" + moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter20"))
|
|
{
|
|
Console.WriteLine("ActualWeldingBar =" + moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter21"))
|
|
{
|
|
Console.WriteLine("SetCoolingBar =" + moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter22"))
|
|
{
|
|
Console.WriteLine("ActualCoolingBar =" + moldnumber.ToString());
|
|
}
|
|
|
|
|
|
|
|
//闫永刚 2016:4:7 获取模具号
|
|
if (tag.Contains("ZDH_Parameter57"))
|
|
{
|
|
Console.WriteLine("MoldNumber =" + moldnumber.ToString());
|
|
}
|
|
if (tag.Contains("ZDH_Parameter58"))
|
|
{
|
|
Console.WriteLine("ColorValue =" + Convert.ToInt32(moldnumber));
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|