private void SendSCADACommand(long currentBreakerId, DiscreteCommandingType discreteCommandingType) { long measrement = -1; using (MeasurementMapProxy measurementMapProxy = proxyFactory.CreateProxy <MeasurementMapProxy, IMeasurementMapContract>(EndpointNames.MeasurementMapEndpoint)) { List <long> measuremnts = new List <long>(); try { measuremnts = measurementMapProxy.GetMeasurementsOfElement(currentBreakerId); } catch (Exception e) { //Logger.LogError("Error on GetMeasurementsForElement() method", e); throw e; } if (measuremnts.Count > 0) { measrement = measuremnts[0]; } } if (measrement != -1) { if (discreteCommandingType == DiscreteCommandingType.OPEN && !outageModel.commandedElements.Contains(currentBreakerId)) { //TODO: add at list outageModel.commandedElements.Add(currentBreakerId); } using (SCADACommandProxy scadaCommandProxy = proxyFactory.CreateProxy <SCADACommandProxy, ISCADACommand>(EndpointNames.SCADACommandService)) { try { bool success = scadaCommandProxy.SendDiscreteCommand(measrement, (ushort)discreteCommandingType, CommandOriginType.ISOLATING_ALGORITHM_COMMAND); } catch (Exception e) { if (discreteCommandingType == DiscreteCommandingType.OPEN && outageModel.commandedElements.Contains(currentBreakerId)) { outageModel.commandedElements.Remove(currentBreakerId); } throw e; } } } }
private void OpenIsolationPoints(Dictionary <long, DiscreteModbusData> isolationPoints) { using (SCADACommandProxy proxy = proxyFactory.CreateProxy <SCADACommandProxy, ISCADACommand>(EndpointNames.SCADACommandService)) { if (proxy == null) { string message = "OpenDefaultIsolationPoints => SCADACommandProxy is null"; Logger.LogError(message); throw new NullReferenceException(message); } foreach (long gid in isolationPoints.Keys) { if (isolationPoints[gid].Value != (ushort)DiscreteCommandingType.OPEN) { //TODO: COMMANDING ENUM u COMMON proxy.SendDiscreteCommand(gid, (ushort)DiscreteCommandingType.OPEN, CommandOriginType.OUTAGE_SIMULATOR); } } } }
public void SendAnalogCommand(long measurementGid, float commandingValue, CommandOriginType commandOrigin) { try { ProxyFactory proxyFactory = new ProxyFactory(); using (SCADACommandProxy proxy = proxyFactory.CreateProxy <SCADACommandProxy, ISCADACommand>(EndpointNames.SCADACommandService)) { if (proxy == null) { string message = "SendDiscreteCommand => SCADACommandProxy is null."; logger.LogError(message); throw new NullReferenceException(message); } proxy.SendAnalogCommand(measurementGid, commandingValue, commandOrigin); } } catch (Exception) { throw; } }
public void SendDiscreteCommand(long measurementGid, int value, CommandOriginType commandOrigin) { try { if (Provider.Instance.MeasurementProvider.TryGetDiscreteMeasurement(measurementGid, out DiscreteMeasurement measurement) && !(measurement is ArtificalDiscreteMeasurement)) { ProxyFactory proxyFactory = new ProxyFactory(); using (SCADACommandProxy proxy = proxyFactory.CreateProxy <SCADACommandProxy, ISCADACommand>(EndpointNames.SCADACommandService)) { if (proxy == null) { string message = "SendDiscreteCommand => SCADACommandProxy is null."; logger.LogError(message); throw new NullReferenceException(message); } proxy.SendDiscreteCommand(measurementGid, (ushort)value, commandOrigin); } } else { //TOOD: DiscreteModbusData prilikom prijema sa skade prepakovati u model podataka koji ce se cuvati na CE, u prilogy AlarmType.NO_ALARM, nije validna stvar, navodi se da se //DiscreteModbusData data = new DiscreteModbusData((ushort)value, AlarmType.NO_ALARM, measurementGid, commandOrigin); Dictionary <long, DiscreteModbusData> data = new Dictionary <long, DiscreteModbusData>(1) { { measurementGid, new DiscreteModbusData((ushort)value, AlarmType.NO_ALARM, measurementGid, commandOrigin) } }; Provider.Instance.MeasurementProvider.UpdateDiscreteMeasurement(data); //Provider.Instance.MeasurementProvider.UpdateDiscreteMeasurement(data.MeasurementGid, data.Value, data.CommandOrigin); } } catch (Exception ex) { logger.LogError($"Sending discrete command for measurement with GID 0x{measurementGid.ToString("X16")} failed. Exception: {ex.Message}"); } }