public void Rangieren(Datenstruktur datenstruktur, bool eingaengeRangieren) { if (eingaengeRangieren) { _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.B1, _foerderanlageViewModel.Foerderanlage.B1); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.B2, _foerderanlageViewModel.Foerderanlage.B2); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.F1, _foerderanlageViewModel.Foerderanlage.F1); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S0, _foerderanlageViewModel.Foerderanlage.S0); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S1, _foerderanlageViewModel.Foerderanlage.S1); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S2, _foerderanlageViewModel.Foerderanlage.S2); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S3, _foerderanlageViewModel.Foerderanlage.S3); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S4, _foerderanlageViewModel.Foerderanlage.S4); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S5, _foerderanlageViewModel.Foerderanlage.S5); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S6, _foerderanlageViewModel.Foerderanlage.S6); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S7, _foerderanlageViewModel.Foerderanlage.S7); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S8, _foerderanlageViewModel.Foerderanlage.S8); _plc.SetIntAt(datenstruktur.AnalogInput, 0, Simatic.Analog_2_Int16(_foerderanlageViewModel.Foerderanlage.Silo.GetFuellstand(), 1)); } if (_mainWindow.DebugWindowAktiv) { return; } _foerderanlageViewModel.Foerderanlage.K1 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.K1); _foerderanlageViewModel.Foerderanlage.P1 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.P1); _foerderanlageViewModel.Foerderanlage.P2 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.P2); _foerderanlageViewModel.Foerderanlage.Q1 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.Q1); _foerderanlageViewModel.Foerderanlage.Q2 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.Q2); _foerderanlageViewModel.Foerderanlage.T1 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.T1); }
public void Rangieren(Datenstruktur datenstruktur, bool eingaengeRangieren) { if (eingaengeRangieren) { _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S1, _viewModel.Kraftwerk.KraftwerkStarten); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S2, _viewModel.Kraftwerk.KraftwerkStoppen); _plc.SetIntAt(datenstruktur.AnalogInput, 0, Simatic.Analog_2_Int16(_viewModel.Kraftwerk.GeneratorN, 10000)); _plc.SetIntAt(datenstruktur.AnalogInput, 2, Simatic.Analog_2_Int16(_viewModel.Kraftwerk.GeneratorU, 1000)); _plc.SetIntAt(datenstruktur.AnalogInput, 4, Simatic.Analog_2_Int16(_viewModel.Kraftwerk.GeneratorF, 100)); _plc.SetIntAt(datenstruktur.AnalogInput, 6, Simatic.Analog_2_Int16(_viewModel.Kraftwerk.GeneratorP, 10000)); _plc.SetIntAt(datenstruktur.AnalogInput, 8, Simatic.Analog_2_Int16(_viewModel.Kraftwerk.GeneratorCosPhi, 1)); _plc.SetIntAt(datenstruktur.AnalogInput, 10, Simatic.Analog_2_Int16(_viewModel.Kraftwerk.NetzU, 1000)); _plc.SetIntAt(datenstruktur.AnalogInput, 12, Simatic.Analog_2_Int16(_viewModel.Kraftwerk.NetzF, 100)); _plc.SetIntAt(datenstruktur.AnalogInput, 14, Simatic.Analog_2_Int16(_viewModel.Kraftwerk.NetzP, 10000)); _plc.SetIntAt(datenstruktur.AnalogInput, 16, Simatic.Analog_2_Int16(_viewModel.Kraftwerk.NetzCosPhi, 1)); _plc.SetIntAt(datenstruktur.AnalogInput, 18, Simatic.Analog_2_Int16(_viewModel.Kraftwerk.SpannungsdifferenzGeneratorNetz, 1000)); } if (_mainWindow.DebugWindowAktiv) { return; } _viewModel.Kraftwerk.Q1 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.Q1); _viewModel.Kraftwerk.VentilY = _viewModel.Kraftwerk.Generator.VentilRampe.GetWert(Simatic.Analog_2_Double(_plc.GetIntAt(datenstruktur.AnalogOutput, 0), 100)); _viewModel.Kraftwerk.GeneratorIe = _viewModel.Kraftwerk.Generator.ErregerstromRampe.GetWert(Simatic.Analog_2_Double(_plc.GetIntAt(datenstruktur.AnalogOutput, 2), 10)); }
private static void SetAnalogerEingang(FunctionEventArgs e) { var startByte = e.Parameters[0].ToInteger(); var analogInput = e.Parameters[1].ToInteger(); var datenTyp = e.Parameters[2].ToString(); if (datenTyp != "S7 / 16 Bit / Prozent") { return; } var siemens = Simatic.Analog_2_Int16(analogInput, 100); Datenstruktur.AnalogInput[startByte] = Simatic.Digital_GetLowByte((uint)siemens); Datenstruktur.AnalogInput[startByte + 1] = Simatic.Digital_GetHighByte((uint)siemens); }
public void Rangieren(Datenstruktur datenstruktur, bool eingaengeRangieren) { if (eingaengeRangieren) { _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.B1, _viewModel.Abfuellanlage.B1); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.F1, _viewModel.Abfuellanlage.F1); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S1, _viewModel.Abfuellanlage.S1); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S2, _viewModel.Abfuellanlage.S2); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S3, _viewModel.Abfuellanlage.S3); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S4, _viewModel.Abfuellanlage.S4); _plc.SetIntAt(datenstruktur.AnalogInput, 0, Simatic.Analog_2_Int16(_viewModel.Abfuellanlage.Pegel, 1)); } _viewModel.Abfuellanlage.K1 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.K1); _viewModel.Abfuellanlage.K2 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.K2); _viewModel.Abfuellanlage.P1 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.P1); _viewModel.Abfuellanlage.P2 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.P2); _viewModel.Abfuellanlage.Q1 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.Q1); }
public void Rangieren(Datenstruktur datenstruktur, bool eingaengeRangieren) { if (eingaengeRangieren) { _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.B1, _viewModel.Schleifmaschine.B1); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.F1, _viewModel.Schleifmaschine.F1); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.F2, _viewModel.Schleifmaschine.F2); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S0, _viewModel.Schleifmaschine.S0); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S1, _viewModel.Schleifmaschine.S1); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S2, _viewModel.Schleifmaschine.S2); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S3, _viewModel.Schleifmaschine.S3); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S4, _viewModel.Schleifmaschine.S4); } _viewModel.Schleifmaschine.P1 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.P1); _viewModel.Schleifmaschine.P2 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.P2); _viewModel.Schleifmaschine.P3 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.P3); _viewModel.Schleifmaschine.Q1 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.Q1); _viewModel.Schleifmaschine.Q2 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.Q2); _plc.SetIntAt(datenstruktur.AnalogInput, 0, Simatic.Analog_2_Int16(_viewModel.Schleifmaschine.DrehzahlSchleifmaschine, 10000)); }
public void Rangieren(Datenstruktur datenstruktur, bool eingaengeRangieren) { if (eingaengeRangieren) { _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.B1, _foerderanlageViewModel.Silosteuerung.B1); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.B2, _foerderanlageViewModel.Silosteuerung.B2); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.F1, _foerderanlageViewModel.Silosteuerung.F1); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.F2, _foerderanlageViewModel.Silosteuerung.F2); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S0, _foerderanlageViewModel.Silosteuerung.S0); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S1, _foerderanlageViewModel.Silosteuerung.S1); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S2, _foerderanlageViewModel.Silosteuerung.S2); _plc.SetBitAt(datenstruktur.DigInput, (int)BitPosEingang.S3, _foerderanlageViewModel.Silosteuerung.S3); _plc.SetIntAt(datenstruktur.AnalogInput, 0, Simatic.Analog_2_Int16(_foerderanlageViewModel.Silosteuerung.Silo.GetFuellstand(), 1)); } _foerderanlageViewModel.Silosteuerung.P1 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.P1); _foerderanlageViewModel.Silosteuerung.P2 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.P2); _foerderanlageViewModel.Silosteuerung.Q1 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.Q1); _foerderanlageViewModel.Silosteuerung.Q2 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.Q2); _foerderanlageViewModel.Silosteuerung.Y1 = _plc.GetBitAt(datenstruktur.DigOutput, (int)BitPosAusgang.Y1); }
internal void StartDiffProcessAsync() { Simatic _Simatic; try { IsBusy = true; //_Simatic = new Simatic(); ProgressBarMax = 10; ProgressBarCurrent = 1; DateTime tsSearchTimeStart = DateTime.Now; EventFire.Info("Merging. Search start timestamp: " + (DateTime.Now - tsSearchTimeStart).TotalSeconds.ToString("0.0") + "s"); if (CurrentBlock.Value.LeftBlock.ModifiedSimilarity == BlockSimilarityType.Orphan) { EventFire.Error("Merging. Can't merge orphan blocks."); return; } _Simatic = new Simatic(); if (_Simatic == null) { EventFire.Info("Merging. Creating Simatic instance."); _Simatic = new Simatic(); } ProgressBarCurrent++; // Attaching both projects LoadingBothSimaticProjects(ref _Simatic); // Special logic to merge source files if (CurrentBlock.Value.LeftBlock.Type == PLCBlockType.SourceBlock && CurrentBlock.Value.RightBlock.Type == PLCBlockType.SourceBlock) { S7Source rightBlock = null; S7Source leftBlock = null; rightBlock = FindCurrentSourceInProgram(_RightProject, ref _dicRightSimaticCache); leftBlock = FindCurrentSourceInProgram(_LeftProject, ref _dicLeftSimaticCache); // TODO: wrap it into function // Find left and right blocks at the same time //Thread thRight = new Thread(new ThreadStart(() => //{ // EventFire.Info("Merging Source. Searching for the right block in Simatic structure."); // rightBlock = FindCurrentSourceInProgram(_RightProject.Programs, ref _dicRightSimaticCache); // EventFire.Info("Merging Source. Right block found."); //})); //thRight.Start(); //Thread thLeft = new Thread(new ThreadStart(() => //{ // EventFire.Info("Merging Source. Searching for the left block in Simatic structure."); // leftBlock = FindCurrentSourceInProgram(_LeftProject.Programs, ref _dicLeftSimaticCache); // EventFire.Info("Merging Source. Left block found."); //})); //thLeft.Start(); //// Wait for both threads to complete //thRight.Join(); //thLeft.Join(); //// TODO: end wrap it into function ProgressBarCurrent++; EventFire.Info("Merging. Search complete timestamp: " + (DateTime.Now - tsSearchTimeStart).TotalSeconds.ToString("0.0") + "s"); S7_BlockCopyMerge mrg = new S7_BlockCopyMerge(); mrg.MergeBlocks(leftBlock, rightBlock, ExtractRightProjectPath, CurrentBlock); } else { // Standard FB/FC/DB S7Block leftBlock = null; S7Block rightBlock = null; rightBlock = FindCurrentBlockInProgram(_RightProject, ref _dicRightSimaticCache); leftBlock = FindCurrentBlockInProgram(_LeftProject, ref _dicLeftSimaticCache); // TODO: wrap it into function // Find left and right blocks at the same time //Thread thRight = new Thread(new ThreadStart(() => //{ // EventFire.Info("Merging. Searching for the right block in Simatic structure."); // rightBlock = FindCurrentBlockInProgram(_RightProject.Programs, ref _dicRightSimaticCache); // EventFire.Info("Merging. Right block found."); //})); //thRight.Start(); //Thread thLeft = new Thread(new ThreadStart(() => //{ // EventFire.Info("Merging. Searching for the left block in Simatic structure."); // leftBlock = FindCurrentBlockInProgram(_LeftProject.Programs, ref _dicLeftSimaticCache); // EventFire.Info("Merging. Left block found."); //})); //thLeft.Start(); //// Wait for both threads to complete //thRight.Join(); //thLeft.Join(); // TODO: end wrap it into function ProgressBarCurrent++; EventFire.Info("Merging. Search complete timestamp: " + (DateTime.Now - tsSearchTimeStart).TotalSeconds.ToString("0.0") + "s"); S7_BlockCopyMerge mrg = new S7_BlockCopyMerge(); mrg.MergeBlocks(leftBlock, rightBlock); } ProgressBarCurrent++; // TODO: Remove temp files // Refresh list EventFire.Info("Merging. Refreshing projects."); GetBlocksAsync(ExtractRightProjectPath, ExtractLeftProjectPath); ProgressBarCurrent = ProgressBarMax; EventFire.Info("Merging. Process completed."); IsBusy = false; } catch (Exception err) { EventFire.Error(err.ToString()); } }
internal void CopyBlockToRightAsync() { Simatic _Simatic = null; try { if (CurrentBlock.Key.Count() <= 0) { return; } IsBusy = true; ProgressBarMax = 10; ProgressBarCurrent = 1; DateTime tsSearchTimeStart = DateTime.Now; EventFire.Info("Copying. Search start timestamp: " + (DateTime.Now - tsSearchTimeStart).TotalSeconds.ToString("0.0") + "s"); if (_Simatic == null) { EventFire.Info("Copying. Creating Simatic instance."); _Simatic = new Simatic(); } // Trying to find loaded projects LoadingBothSimaticProjects(ref _Simatic); // Special logic to copy source files if (CurrentBlock.Value.LeftBlock.Type == PLCBlockType.SourceBlock && CurrentBlock.Value.RightBlock.Type == PLCBlockType.SourceBlock) { // Special case - copying source blocks S7Source rightBlock = null; S7Source leftBlock = null; rightBlock = FindCurrentSourceInProgram(_RightProject, ref _dicRightSimaticCache); leftBlock = FindCurrentSourceInProgram(_LeftProject, ref _dicLeftSimaticCache); //// TODO: wrap it into function //// Find left and right blocks at the same time //Thread thRight = new Thread(new ThreadStart(() => //{ // EventFire.Info("Copying Source. Searching for the right block in Simatic structure."); // rightBlock = FindCurrentSourceInProgram(_RightProject.Programs, ref _dicRightSimaticCache); // EventFire.Info("Copying Source. Right block found."); //})); //thRight.Start(); //Thread thLeft = new Thread(new ThreadStart(() => // { // EventFire.Info("Copying Source. Searching for the left block in Simatic structure."); // leftBlock = FindCurrentSourceInProgram(_LeftProject.Programs, ref _dicLeftSimaticCache); // EventFire.Info("Copying Source. Left block found."); //})); //thLeft.Start(); //// Wait for both threads to complete //thRight.Join(); //thLeft.Join(); //// TODO: end wrap it into function ProgressBarCurrent++; // Find right block folder IS7Container rightFolder = FindBlockFolderInProgram(CurrentBlock, _RightProject, ref _dicRightSimaticCache); EventFire.Info("Copying. Search complete timestamp: " + (DateTime.Now - tsSearchTimeStart).TotalSeconds.ToString("0.0") + "s"); S7_BlockCopyMerge mrg = new S7_BlockCopyMerge(); if (mrg.CopyBlock(leftBlock, rightBlock, rightFolder)) { // Need to refresh right cache EventFire.Info("Copying. Clearing right project cache."); this._dicRightSimaticCache.dicProgramsLogPath.Clear(); } } else { // Standard block FC/FB/DB S7Block leftBlock = null; S7Block rightBlock = null; rightBlock = FindCurrentBlockInProgram(_RightProject, ref _dicRightSimaticCache); leftBlock = FindCurrentBlockInProgram(_LeftProject, ref _dicLeftSimaticCache); // TODO: wrap it into function // Find left and right blocks at the same time //Thread thRight = new Thread(new ThreadStart(() => //{ // EventFire.Info("Copying. Searching for the right block in Simatic structure."); // rightBlock = FindCurrentBlockInProgram(_RightProject.Programs, ref _dicRightSimaticCache); // EventFire.Info("Copying. Right block found."); //})); //thRight.SetApartmentState(ApartmentState.STA); //thRight.Start(); //Thread thLeft = new Thread(new ThreadStart(() => //{ // EventFire.Info("Copying. Searching for the left block in Simatic structure."); // leftBlock = FindCurrentBlockInProgram(_LeftProject.Programs, ref _dicLeftSimaticCache); // EventFire.Info("Copying. Left block found."); //})); //thLeft.SetApartmentState(ApartmentState.STA); //thLeft.Start(); //// Wait for both threads to complete //thRight.Join(); //thLeft.Join(); //// TODO: end wrap it into function ProgressBarCurrent++; // Find right block folder IS7Container rightFolder = FindBlockFolderInProgram(CurrentBlock, _RightProject, ref _dicRightSimaticCache); EventFire.Info("Copying. Search complete timestamp: " + (DateTime.Now - tsSearchTimeStart).TotalSeconds.ToString("0.0") + "s"); // Copy block to the right S7_BlockCopyMerge mrg = new S7_BlockCopyMerge(); if (mrg.CopyBlock(leftBlock, rightBlock, rightFolder)) { // Need to refresh right cache EventFire.Info("Copying. Clearing right project cache."); this._dicRightSimaticCache.dicProgramsLogPath.Clear(); } ProgressBarCurrent++; } ProgressBarCurrent++; EventFire.Info("Copying. Refreshing projects."); GetBlocksAsync(ExtractRightProjectPath, ExtractLeftProjectPath); ProgressBarCurrent = ProgressBarMax; EventFire.Info("Copying. Process completed."); IsBusy = false; } catch (Exception err) { EventFire.Error(err.ToString()); } }
private void LoadingBothSimaticProjects(ref Simatic _Simatic) { try { // Trying to find loaded projects EventFire.Info("Loading left project to Simatic."); if (ExtractLeftProjectPath != "") { _LeftProject = getSimaticProject(ref _Simatic, GetProjectFileNameFromPath(ExtractLeftProjectPath)); } else { if (IsZippedProject(LeftProjectPath)) { // Zipped project - Unzip it first ExtractLeftProjectPath = Path.GetTempPath() + "DMC_Merge" + "\\pLeft\\"; _LeftProject = getSimaticProject(ref _Simatic, UnzipProject(LeftProjectPath, ExtractLeftProjectPath)); } else { // Unzipped project - attach ExtractLeftProjectPath = LeftProjectPath; _LeftProject = getSimaticProject(ref _Simatic, GetProjectFileNameFromPath(LeftProjectPath)); } } ProgressBarCurrent++; EventFire.Info("Loading right project to Simatic."); if (ExtractRightProjectPath != "") { _RightProject = getSimaticProject(ref _Simatic, GetProjectFileNameFromPath(ExtractRightProjectPath)); } else { if (IsZippedProject(RightProjectPath)) { // Zipped project - Unzip it first ExtractRightProjectPath = Path.GetTempPath() + "DMC_Merge" + "\\pRight\\"; _RightProject = getSimaticProject(ref _Simatic, UnzipProject(RightProjectPath, ExtractRightProjectPath)); } else { // Unzipped project - attach ExtractRightProjectPath = RightProjectPath; _RightProject = getSimaticProject(ref _Simatic, GetProjectFileNameFromPath(RightProjectPath)); } } ProgressBarCurrent++; } catch (Exception err) { EventFire.Error(err.ToString()); } }
private S7Project getSimaticProject(ref Simatic _Simatic, string ProjectPath) { if (ProjectPath.ToLower().EndsWith(".s7p")) { return (S7Project)_Simatic.Projects.Add(ProjectPath); } else { var Projects = Directory.EnumerateFiles(ProjectPath, "*.s7p", SearchOption.AllDirectories); if (Projects.Count() > 0) { return (S7Project)_Simatic.Projects.Add(Projects.First()); } else { throw new FileNotFoundException("s7p file not found in the folder!"); } } }
internal static uint GetDigitalOutputWord() => Simatic.Digital_CombineTwoByte(Datenstruktur.DigOutput[0], Datenstruktur.DigOutput[1]);
internal static void SetDigitaleEingaengeWord(Uint eingaenge) { Datenstruktur.DigInput[0] = Simatic.Digital_GetLowByte((uint)eingaenge.GetDec()); Datenstruktur.DigInput[1] = Simatic.Digital_GetHighByte((uint)eingaenge.GetDec()); }
private void EinZyklusAbwarten() { var akt = _aktuell + _faktor * (_neuerSollwert - _aktuell); _aktuell = Simatic.Clamp(akt, _limitMin, _limitMax); }