private static void TestCreateSchema() { var status = new UnitStatus() { Ok = 134, CasOk = 5454, CilKusuTabule = 1000, AktualDefectTabule = 0 }; SqlliteDao.OpenConnection(true); SqlliteDao.AddUnitState(100, status); status.Ok = 135; status.CasOk = 5455; SqlliteDao.AddUnitState(100, status); SqlliteDao.CloseConnection(); }
/// <summary> /// Získá status jednoty načtením stavu čítačů a výpočtem parametrů zobrazovaných na tabuli /// </summary> /// <param name="addr"></param> /// <returns></returns> public static UnitStatus ObtainStatus(byte addr) { Logger.Info($"+ *** unit {addr}"); if (_runConfig.IsMockupMode) { return(_unitDictionary[addr].UnitStatus); } int ok, ng; Single casOk = -1, casNg = -1; var res = _unitDictionary[addr].ReadStavCitacu(out ok, out ng); var s = res ? "" : "err"; Logger.Info($">ok:{ok} ng:{ng} " + s); if (!res) { _ErrorRecordedCnt++; if (!_ErrorRecorded) { ErrorsLogger.Error($"ReadStavCitacu;{addr};total errors:{_ErrorRecordedCnt}"); _ErrorRecorded = true; } } else { if (_ErrorRecorded) { ErrorsLogger.Info($"ReadStavCitacu;{addr};recovered"); _ErrorRecorded = false; } } if (res && _runConfig.IsReadOkNgTime) { _unitDictionary[addr].ReadCasOK(out casOk); Logger.Info($">casOk:{casOk}"); _unitDictionary[addr].ReadCasNG(out casNg); Logger.Info($">casNg:{casNg}"); } if (res) { //prepocitat pro zobrazeni tabule try { _unitDictionary[addr].RecalcTabule(); _unitDictionary[addr].UnitStatus.LastCheckTime = DateTime.Now; string casOkStr = (_runConfig.IsReadOkNgTime) ? casOk.ToString(CultureInfo.InvariantCulture) : string.Empty; string casNgStr = (_runConfig.IsReadOkNgTime) ? casNg.ToString(CultureInfo.InvariantCulture) : string.Empty; UnitsLogger.Info($"4;{addr};{ok};{ng};{casOkStr};{casNgStr};{(int)_unitDictionary[addr].UnitStatus.MachineStatus}"); StringBuilder sb = new StringBuilder(); sb.Append($"4;{_unitDictionary[addr].UnitConfig.UnitName};{addr}"); //az po 4 sb.Append($";{_unitDictionary[addr].UnitStatus.CilKusuTabule}"); //5 sb.Append($";{ok}"); //6 sb.Append(_runConfig.IsReadOkNgTime ? $";{_unitDictionary[addr].UnitStatus.CasOk}" : ";"); //7 sb.Append(ok != 0 ? $";{_unitDictionary[addr].UnitStatus.UbehlyCasSmenySec / (float)ok:F}" : ";"); sb.Append($";{_unitDictionary[addr].UnitStatus.CilDefectTabule:F}"); //9 sb.Append($";{ng}"); //10 sb.Append(_runConfig.IsReadOkNgTime ? $";{_unitDictionary[addr].UnitStatus.CasNg}" : ";"); //11 sb.Append(ng != 0 ? $";{_unitDictionary[addr].UnitStatus.UbehlyCasSmenySec / (float)ng:F}" : ";"); //12 sb.Append($";{_unitDictionary[addr].UnitStatus.RozdilTabuleTxt}"); //13 sb.Append($";{_unitDictionary[addr].UnitStatus.AktualDefectTabuleTxt}"); //14 sb.Append($";{_unitDictionary[addr].UnitStatus.MachineStatus}"); //15 sb.Append($";{Convert.ToInt32(_unitDictionary[addr].UnitStatus.IsPrestavkaTabule)}"); //16 Units2Logger.Info(sb.ToString); SqlliteDao.AddUnitState(addr, _unitDictionary[addr].UnitStatus); } catch (Exception ex) { Logger.Error(ex); } } else { if (_runConfig.IsWriteEmptyToLog) { UnitsLogger.Info($" 4;{addr};;;;;"); } } Logger.Info($"-"); return(_unitDictionary[addr].UnitStatus); }