private void AutomationWorker_DoWork() { List <Tuple <ushort, ushort> > tuples = new List <Tuple <ushort, ushort> >() { new Tuple <ushort, ushort>((ushort)PointType.DIGITAL_OUTPUT, 2000), new Tuple <ushort, ushort>((ushort)PointType.DIGITAL_OUTPUT, 2001), new Tuple <ushort, ushort>((ushort)PointType.ANALOG_OUTPUT, 1000) }; List <IPoint> points = storage.GetPoints(tuples); IConfigItem item = configuration.GetConfigurationItems().Find(x => x.StartAddress == 1000); while (!shutDown) { ushort value = points[2].RawValue; if (points[0].RawValue == 1) { value -= EGUConverter.ConvertToRaw(item.A, item.B, 10); } if (points[1].RawValue == 1) { value -= EGUConverter.ConvertToRaw(item.A, item.B, 15); } if (value != points[2].RawValue) { commandExecutor.CreateAndExecuteFunction(ModbusFunctionCode.WRITE_SINGLE_REGISTER, 1000, value); } Thread.Sleep(1000); // don't burn CPU // TODO implement } }
private void AutomationWorker_DoWork() { List <Tuple <ushort, ushort> > tuples = new List <Tuple <ushort, ushort> >() { new Tuple <ushort, ushort>((ushort)PointType.DIGITAL_INPUT, (ushort)1000), new Tuple <ushort, ushort>((ushort)PointType.DIGITAL_INPUT, (ushort)1001), new Tuple <ushort, ushort>((ushort)PointType.ANALOG_OUTPUT, (ushort)3000), new Tuple <ushort, ushort>((ushort)PointType.ANALOG_OUTPUT, (ushort)3001) }; List <IPoint> points = storage.GetPoints(tuples); IConfigItem AO = configuration.GetConfigurationItems().Find(x => x.StartAddress == 3000); while (!shutDown) { if (points[0].RawValue == 0 && points[1].RawValue == 1 && points[2].RawValue > EGUConverter.ConvertToRaw(AO.A, AO.B, 2000) && points[3].RawValue < EGUConverter.ConvertToRaw(AO.A, AO.B, 1500)) { commandExecutor.CreateAndExecuteFunction(ModbusFunctionCode.WRITE_SINGLE_COIL, 40, 1); commandExecutor.CreateAndExecuteFunction(ModbusFunctionCode.WRITE_SINGLE_REGISTER, 3000, (ushort)(points[2].RawValue - EGUConverter.ConvertToRaw(AO.A, AO.B, 10))); commandExecutor.CreateAndExecuteFunction(ModbusFunctionCode.WRITE_SINGLE_REGISTER, 3001, (ushort)(points[3].RawValue + EGUConverter.ConvertToRaw(AO.A, AO.B, 10))); } Thread.Sleep(2000); // don't burn CPU } }
private void AutomationWorker_DoWork() { EGUConverter eguConverter = new EGUConverter(); while (!disposedValue) { PointIdentifier analogOut = new PointIdentifier(PointType.ANALOG_OUTPUT, 1000); PointIdentifier izlaz1 = new PointIdentifier(PointType.DIGITAL_OUTPUT, 2000); PointIdentifier izlaz2 = new PointIdentifier(PointType.DIGITAL_OUTPUT, 2001); PointIdentifier izlaz3 = new PointIdentifier(PointType.DIGITAL_OUTPUT, 2002); PointIdentifier izlaz4 = new PointIdentifier(PointType.DIGITAL_OUTPUT, 2003); PointIdentifier punjac1 = new PointIdentifier(PointType.DIGITAL_OUTPUT, 3000); PointIdentifier punjac2 = new PointIdentifier(PointType.DIGITAL_OUTPUT, 3001); List <PointIdentifier> points = new List <PointIdentifier>() { analogOut, izlaz1, izlaz2, izlaz3, izlaz4, punjac1, punjac2 }; // List <IPoint> pointList = storage.GetPoints(points); // ushort value = pointList[0].RawValue; bool ugasiIzlaz = false; bool ugasiPunjac = false; // kad rezervoar stigne do manje od 1000 onda ugasiti izlaze i upaliti punjace if (value < eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 1000)) { ugasiIzlaz = true; } // kad rezervoar stigne do vise od 8000 onda ugasiti punjace if (value > eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 8000)) { ugasiPunjac = true; } // logika za rad izlaza if (!ugasiIzlaz) { if (pointList[1].RawValue == 1) { value -= eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 10); } if (pointList[2].RawValue == 1) { value -= eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 10); } if (pointList[3].RawValue == 1) { value -= eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 10); } if (pointList[4].RawValue == 1) { value -= eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 10); } } if (!ugasiPunjac) { if (pointList[5].RawValue == 1) { value += eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 100); } if (pointList[6].RawValue == 1) { value += eguConverter.ConvertToRaw(pointList[0].ConfigItem.ScaleFactor, pointList[0].ConfigItem.Deviation, 50); } // pokusaj zabrane promene if (pointList[1].RawValue == 1) { processingManager.ExecuteWriteCommand(pointList[1].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[1].Address, 0); } if (pointList[2].RawValue == 1) { processingManager.ExecuteWriteCommand(pointList[2].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[2].Address, 0); } if (pointList[3].RawValue == 1) { processingManager.ExecuteWriteCommand(pointList[1].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[3].Address, 0); } if (pointList[4].RawValue == 1) { processingManager.ExecuteWriteCommand(pointList[2].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[4].Address, 0); } } // slanje updatovane vrednosti nazad u rezervoar if (value != pointList[0].RawValue) { processingManager.ExecuteWriteCommand(pointList[0].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[0].Address, value); } if (ugasiIzlaz) { // ugasi sve izlaze if (pointList[1].RawValue == 1) { processingManager.ExecuteWriteCommand(pointList[1].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[1].Address, 0); } if (pointList[2].RawValue == 1) { processingManager.ExecuteWriteCommand(pointList[2].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[2].Address, 0); } if (pointList[3].RawValue == 1) { processingManager.ExecuteWriteCommand(pointList[1].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[3].Address, 0); } if (pointList[4].RawValue == 1) { processingManager.ExecuteWriteCommand(pointList[2].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[4].Address, 0); } // upali sve punjace if (pointList[5].RawValue == 0) { processingManager.ExecuteWriteCommand(pointList[5].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[5].Address, 1); } if (pointList[6].RawValue == 0) { processingManager.ExecuteWriteCommand(pointList[6].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[6].Address, 1); } } // ugasi sve punjace if (ugasiPunjac) { if (pointList[5].RawValue == 1) { processingManager.ExecuteWriteCommand(pointList[5].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[5].Address, 0); } if (pointList[6].RawValue == 1) { processingManager.ExecuteWriteCommand(pointList[6].ConfigItem, configuration.GetTransactionId(), configuration.UnitAddress, points[6].Address, 0); } } automationTrigger.WaitOne(delayBetweenCommands); } }