Oracle DB changes from iPerl-12 branch, WMType_ID/Rev dropped from WaterMeter, CheckBarcodeScanning operation commented out.

This commit is contained in:
Milan Hanajik 2017-11-10 10:32:43 +01:00
parent 656bd36a1d
commit 607dbaacb1
5 changed files with 142 additions and 42 deletions

View File

@ -27,10 +27,23 @@ namespace TBF.BenchControl.DB.SensusOracle
private static readonly ILog log = LogManager.GetLogger(typeof(Database));
public override string ToString() { return string.Format("Sensus-Oracle-Database({0})", Cfg.ToString(1)); }
const int Anbid_StaraTura = 4;
enum CurrentOp
{
None,
CheckBarcodeScanning,
WriteResults,
}
CurrentOp currentOp;
bool opCompleted;
bool anyError;
///
/// iPerls to verify
///
GenericDevices.IRegisterReader[] iperlHeads;
public static DatabaseCfg DBCfg;
string separatorStr;
/// <summary>
/// Result items to print
@ -47,6 +60,12 @@ namespace TBF.BenchControl.DB.SensusOracle
StreamWriter logger; /// Logs specified by LU
const int Anbid_StaraTura = 4;
public static DatabaseCfg DBCfg;
string separatorStr;
///
/// Information extracted from VT_PRUEFPUNKT_SOLL_SD for a given watermeter by query:
/// SELECT * FROM VT_PRUEFPUNKT_SOLL_SD WHERE ANBID=4 AND ID_WZTyp=x AND Rev_WZTyp=y
@ -73,6 +92,8 @@ namespace TBF.BenchControl.DB.SensusOracle
{
DBCfg = cfg as DatabaseCfg;
currentOp = CurrentOp.None;
switch (DBCfg.Separator)
{
default:
@ -211,6 +232,7 @@ namespace TBF.BenchControl.DB.SensusOracle
return string.Format("{0}{1}_{2}.log", directory, time.Hour.ToString("D2"), time.Minute.ToString("D2"));
}
/// <summary>
/// Writes the test cycle results into a file, Events: Event.ResultsWritten
/// </summary>
@ -219,7 +241,12 @@ namespace TBF.BenchControl.DB.SensusOracle
/// <returns>Reference to the operation</returns>
public IOperation WriteResultsOp(Results.Entities.Batch batch)
{
this.batch = batch;
if (currentOp != CurrentOp.None)
throw new Exception("Sequence error");
else
currentOp = CurrentOp.WriteResults;
this.batch = batch;
string fname = GetLogFileName(batch.StartTime);
@ -233,43 +260,81 @@ namespace TBF.BenchControl.DB.SensusOracle
log.ErrorFormat("Was not able to open LU log file {0}", fname);
}
return this;
return this;
}
public IOperation CheckBarcodeScanningOp(GenericDevices.IRegisterReader[] iperlHeads)
{
if (currentOp != CurrentOp.None)
throw new Exception("Sequence error");
else
currentOp = CurrentOp.CheckBarcodeScanning;
this.iperlHeads = iperlHeads;
return this;
}
/// <summary>Start this operation</summary>
public void Start()
{
}
opCompleted = false;
anyError = false;
}
/// <summary>Run this operation</summary>
/// <returns>Event.ResultsWritten or Event.Error</returns>
public Event Run()
{
if (batch.WaterMeters.Count == 0) return Event.ResultsWritten;
bool anyError = false;
if (currentOp == CurrentOp.WriteResults)
{
if (!opCompleted)
{
if (batch.WaterMeters.Count == 0) return Event.ResultsWritten;
#if ORACLE_DB
if (DBCfg.DebugLevel != DebugMode.Simulate && connection != null)
{
if (WriteResultsToDatabase(connection, batch, false) == Retv.Error) anyError = true;
}
if (DBCfg.DebugLevel != DebugMode.Simulate && connection != null)
{
if (WriteResultsToDatabase(connection, batch, false) == Retv.Error) anyError = true;
}
#endif
WriteLogsToDisk(logger, batch);
WriteLogsToDisk(logger, batch);
if (anyError)
{
return Event.ResultsNotWritten;
}
else
{
return Event.ResultsWritten;
}
opCompleted = true;
}
if (anyError)
return Event.ResultsNotWritten;
else
return Event.ResultsWritten;
}
else if (currentOp == CurrentOp.CheckBarcodeScanning)
{
if (!opCompleted)
{
#if ORACLE_DB
if (DBCfg.DebugLevel != DebugMode.Simulate && connection != null)
{
if (CheckBarcodeScanning(connection, iperlHeads) == Retv.Error) anyError = true; ;
}
#endif
opCompleted = true;
}
if (anyError)
return Event.CheckNotDone;
else
return Event.CheckDone;
}
else
{
return Event.None;
}
}
/// <summary>Stop this operation</summary>
public void Stop()
{
currentOp = CurrentOp.None;
}
@ -665,9 +730,50 @@ namespace TBF.BenchControl.DB.SensusOracle
}
#if ORACLE_DB
public static Retv WriteResultsToDatabase(OracleConnection conn, Results.Entities.Batch batch, bool safeMode)
public static Retv CheckBarcodeScanning(OracleConnection conn, GenericDevices.IRegisterReader[] iPerlHeads)
{
try
{
conn.Open(); /// Open the Oracle database
foreach (var rr in iPerlHeads)
{
//WaterMeters.iPerl.WaterMeter iPerlHead = rr as WaterMeters.iPerl.WaterMeter;
//if (iPerlHead != null)
//{
// OracleCommand cmd = new OracleCommand("select * from IP_ENDTEST_PD where PCBNUMBER = :1 and TESTSTATIONNAME = :2", conn);
// OracleParameter param;
// param = new OracleParameter("PCBNUMBER", OracleDbType.Varchar2); param.Value = iPerlHead.SerialNr; cmd.Parameters.Add(param);
// param = new OracleParameter("TESTSTATIONNAME", OracleDbType.Varchar2); param.Value = "STAWL001"; cmd.Parameters.Add(param);
// bool exists = false; /// true = RF_Power record exists
// OracleDataReader dr1 = cmd.ExecuteReader();
// if (dr1.Read()) { exists = true; }
// dr1.Close();
// if (!exists)
// {
// iPerlHead.CommFailed = true;
// }
//}
}
}
catch (Exception exc)
{
log.ErrorFormat("Barcode scanning records were not checked: {1}", exc.Message);
conn.Close();
return Retv.Error;
}
conn.Close();
return Retv.OK;
}
public static Retv WriteResultsToDatabase(OracleConnection conn, Results.Entities.Batch batch, bool safeMode)
{
OracleTransaction transaction = null;

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2013-2015 Sensus Metering Systems
/// Copyright (c) 2013-2017 Sensus Metering Systems
///
namespace TBF.BenchControl
{
@ -159,7 +159,7 @@ namespace TBF.BenchControl
/// Timer events
TimerExpired,
/// IDC camera events
/// Process camera events
CameraBusy,
GrabPassed,
GrabFailed,
@ -188,6 +188,12 @@ namespace TBF.BenchControl
OuterLoopStart,
OuterLoopNext,
OuterLoopEnd,
/// Production monitoring
CheckDone,
CheckNotDone,
/// Error evaluation
ErrorConditionsDone,
}
}

