int GetLastId() { var sendResult = SendManager.Send(GkDatabase.RootDevice, 0, 6, 64); if (IsStopping) return -1; if (sendResult.HasError) { ConnectionChanged(false); return -1; } ConnectionChanged(true); var journalParser = new JournalParser(GkDatabase.RootDevice, sendResult.Bytes); return journalParser.JournalItem.GKJournalRecordNo.Value; }
JournalItem ReadJournal(int index) { if (IsStopping) return null; var data = BitConverter.GetBytes(index).ToList(); var sendResult = SendManager.Send(GkDatabase.RootDevice, 4, 7, 64, data); if (sendResult.HasError) { ConnectionChanged(false); return null; } if (sendResult.Bytes.Count == 64) { var journalParser = new JournalParser(GkDatabase.RootDevice, sendResult.Bytes); return journalParser.JournalItem; } return null; }
public static OperationResult<JournalItem> GKReadJournalItem(XDevice device, int no) { var data = BitConverter.GetBytes(no).ToList(); var sendResult = SendManager.Send(device, 4, 7, 64, data); if (sendResult.HasError) { return new OperationResult<JournalItem>("Ошибка связи с устройством"); } if (sendResult.Bytes.Count == 64) { var journalParser = new JournalParser(device, sendResult.Bytes); return new OperationResult<JournalItem>() { Result = journalParser.JournalItem }; } else { return new OperationResult<JournalItem>("Ошибка. Недостаточное количество байт в записи журнала"); } }
public static OperationResult<int> GKGetJournalItemsCount(XDevice device) { var sendResult = SendManager.Send(device, 0, 6, 64); if (sendResult.HasError) { return new OperationResult<int>("Ошибка связи с устройством"); } var journalParser = new JournalParser(device, sendResult.Bytes); var result = journalParser.JournalItem.GKJournalRecordNo.Value; return new OperationResult<int>() { Result = result }; }
JournalParser ReadJournal(int index) { LastUpdateTime = DateTime.Now; if (IsStopping) return null; var data = BitConverter.GetBytes(index).ToList(); var sendResult = SendManager.Send(GkDatabase.RootDevice, 4, 7, 64, data); if (sendResult.HasError) { ConnectionChanged(false); return null; } if (sendResult.Bytes.Count == 64) { var journalParser = new JournalParser(GkDatabase.RootDevice, sendResult.Bytes); #if !DEBUG if (journalParser.JournalItem.JournalObjectType == JournalObjectType.GKPim) return null; #endif return journalParser; } return null; }
public static OperationResult<int> GKGetJournalItemsCount(GKDevice device) { var sendResult = SendManager.Send(device, 0, 6, 64); if (sendResult.HasError) { return OperationResult<int>.FromError("Устройство недоступно"); } var journalParser = new JournalParser(device, sendResult.Bytes); return new OperationResult<int>(journalParser.GKJournalRecordNo); }
void ParseAdditionalStates(JournalParser journalParser) { var journalItem = journalParser.JournalItem; var description = EventDescriptionAttributeHelper.ToName(journalItem.JournalEventDescriptionType); var descriptor = GkDatabase.Descriptors.FirstOrDefault(x => x.GetDescriptorNo() == journalParser.GKObjectNo); if (descriptor != null && descriptor.GKBase is GKDevice) { var device = descriptor.GKBase as GKDevice; var deviceState = device.InternalState; if (journalItem.JournalEventNameType == JournalEventNameType.Неисправность) { if (!string.IsNullOrEmpty(description)) { AddAdditionalState(deviceState, description, XStateClass.Failure); } } if (journalItem.JournalEventNameType == JournalEventNameType.Неисправность_устранена) { if (string.IsNullOrEmpty(description)) { deviceState.AdditionalStates.RemoveAll(x => x.StateClass == XStateClass.Failure); } else { deviceState.AdditionalStates.RemoveAll(x => x.Name == description); if (description == "Обрыв АЛС 1-2") { deviceState.AdditionalStates.RemoveAll(x => x.Name == "Обрыв АЛС 1"); deviceState.AdditionalStates.RemoveAll(x => x.Name == "Обрыв АЛС 2"); } if (description == "Обрыв АЛС 3-4") { deviceState.AdditionalStates.RemoveAll(x => x.Name == "Обрыв АЛС 3"); deviceState.AdditionalStates.RemoveAll(x => x.Name == "Обрыв АЛС 4"); } if (description == "Обрыв АЛС 5-6") { deviceState.AdditionalStates.RemoveAll(x => x.Name == "Обрыв АЛС 5"); deviceState.AdditionalStates.RemoveAll(x => x.Name == "Обрыв АЛС 6"); } if (description == "Обрыв АЛС 7-8") { deviceState.AdditionalStates.RemoveAll(x => x.Name == "Обрыв АЛС 7"); deviceState.AdditionalStates.RemoveAll(x => x.Name == "Обрыв АЛС 8"); } } } if (journalItem.JournalEventNameType == JournalEventNameType.Информация) { switch (description) { case "Низкий уровень": deviceState.AdditionalStates.RemoveAll(x => x.Name == "Высокий уровень"); deviceState.AdditionalStates.RemoveAll(x => x.Name == "Аварийный уровень"); AddAdditionalState(deviceState, "Низкий уровень", XStateClass.Info); break; case "Высокий уровень": deviceState.AdditionalStates.RemoveAll(x => x.Name == "Аварийный уровень"); AddAdditionalState(deviceState, "Низкий уровень", XStateClass.Info); AddAdditionalState(deviceState, "Высокий уровень", XStateClass.Info); break; case "Аварийный уровень": AddAdditionalState(deviceState, "Низкий уровень", XStateClass.Info); AddAdditionalState(deviceState, "Высокий уровень", XStateClass.Info); AddAdditionalState(deviceState, "Аварийный уровень", XStateClass.Failure); break; case "Уровень норма": deviceState.AdditionalStates.RemoveAll(x => x.Name == "Низкий уровень"); deviceState.AdditionalStates.RemoveAll(x => x.Name == "Высокий уровень"); deviceState.AdditionalStates.RemoveAll(x => x.Name == "Аварийный уровень"); break; } } } }