|
@@ -13,7 +13,7 @@ namespace PLCTool.Common
|
|
{
|
|
{
|
|
private static string plcIp = ConfigurationManager.AppSettings["PLCIp"];
|
|
private static string plcIp = ConfigurationManager.AppSettings["PLCIp"];
|
|
private static string plcPort = ConfigurationManager.AppSettings["PLCPort"];
|
|
private static string plcPort = ConfigurationManager.AppSettings["PLCPort"];
|
|
- private EtherNetPLC ENT;//plc连接
|
|
|
|
|
|
+ private static EtherNetPLC ENT = new EtherNetPLC();
|
|
private static PLCCom instance;
|
|
private static PLCCom instance;
|
|
private static bool isConnect=false;
|
|
private static bool isConnect=false;
|
|
|
|
|
|
@@ -26,7 +26,7 @@ namespace PLCTool.Common
|
|
|
|
|
|
public static PLCCom GetInstance()
|
|
public static PLCCom GetInstance()
|
|
{
|
|
{
|
|
- if (instance == null||(!isConnect))
|
|
|
|
|
|
+ if ((!ENT.IsConnect))
|
|
{
|
|
{
|
|
instance = new PLCCom();
|
|
instance = new PLCCom();
|
|
}
|
|
}
|
|
@@ -43,7 +43,7 @@ namespace PLCTool.Common
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- ENT = new EtherNetPLC();
|
|
|
|
|
|
+
|
|
short re = ENT.Link(plcIp, short.Parse(plcPort), 500);
|
|
short re = ENT.Link(plcIp, short.Parse(plcPort), 500);
|
|
if (re == 0)
|
|
if (re == 0)
|
|
{
|
|
{
|
|
@@ -52,6 +52,7 @@ namespace PLCTool.Common
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
|
|
+
|
|
isConnect = false;
|
|
isConnect = false;
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|