View File

@ -1336,15 +1336,6 @@ namespace TBF.BenchControl.Sequences
waterMeterData[wmNr].MetrologicalClassAux = WaterMeters[auxIx].MetrologicalClass;
waterMeterData[wmNr].ApprovalInfoAux = WaterMeters[auxIx].ApprovalInfo;
}
#if ORACLE_DB
BenchControl.WaterMeters.WaterMeter.WaterMeter iPerl = WaterMeters[wmNr] as BenchControl.WaterMeters.WaterMeter.WaterMeter;
if (iPerl != null)
{
waterMeterData[wmNr].WMTypeId = iPerl.WMType_ID;
waterMeterData[wmNr].WMTypeRev = iPerl.WMType_Rev;
}
#endif
}
/// Prepare empty results

View File

@ -1840,7 +1840,9 @@ namespace TBF.BenchControl.TestMethods.iPerlCommunication
if (meterRslt != null && iperlHeads[i] != null)
{
meterRslt.WaterMeter.SerialNr = iperlHeads[i].SerialNr;
meterRslt.Passed = (!iperlHeads[i].CommFailed && !iperlHeads[i].Disabled);
meterRslt.WaterMeter.WaterMeterData.WMTypeId = iperlHeads[i].WMType_ID;
meterRslt.WaterMeter.WaterMeterData.WMTypeRev = iperlHeads[i].WMType_Rev;
meterRslt.Passed = (!iperlHeads[i].CommFailed && !iperlHeads[i].Disabled);
meterRslt.TestDone = true;
}
}

View File

@ -70,11 +70,6 @@ namespace TBF.BenchControl.WaterMeters.WaterMeter
public string FWVersion;
#endif
#if ORACLE_DB
public int WMType_ID; /// Required by Oracle DB
public int WMType_Rev; /// Required by Oracle DB
#endif
/// Properties set by the Begin and the End form or the iPerl head
public string SerialNr
{