using System ;
using System.Collections.Generic ;
using System.Text ;
using Opc.Ua ;
using Opc.Ua.Client ;
using System.Threading ;
using System.Data ;
using DBFactory ;
using CommonLib ;
using Siemens.OpcUA ;
namespace OPCClient
{
public static class CCommonOPCClient
{
private static ushort S7NameSpace = 2 ; //20151120��Ĭ��ֵ��32λϵͳ��ֵ2��64λϵͳ��ֵ��3
private static Model . MDevice devinfo ;
private static Object thisLock = new Object ( ) ;
public static event CUpdateDBEventHandler UpdateDB ;
public static void OnUpdateDB ( object sender , CUpdateDBChangeEventArgs e )
{
if ( UpdateDB ! = null )
{
UpdateDB ( sender , e ) ;
}
}
public static DBOperator dbo = CommonClassLib . AppSettings . dbo ; //20130510
//20110726
private static Dictionary < string , int > _ connectCount = new Dictionary < string , int > ( ) ;
//20110726
public static Dictionary < string , int > ConnectCount
{
get { return CCommonOPCClient . _ connectCount ; }
set { CCommonOPCClient . _ connectCount = value ; }
}
private static int [ ] _ plcStates = null ;
public static int [ ] PlcStates
{
get { return CCommonOPCClient . _ plcStates ; }
//set { CCommonOPCClient._plcStates = value; }
}
private static Server m_Server = null ;
private static Siemens . OpcUA . Subscription m_Subscription ;
/// <summary>
/// 20110309���ĵ����ڱ�ǩ���ݱ仯�¼�
/// </summary>
/// <param name="subscriptionHandle">�ͻ��˾���</param>
/// <param name="requestHandle">��������</param>
/// <param name="values">��ǩֵ����</param>
public static void OnDataChange ( object clientHandle , DataValue value )
{
lock ( thisLock )
{
//����subscriptionHandle��Ӧ�豸�����������豸���ࣨ��ͬ�����豸ͨѶ����֡��ͬ��
//�ֱ����������ɣ����������翪�أ�PLC����������
int deviceindex = 0 ;
try
{
if ( clientHandle . ToString ( ) . IndexOf ( "split" ) > = 0 )
{
deviceindex = System . Convert . ToInt32 ( clientHandle . ToString ( ) . Substring ( 5 ) ) ;
}
else
{
deviceindex = System . Convert . ToInt32 ( clientHandle ) ;
}
devinfo = Model . CGetInfo . GetDeviceInfo ( deviceindex ) ;
if ( ! StatusCode . IsGood ( value . StatusCode ) )
{
if ( devinfo = = null )
{
OpcError = string . Format ( "�豸����{0}�����ݿⲻ���ڣ�" , clientHandle ) ;
return ;
}
//if (value.StatusCode.ToString() == "BadNoCommunication")
//{
// CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");//20090922 devinfo.RemoteIP;
// CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
// CCommonOPCClient.PlcConnectionID = devinfo.S7Connection;//20110216
// StringBuilder[] itemnames = new StringBuilder[1] { new StringBuilder("") };
// itemnames[0].Append(Model.CGeneralFunction.DBGet).Append(".").Append(Convert.ToString(devinfo.Dbw2Address)).Append(",b");
// DataValueCollection dvc= SyncReadAllItemValue(itemnames);
// if (dvc.Count > 0)
// {
// value = dvc[0];
// }
// OpcError = string.Format("{0}���ڵ�PLC�Ѿ����ߣ��Զ����¶�ȡ���ݣ����ı�ǩ״̬��" + value.StatusCode.ToString(), clientHandle);
// //return;
//}
//����һ�������¼���ʾPLC�Ͽ�����
if ( ConnectCount . ContainsKey ( devinfo . S7Connection ) = = false ) //20110726
{
ConnectCount . Add ( devinfo . S7Connection , 0 ) ;
}
OpcError = string . Format ( "{0}���ڵ�PLC�Ѿ����ߣ����ı�ǩ״̬��" + value . StatusCode . ToString ( ) , clientHandle ) ;
if ( ConnectCount [ devinfo . S7Connection ] > 3 ) //20150204
{
_ opcError = "���ķ�������ʱ��OPC Serverû���ӵ�PLC:" + devinfo . S7Connection . ToString ( ) + "���˹�ȷ�Ϻ����С�PLC��ʼ����" ; //20150204
return ;
}
ConnectCount [ devinfo . S7Connection ] + + ; //20150204
return ;
}
ConnectCount [ devinfo . S7Connection ] = 0 ;
if ( clientHandle . ToString ( ) . IndexOf ( "split" ) > = 0 )
{
Array arr = ( Array ) value . Value ;
byte [ ] GDKG = null ;
GDKG = new byte [ arr . GetLength ( 0 ) ] ;
Array . Copy ( arr , GDKG , arr . GetLength ( 0 ) ) ;
CUpdateDBChangeEventArgs udbe = new CUpdateDBChangeEventArgs ( deviceindex , GDKG , null ) ;
OnUpdateDB ( "OPCClient.CCommonOPCClient.OnDataChange" , udbe ) ;
}
else
{
Array arr = ( Array ) value . Value ;
byte [ ] itemnamevalue = new byte [ arr . GetLength ( 0 ) ] ;
Array . Copy ( arr , itemnamevalue , arr . GetLength ( 0 ) ) ;
int head = 0 ;
head = itemnamevalue [ 0 ] ; //��д��־
CUpdateDBChangeEventArgs udbe = new CUpdateDBChangeEventArgs ( deviceindex , null , itemnamevalue ) ;
OnUpdateDB ( "OPCClient.CCommonOPCClient.OnDataChange" , udbe ) ;
}
}
catch ( Exception ex )
{ //20120420
OpcError = string . Format ( "OPC�����������¼��쳣��{0},{1}" , ex . Message , ex . StackTrace ) ;
}
}
}
static private string _ PLCconnectionID = "S7 connection_1" ; //OPC.UA����д��"ns=2,S7 connection_1.db2.0,b,5"��ʾ��"S7:[S7 connection_1]��db2.DBB0��ʼ5���ֽ�"
/// <summary>
/// ����PLC���ӵ�ID�����磺"S7:[S7 connection_1]"
/// ����"S7:[@LOCALSERVER]"
/// </summary>
public static string PlcConnectionID
{
get { return CCommonOPCClient . _ PLCconnectionID ; }
set { CCommonOPCClient . _ PLCconnectionID = value ; }
}
static private string _ opcError ;
static private bool _ IfConnectOPCServer = false ;
static private string _ hostname ;
/// <summary>
/// OPC Server�Ļ������ƻ���IP��ַ
/// </summary>
public static string Hostname
{
get { return CCommonOPCClient . _ hostname ; }
set { CCommonOPCClient . _ hostname = value ; }
}
static private string _ progID ;
/// <summary>
/// OPC Server�ij�����ʶ�����磺OPC.SimaticNET
/// </summary>
public static string ProgID
{
get { return CCommonOPCClient . _ progID ; }
set { CCommonOPCClient . _ progID = value ; }
}
public static string OpcError
{
get { return CCommonOPCClient . _ opcError ; }
set {
CCommonOPCClient . _ opcError = value ;
CUpdateDBChangeEventArgs udbe = new CUpdateDBChangeEventArgs ( 0 , null , null ) ;
OnUpdateDB ( "OPCClient.CCommonOPCClient.OnDataChange" , udbe ) ;
}
}
/// <summary>
/// ���豸��������Ӧ�豸���ġ�
/// </summary>
public static SubscriptionCollection SubscriptionGroup = new SubscriptionCollection ( ) ; //���������ϣ��������ϣ�//20110309
/// <summary>
/// 20110309ÿ���豸����һ�����ĺ�DataChange�¼�
/// </summary>
public static void CreateSubscriptionGroup ( )
{
if ( _ IfConnectOPCServer = = false )
{
_ hostname = CommonClassLib . AppSettings . GetValue ( "HostName" ) ;
_ progID = CommonClassLib . AppSettings . GetValue ( "OPCProgID" ) ;
if ( ConnectOPCServer ( _ hostname , _ progID ) = = false ) return ;
}
DataView dv = dbo . ExceSQL ( "SELECT F_ReadSubscription, F_DeviceIndex, F_DBW2Address, F_DBWGetLength, F_S7Connection, F_SplitByte FROM T_Base_Device WHERE (F_ReadSubscription IS NOT NULL) AND (F_ReadSubscription =F_DeviceIndex) ORDER BY F_ReadSubscription" ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
if ( dv . Count < SubscriptionGroup . Count ) return ;
}
DataView dvx ;
for ( int i = 0 ; i < dv . Count ; i + + )
{
string dt = DateTime . Now . Minute . ToString ( ) + "-" + DateTime . Now . Second . ToString ( ) + "-" + DateTime . Now . Millisecond . ToString ( ) ;
dvx = dbo . ExceSQL ( string . Format ( "SELECT (MAX(F_DBW2Address) + F_DBWGetLength) as maxdbw2 FROM T_Base_Device WHERE (F_ReadSubscription = {0}) AND (F_DeviceKindIndex <> 33) GROUP BY F_DBWGetLength ORDER BY maxdbw2 DESC" , dv [ i ] [ "F_ReadSubscription" ] ) ) . Tables [ 0 ] . DefaultView ;
int aa = Convert . ToInt32 ( dv [ i ] [ "F_ReadSubscription" ] ) ;
string kk = string . Format ( "SELECT (MAX(F_DBW2Address) + F_DBWGetLength) as maxdbw2 FROM T_Base_Device WHERE (F_ReadSubscription = {0}) AND (F_DeviceKindIndex <> 33) GROUP BY F_DBWGetLength ORDER BY maxdbw2 DESC" , dv [ i ] [ "F_ReadSubscription" ] ) ;
if ( dvx . Count > 0 )
{
NodeId nodeId = new NodeId ( dv [ i ] [ "F_S7Connection" ] . ToString ( ) + "." +
Model . CGeneralFunction . DBGet + "." +
dv [ i ] [ "F_DBW2Address" ] . ToString ( ) + ",b," +
( System . Convert . ToInt32 ( System . Convert . ToInt32 ( dvx [ 0 ] [ "maxdbw2" ] ) - System . Convert . ToInt32 ( dv [ i ] [ "F_DBW2Address" ] ) ) ) . ToString ( ) , S7NameSpace ) ; //20151120
// Add the attribute name/value to the list view.
object serverHandle = null ;
try
{
// Add the item and apply any changes to it.
m_Subscription . AddDataMonitoredItem ( nodeId , dv [ i ] [ "F_ReadSubscription" ] . ToString ( ) , OnDataChange , 1 0 0 , out serverHandle ) ;
}
catch ( ServiceResultException monitoredItemResult )
{
OpcError = "����OPC������ʱ��" + monitoredItemResult . Message ;
}
}
}
dv = dbo . ExceSQL ( "SELECT F_ReadSubscription, F_DeviceIndex, F_DBW2Address, F_DBWGetLength, F_S7Connection, F_SplitByte FROM T_Base_Device WHERE (F_ReadSubscription IS NOT NULL) AND (F_DeviceKindIndex=33) ORDER BY F_ReadSubscription" ) . Tables [ 0 ] . DefaultView ;
for ( int i = 0 ; i < dv . Count ; i + + )
{
NodeId nodeId = new NodeId ( dv [ i ] [ "F_S7Connection" ] . ToString ( ) + "." +
Model . CGeneralFunction . DBGet + "." +
dv [ i ] [ "F_DBW2Address" ] . ToString ( ) + ",b," + System . Convert . ToInt32 ( dv [ i ] [ "F_DBWGetLength" ] ) . ToString ( ) , S7NameSpace ) ; //20151120
// Add the attribute name/value to the list view.
object serverHandle = null ;
try
{
// Add the item and apply any changes to it.
m_Subscription . AddDataMonitoredItem ( nodeId , "split" + dv [ i ] [ "F_ReadSubscription" ] . ToString ( ) , OnDataChange , 1 0 0 , out serverHandle ) ;
}
catch ( ServiceResultException monitoredItemResult )
{
OpcError = "����OPC������ʱ��" + monitoredItemResult . Message ;
}
}
}
/// <summary>
/// ͨ�����ö��ĵļ���ģʽ��ˢ�¶���
/// </summary>
/// <returns></returns>
public static bool RefreshMonitoringMode ( )
{ //20150103���Ӷ����ָ�
if ( m_Subscription ! = null )
{
m_Subscription . RefreshMonitoringMode ( ) ;
}
return true ;
}
/// <summary>
/// ����ָ��������OPC������
/// </summary>
/// <param name="hostname">��������</param>
/// <param name="ProgID">OPC������������ʶ���磺"OPC.SimaticNET"</param>
/// <returns></returns>
public static bool ConnectOPCServer ( string hostname , string ProgID )
{
try
{
Uri discoveryUrl = new Uri ( "opc.tcp://" + hostname + ":55101" ) ;
Discovery discovery = new Discovery ( ) ;
EndpointDescriptionCollection endpoints = null ;
string rr = discovery . GetEndpoints ( discoveryUrl , ref endpoints ) ;
for ( int i = 0 ; i < endpoints . Count ; i + + )
{
if ( ( endpoints [ i ] . Server . ApplicationName . Text . IndexOf ( ProgID ) > - 1 )
& & ( endpoints [ i ] . SecurityMode = = MessageSecurityMode . None ) ) //20151120
{
m_Server = new Server ( ) ;
m_Server . CertificateEvent + = new certificateValidation ( m_Server_CertificateEvent ) ;
m_Server . Connect ( endpoints [ i ] ) ;
_ IfConnectOPCServer = true ;
if ( m_Subscription = = null )
{
m_Subscription = m_Server . AddSubscription ( 1 0 0 ) ;
}
#region �Զ���ȡ��S7:���������ռ�����//20151120
DataValueCollection m_currentValues ;
NodeId nodeId = new NodeId ( 2 2 5 5 ) ;
NodeIdCollection nodesToRead = new NodeIdCollection ( 1 ) ;
nodesToRead . Add ( nodeId ) ;
m_Server . ReadValues ( nodesToRead , out m_currentValues ) ;
if ( m_currentValues . Count > 0 )
{
string [ ] arr ;
arr = ( string [ ] ) m_currentValues [ 0 ] . Value ;
S7NameSpace = ( ushort ) Array . IndexOf ( arr , "S7:" ) ;
}
#endregion
return true ;
}
}
OpcError = "����OPC���ݴ�ȡ������ʱ��������OPCProgID��HostName��ȷ��" ;
_ IfConnectOPCServer = false ;
return false ;
}
catch ( Exception ex )
{
OpcError = "����OPC���ݴ�ȡ������ʱ��" + ex . Message ;
_ IfConnectOPCServer = false ;
return false ;
}
}
public static DataValueCollection SyncReadAllItemValue ( StringBuilder [ ] itemnames )
{
DataValueCollection m_currentValues ;
if ( _ IfConnectOPCServer = = false )
{
if ( ConnectOPCServer ( _ hostname , _ progID ) = = false ) return null ;
}
if ( ConnectCount . ContainsKey ( _ PLCconnectionID ) = = false ) //20110726
{
ConnectCount . Add ( _ PLCconnectionID , 0 ) ;
}
if ( ConnectCount [ _ PLCconnectionID ] > 3 ) //20150204
{
_ opcError = "������ʱ��OPC Serverû���ӵ�PLC:" + _ PLCconnectionID . ToString ( ) + "���˹�ȷ�Ϻ����С�PLC��ʼ����" ; //20150204
return null ;
}
NodeIdCollection nodesToRead = new NodeIdCollection ( itemnames . GetLength ( 0 ) ) ;
foreach ( StringBuilder item in itemnames )
{
// NodeIds.
String sNodeId = _ PLCconnectionID + "." + item . ToString ( ) ;
NodeId nodeId = new NodeId ( sNodeId , S7NameSpace ) ; //20151120
nodesToRead . Add ( nodeId ) ;
}
// Call to ClientAPI.
m_Server . ReadValues (
nodesToRead ,
out m_currentValues ) ;
return m_currentValues ;
}
public static bool SyncWriteAllItemValue ( StringBuilder [ ] itemnames , StringBuilder [ ] itemvalues )
{
try
{
if ( _ IfConnectOPCServer = = false )
{
if ( ConnectOPCServer ( _ hostname , _ progID ) = = false ) return false ;
}
if ( ConnectCount . ContainsKey ( _ PLCconnectionID ) = = false ) //20110726
{
ConnectCount . Add ( _ PLCconnectionID , 0 ) ;
}
if ( ConnectCount [ _ PLCconnectionID ] > 3 ) //20150204
{
_ opcError = "д����ʱ��OPC Serverû���ӵ�PLC:" + _ PLCconnectionID . ToString ( ) + "���˹�ȷ�Ϻ����С�PLC��ʼ����" ; //20150204
return false ;
}
NodeIdCollection nodesToWrite = new NodeIdCollection ( itemnames . GetLength ( 0 ) ) ;
DataValueCollection values = new DataValueCollection ( itemnames . GetLength ( 0 ) ) ;
StatusCodeCollection results = null ;
int i = 0 ;
foreach ( StringBuilder item in itemnames )
{
// Values to write.
String sValue = itemvalues [ i ] . ToString ( ) ;
// Leave current value if write value is empty.
if ( sValue . Length = = 0 )
{
i + + ;
continue ;
}
#region win7��64λ����ϵͳ��Ҫָ��ȷ�е���������//20151120
Type gt = typeof ( byte ) ;
if ( item . ToString ( ) . IndexOf ( ",b" ) > = 0 ) //�����ֽ���0--255
{
gt = typeof ( byte ) ;
}
else if ( item . ToString ( ) . IndexOf ( ",i" ) > = 0 ) //short���з��������ֽڵĵ���-32768��32767
{
gt = typeof ( short ) ;
}
else if ( item . ToString ( ) . IndexOf ( ",w" ) > = 0 ) //ushort�����������ֽڵĵ���0��65535
{
gt = typeof ( ushort ) ;
}
else if ( item . ToString ( ) . IndexOf ( ",di" ) > = 0 ) //int���з����ĸ��ֽڵ�˫��-2147483648��2147483647
{
gt = typeof ( int ) ;
}
else if ( item . ToString ( ) . IndexOf ( ",dw" ) > = 0 ) //uint�������ĸ��ֽڵ�˫��0��4294967295
{
gt = typeof ( uint ) ;
}
Variant variant = new Variant ( Convert . ChangeType ( sValue , gt ) ) ;
#endregion
DataValue value = new DataValue ( variant ) ;
values . Add ( value ) ;
// NodeIds.
String sNodeId = _ PLCconnectionID + "." + item . ToString ( ) ;
NodeId nodeId = new NodeId ( sNodeId , S7NameSpace ) ; //20151120
nodesToWrite . Add ( nodeId ) ;
i + + ;
}
// Call to ClientAPI.
m_Server . WriteValues (
nodesToWrite ,
values ,
out results ) ;
int ia = 0 ; //richard.liu20141110
foreach ( StatusCode sc in results )
{ //richard.liu20141110
if ( sc . Code ! = StatusCodes . Good )
{
ConnectCount [ _ PLCconnectionID ] + + ; //20150204
OpcError = "��OPC���ݴ�ȡ������д����ʱ��WriteValues:" + nodesToWrite [ ia ] . ToString ( ) + "�ķ���ֵ�д�����" + sc . ToString ( ) ;
return false ;
}
ia + + ;
}
ConnectCount [ _ PLCconnectionID ] = 0 ; //20150204
return true ;
}
catch ( Exception ex )
{
ConnectCount [ _ PLCconnectionID ] + + ; //20150204
OpcError = "��OPC���ݴ�ȡ������д����ʱ��" + ex . Message ;
_ IfConnectOPCServer = false ;
return false ;
}
}
/// <summary>
/// �����豸��������
/// </summary>
/// <param name="devIdx">�豸����</param>
/// <returns>�豸��������</returns>
static int GetDeviceKindIdx ( int devIdx )
{
System . Object lockThis = new System . Object ( ) ;
lock ( lockThis )
{
try
{
DataView dv = dbo . ExceSQL ( string . Format ( "SELECT F_DeviceKindIndex FROM T_Base_Device WHERE F_DeviceIndex={0}" , devIdx ) ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
return System . Convert . ToInt32 ( dv [ 0 ] [ "F_DeviceKindIndex" ] ) ;
}
else
return 0 ;
}
catch ( Exception ex )
{
throw ex ;
}
}
}
public static void DisConnectOPCServer ( )
{
try
{
int result ;
if ( m_Server = = null ) return ;
result = m_Server . Disconnect ( ) ;
// Disconnect succeeded.
if ( result = = 0 )
{
m_Subscription . RemoveAllMonitoredItems ( ) ; //20150103���Ӷ����ָ�
m_Server . RemoveSubscription ( m_Subscription ) ;
m_Subscription = null ;
}
_ IfConnectOPCServer = false ; //20140514�Ų���ɽ���������ִ�����
}
catch ( Exception ex )
{
OpcError = "�ر�OPC���ݴ�ȡ������ʱ��" + ex . Message ;
}
}
static void m_Server_CertificateEvent ( CertificateValidator validator , CertificateValidationEventArgs e )
{
e . Accept = true ;
}
public static bool AWriteAllItemValue ( StringBuilder [ ] itemnames , StringBuilder [ ] itemvalues )
{
try
{
if ( _ IfConnectOPCServer = = false )
{
if ( ConnectOPCServer ( _ hostname , _ progID ) = = false ) return false ;
}
if ( ConnectCount . ContainsKey ( _ PLCconnectionID ) = = false ) //20110726
{
ConnectCount . Add ( _ PLCconnectionID , 0 ) ;
}
if ( ConnectCount [ _ PLCconnectionID ] > 3 ) //20150204
{
_ opcError = "д����ʱ��OPC Serverû���ӵ�PLC:" + _ PLCconnectionID . ToString ( ) + "���˹�ȷ�Ϻ����С�PLC��ʼ����" ; //20150204
return false ;
}
NodeIdCollection nodesToWrite = new NodeIdCollection ( itemnames . GetLength ( 0 ) ) ;
DataValueCollection values = new DataValueCollection ( itemnames . GetLength ( 0 ) ) ;
StatusCodeCollection results = null ;
int i = 0 ;
foreach ( StringBuilder item in itemnames )
{
// Values to write.
String sValue = itemvalues [ i ] . ToString ( ) ;
// Leave current value if write value is empty.
if ( sValue . Length = = 0 )
{
i + + ;
continue ;
}
#region win7��64λ����ϵͳ��Ҫָ��ȷ�е���������//20151120
Type gt = typeof ( byte ) ;
if ( item . ToString ( ) . IndexOf ( ",b" ) > = 0 ) //�����ֽ���0--255
{
gt = typeof ( byte ) ;
}
else if ( item . ToString ( ) . IndexOf ( ",i" ) > = 0 ) //short���з��������ֽڵĵ���-32768��32767
{
gt = typeof ( short ) ;
}
else if ( item . ToString ( ) . IndexOf ( ",w" ) > = 0 ) //ushort�����������ֽڵĵ���0��65535
{
gt = typeof ( ushort ) ;
}
else if ( item . ToString ( ) . IndexOf ( ",di" ) > = 0 ) //int���з����ĸ��ֽڵ�˫��-2147483648��2147483647
{
gt = typeof ( int ) ;
}
else if ( item . ToString ( ) . IndexOf ( ",dw" ) > = 0 ) //uint�������ĸ��ֽڵ�˫��0��4294967295
{
gt = typeof ( uint ) ;
}
Variant variant = new Variant ( Convert . ChangeType ( sValue , gt ) ) ;
#endregion
DataValue value = new DataValue ( variant ) ;
values . Add ( value ) ;
// NodeIds.
String sNodeId = _ PLCconnectionID + "." + item . ToString ( ) ;
NodeId nodeId = new NodeId ( sNodeId , S7NameSpace ) ; //20151120
nodesToWrite . Add ( nodeId ) ;
i + + ;
}
// Call to ClientAPI.
m_Server . BeginWriteValues (
nodesToWrite ,
values ,
out results ) ;
//int ia = 0;//richard.liu20141110
////foreach (StatusCode sc in results)
////{//richard.liu20141110
//// if (sc.Code != StatusCodes.Good)
//// {
//// ConnectCount[_PLCconnectionID]++;//20150204
//// OpcError = "��OPC���ݴ�ȡ������д����ʱ��WriteValues:" + nodesToWrite[ia].ToString() + "�ķ���ֵ�д�����" + sc.ToString();
//// return false;
//// }
//// ia++;
////}
ConnectCount [ _ PLCconnectionID ] = 0 ; //20150204
return true ;
}
catch ( Exception ex )
{
ConnectCount [ _ PLCconnectionID ] + + ; //20150204
OpcError = "��OPC���ݴ�ȡ������д����ʱ��" + ex . Message ;
_ IfConnectOPCServer = false ;
return false ;
}
}
}
}