Added lock for avoid connect resource contention
This commit is contained in:
@@ -69,6 +69,10 @@ namespace CMS_CORE_Library.S7Net
|
||||
/// Oggetto PLC da ri-utilizzare...
|
||||
/// </summary>
|
||||
protected Plc currPLC;
|
||||
/// <summary>
|
||||
/// Lock per connessione PLC
|
||||
/// </summary>
|
||||
private readonly object connectLock = new object();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -137,40 +141,42 @@ namespace CMS_CORE_Library.S7Net
|
||||
/// <returns></returns>
|
||||
public override CmsError NC_Connect()
|
||||
{
|
||||
// Try to get information
|
||||
try
|
||||
lock (connectLock)
|
||||
{
|
||||
// Check if Siemens Environment is started
|
||||
CmsError libraryError = CheckS7Ping();
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
|
||||
// Check connection
|
||||
currPLC = new Plc(tipoCpu, this.Ip, this.rack, this.slot);
|
||||
currPLC.Open();
|
||||
if (currPLC.IsConnected)
|
||||
Connected = true;
|
||||
|
||||
// FARE TODO FIXME
|
||||
// Setup the alarms (with DB bitmap) --> PlcMessages
|
||||
|
||||
if (this.EnableAlarms)
|
||||
// Try to get information
|
||||
try
|
||||
{
|
||||
// PlcMessages
|
||||
// Check if Siemens Environment is started
|
||||
CmsError libraryError = CheckS7Ping();
|
||||
if (libraryError.IsError())
|
||||
return libraryError;
|
||||
|
||||
// Check connection
|
||||
currPLC = new Plc(tipoCpu, this.Ip, this.rack, this.slot);
|
||||
currPLC.Open();
|
||||
if (currPLC.IsConnected)
|
||||
Connected = true;
|
||||
|
||||
// FARE TODO FIXME
|
||||
// Setup the alarms (with DB bitmap) --> PlcMessages
|
||||
|
||||
if (this.EnableAlarms)
|
||||
{
|
||||
// PlcMessages
|
||||
#if false
|
||||
SiemensAlarms = new Alarm[] { };
|
||||
SiemensAlmSvc = new AlarmSvc(ConvertToSTEPLanguage(SiemensLanguage).ThreeLetterISOLanguageName);
|
||||
SiemensAlmSvc.Subscribe(AlarmsChanged);
|
||||
Infrastructure.SubscribeLanguageChanged(NcLanguageChanged);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ManageException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ManageException(ex);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user