diff --git a/TBF/BenchControl/DataEntry/DataStream/EntryForm.cs b/TBF/BenchControl/DataEntry/DataStream/EntryForm.cs
index 734b3be93..c99fa7586 100644
--- a/TBF/BenchControl/DataEntry/DataStream/EntryForm.cs
+++ b/TBF/BenchControl/DataEntry/DataStream/EntryForm.cs
@@ -88,7 +88,8 @@ namespace TBF.BenchControl.DataEntry.DataStream
public IOperation ShowCycleBeginFormOp()
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
- currentOp = CurrentOp.ShowFormAtCycleBeginning;
+ mefImport.CloseAllConnections();
+ currentOp = CurrentOp.ShowFormAtCycleBeginning;
this.waterMeters = TBF.BenchControl.Sequences.ProcessData.BatchRslts.Batch.WaterMeters;
return this;
}
@@ -97,10 +98,9 @@ namespace TBF.BenchControl.DataEntry.DataStream
public IOperation ShowCycleEndFormOp()
{
if (currentOp != CurrentOp.None) throw new Exception("Sequence error");
- currentOp = CurrentOp.ShowFormAtCycleEnd;
- this.waterMeters = TBF.BenchControl.Sequences.ProcessData.BatchRslts.Batch.WaterMeters;
- return this;
- }
+ mefImport.CloseAllConnections();
+ return null;
+ }
/// Reference to the operation
public IOperation ShowTestStartFormOp(IRegReader[] regReaders)
diff --git a/TBF/BenchControl/RegisterReaders/DataStream/MefImport/MefImport.cs b/TBF/BenchControl/RegisterReaders/DataStream/MefImport/MefImport.cs
index c8bf102bf..4a80d9434 100644
--- a/TBF/BenchControl/RegisterReaders/DataStream/MefImport/MefImport.cs
+++ b/TBF/BenchControl/RegisterReaders/DataStream/MefImport/MefImport.cs
@@ -29,6 +29,13 @@ namespace TBF.BenchControl.RegisterReaders.DataStream.MefImport
public string CatalogDir { get { return myCfg.CatalogDir; } }
+ ///
+ /// Size of this array is DataStreamIFace.GetMetersCount()
+ /// 'true' in this array represents an open connection to the water meter with the same index
+ ///
+ bool[] isConnectedArray;
+
+
public MefImport() { }
public MefImport(Generic.IComponentCfg cfg)
@@ -46,6 +53,8 @@ namespace TBF.BenchControl.RegisterReaders.DataStream.MefImport
catalog.Catalogs.Add(new DirectoryCatalog(CatalogDir));
(new CompositionContainer(catalog)).ComposeParts(this);
+ isConnectedArray = new bool[DataStreamIFace.GetMetersCount()];
+
log.FatalFormat("{0} initialized: {1}", Name, this);
log.FatalFormat(" Meters count = {0}", DataStreamIFace.GetMetersCount());
log.FatalFormat(" Time unit = {0}", DataStreamIFace.GetTimeUnits().ToString());
@@ -62,5 +71,52 @@ namespace TBF.BenchControl.RegisterReaders.DataStream.MefImport
log.FatalFormat("{0} simulated: {1}", Name, this);
}
}
+
+
+ public bool IsConnected(int ix)
+ {
+ return (isConnectedArray != null && ix >= 0 && ix < isConnectedArray.Length) ? isConnectedArray[ix] : false;
+ }
+
+ ///
+ /// Wrapper for DataStreamIFace.OpenConnection() that updates bool[] isConnected array.
+ ///
+ /// 0-based water meter index
+ /// Connection parameters
+ /// Water meter ID (serial number)
+ /// true = Successfully connected
+ public bool OpenConnection(int ix, string connectionParameters, out string meterId)
+ {
+ if (isConnectedArray != null && ix >= 0 && ix < isConnectedArray.Length)
+ {
+ isConnectedArray[ix] = DataStreamIFace.OpenConnection(ix, connectionParameters, out meterId);
+ return isConnectedArray[ix];
+ }
+ else
+ {
+ meterId = string.Empty;
+ return false;
+ }
+ }
+
+ ///
+ /// Wrapper for DataStreamIFace.CloseConnection() called in a loop for all connected water meters
+ ///
+ public void CloseAllConnections()
+ {
+ if (isConnectedArray != null)
+ {
+ for (int ix = 0; ix < isConnectedArray.Length; ix++)
+ {
+ if (isConnectedArray[ix])
+ {
+ if (DataStreamIFace.CloseConnection(ix))
+ {
+ isConnectedArray[ix] = false; /// reset IsConnected flag
+ }
+ }
+ }
+ }
+ }
}
}