From f5dbdf61c419cce8b5159faa63c888ff0e81e08d Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 1 Dec 2021 17:53:33 +0100 Subject: [PATCH] Eliminazione proj test Beckhoff --- Test-Beckhoff/ADS.cs | 324 ------------------ Test-Beckhoff/App.config | 6 - Test-Beckhoff/Form1.Designer.cs | 62 ---- Test-Beckhoff/Form1.cs | 39 --- Test-Beckhoff/Form1.resx | 120 ------- Test-Beckhoff/Program.cs | 22 -- Test-Beckhoff/Properties/AssemblyInfo.cs | 36 -- .../Properties/Resources.Designer.cs | 70 ---- Test-Beckhoff/Properties/Resources.resx | 117 ------- Test-Beckhoff/Properties/Settings.Designer.cs | 29 -- Test-Beckhoff/Properties/Settings.settings | 7 - Test-Beckhoff/Test-Beckhoff.csproj | 99 ------ 12 files changed, 931 deletions(-) delete mode 100644 Test-Beckhoff/ADS.cs delete mode 100644 Test-Beckhoff/App.config delete mode 100644 Test-Beckhoff/Form1.Designer.cs delete mode 100644 Test-Beckhoff/Form1.cs delete mode 100644 Test-Beckhoff/Form1.resx delete mode 100644 Test-Beckhoff/Program.cs delete mode 100644 Test-Beckhoff/Properties/AssemblyInfo.cs delete mode 100644 Test-Beckhoff/Properties/Resources.Designer.cs delete mode 100644 Test-Beckhoff/Properties/Resources.resx delete mode 100644 Test-Beckhoff/Properties/Settings.Designer.cs delete mode 100644 Test-Beckhoff/Properties/Settings.settings delete mode 100644 Test-Beckhoff/Test-Beckhoff.csproj diff --git a/Test-Beckhoff/ADS.cs b/Test-Beckhoff/ADS.cs deleted file mode 100644 index 37e5199c..00000000 --- a/Test-Beckhoff/ADS.cs +++ /dev/null @@ -1,324 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Net.NetworkInformation; -using System.Threading; -using TwinCAT; -using TwinCAT.Ads; -using TwinCAT.Ads.TypeSystem; -using System.IO; -using System.Text; -using System.Linq; -using System.Threading.Tasks; -using TwinCAT.TypeSystem; - -namespace Test_Beckhoff -{ - - //var handle = adsClient.AddDeviceNotification("MAIN.boolVal", dataStream, 0, 1, - // AdsTransMode.OnChange, 100, 0, new object() ); - - // Structure declaration for handles - - public enum EnuStates //Stato Macchina - { - Errore = -1, - Ferma = 0, - Automatica = 1, - Manuale = 2, - Emergenza = 3, - AzzeraTavola = 4, - ManualeStazione = 5, - Avviamento = 7, - } - - public class ADS - - { - - public class ComandiADS - { - - public TcAdsSymbolInfo Symbol; - public string SymbolName; - public bool ComandoScrittua; - public object Value; - public ManualResetEventSlim Updating; - public bool Error; - public ComandiADS() - { - Updating = new ManualResetEventSlim(false); - } - public ComandiADS(string name) - { - SymbolName = name; - Updating = new ManualResetEventSlim(false); - } - public ComandiADS(TcAdsSymbolInfo info) - { - Symbol = info; - Updating = new ManualResetEventSlim(false); - } - } - - /// - /// Dizionario di conversione da indice a index group e index offset - /// - private Dictionary> addressList; - public delegate void StatusChangedEventHandler(ADS sender, EnuStates newStatus); - public TcAdsSymbolInfoCollection Symbols; - private TcAdsClient adsClient; - public TcAdsClient Client - { - get { return adsClient; } - } - public TwinCAT.Ads.TcAdsSymbolInfoLoader InfoLoader; - public TwinCAT.TypeSystem.ISymbolLoader SymbolLoaderInstance; - - private List addedSignalationList = new List(); - - private int notifyposition; - private int eventHandle; - private int SegnalazioniADSEventHandle, StatusChangedEventHandle, MessageQueuedEventHandle; - - private AdsStream notifyStream; - private AdsStream newNotificationStream; - - public bool EnableEvents { get; set; } - - private EnuStates _status; - private object lockobj = new object(); - - //private Action dispatcher; - private System.Threading.Tasks.Task dispatchertask; - public System.Collections.Concurrent.ConcurrentQueue CodaComandi; - private CancellationTokenSource cts; - - Symbol StatoMacchina; - - - public event StatusChangedEventHandler StatusChanged; - - - public ADS(string indirizzo = "local", int porta = 851) - { - notifyStream = new AdsStream(); - newNotificationStream = new AdsStream(); - addressList = new Dictionary>(); - bool ready = false; - while (!ready) - { - try - { - //LETTURA DEL VETTORE DI INIZIALIZZAZIONE - if (adsClient == null) adsClient = new TcAdsClient(); - // Connect to local PLC - Runtime 1 - TwinCAT2 Port=801, TwinCAT3 Port=851 - if (indirizzo == "") - { - adsClient.Connect(porta); - } - else - { - if (adsClient.IsConnected == false) adsClient.Connect(indirizzo, porta); - } - - SymbolLoaderInstance = SymbolLoaderFactory.Create(adsClient, SymbolLoaderSettings.Default); - InfoLoader = adsClient.CreateSymbolInfoLoader(); - Symbols = InfoLoader.GetSymbols(true); - ready = true; - } - catch (Exception ex) - { - System.Threading.Thread.Sleep(100); - ready = false; - Debug.Print(ex.Message); - } - } - - - - StatoMacchina = (Symbol)SymbolLoaderInstance.Symbols["VarADS.StatoMacchina"]; - StatoMacchina.NotificationSettings = new AdsNotificationSettings(AdsTransMode.OnChange, 100, 100); - StatoMacchina.ValueChanged += StatoMacchina_ValueChanged; - - - notifyposition = 0; - cts = new CancellationTokenSource(); - - //adsClient.AdsNotification += new AdsNotificationEventHandler(adsClient_AdsNotification); - - CodaComandi = new System.Collections.Concurrent.ConcurrentQueue(); - cts = new CancellationTokenSource(); //Task require CancellationToken.cancel() to stop - Action Azione = commandDispatcher; - dispatchertask = new Task(Azione, cts.Token, TaskCreationOptions.PreferFairness); //Definisce e Crea un Task di base a priorità favorevole - dispatchertask.Start(); - } - - - private void StatoMacchina_ValueChanged(object sender, TwinCAT.TypeSystem.ValueChangedArgs e) - { - EnuStates newStatus = (EnuStates)e.Value; - if (StatusChanged != null) StatusChanged(this, newStatus); - } - - public void dispose() - { - //adsClient.Dispose(); - } - - - public TcAdsSymbolInfo GetSymbolInfo(string nome) - { - try - { - var symbol = InfoLoader.FindSymbol(nome); - return symbol; - } - catch (Exception) - { - - throw; - } - } - - private void commandDispatcher(object tk) - { - ComandiADS comando; - Thread.CurrentThread.Name = "ADS Command Dispatcher"; - CancellationToken chiudi = (CancellationToken)tk; - while (!chiudi.IsCancellationRequested) - { - Thread.Sleep(1); - if (CodaComandi.Count <= 0) - { - Thread.Sleep(1); - continue; - } - if (CodaComandi.Count > 100) Debug.Print("CODA COMANDI! " + CodaComandi.Count.ToString()); - if (!CodaComandi.TryDequeue(out comando)) continue; - - if (CodaComandi.Count > 1000) continue; - - if (comando.ComandoScrittua) //gestione scrittura - { - try - { - if (comando.SymbolName != "") - { - if (comando.Symbol == null) comando.Symbol = GetSymbolInfo(comando.SymbolName); - } - else - { - comando.SymbolName = comando.Symbol.Name; - } - if (comando.Value is int && comando.Symbol.Category == TwinCAT.TypeSystem.DataTypeCategory.Array) - { - var newvalue = new int[comando.Symbol.ArrayInfos[0].Elements]; - newvalue[0] = (int)comando.Value; - comando.Value = newvalue; - } - if (comando.Value is double && comando.Symbol.Category == TwinCAT.TypeSystem.DataTypeCategory.Array) - { - var newvalue = new double[comando.Symbol.ArrayInfos[0].Elements]; - newvalue[0] = (double)comando.Value; - comando.Value = newvalue; - } - adsClient.WriteSymbol(comando.Symbol, comando.Value); - - } - catch (Exception err) - { - comando.Error = true; - Debug.Print(comando.SymbolName + " Scrittura " + err.Message); - } - comando.Updating.Set(); - } - else // gestione lettura - { - try - { - if (comando.SymbolName != "") - { - if (comando.Symbol == null) comando.Symbol = GetSymbolInfo(comando.SymbolName); - } - else - { - comando.SymbolName = comando.Symbol.Name; - } - - comando.Value = adsClient.ReadSymbol(comando.Symbol); - - } - catch (Exception errore) - { - Debug.Print(errore.Message); - comando.Error = true; - Debug.Print("Error reading from ADS: VarName: " + comando.SymbolName); - } - comando.Updating.Set(); - } - } - } - - public object ReadVariabile(ref TcAdsSymbolInfo variabile) - { - var comando = new ComandiADS { ComandoScrittua = false, Symbol = variabile }; - return ReadVariabile(comando); - } - - public object ReadVariabile(string symbolName, Type type = null) - { - var comando = new ComandiADS { ComandoScrittua = false, SymbolName = symbolName }; - return ReadVariabile(comando); - } - - - private object ReadVariabile(ComandiADS comando) - { - CodaComandi.Enqueue(comando); - bool test = comando.Updating.Wait(3000); - if (!test) Debug.Print("Errore attesa lettura: " + comando.SymbolName); - if (comando.Value == null) Debug.Print("ADS Variabile non trovata: " + comando.SymbolName); - return comando.Value; - } - - public bool WriteVariabile(string symbolName, object value, bool syncronous = false) - { - var comando = new ComandiADS { Value = value, ComandoScrittua = true, SymbolName = symbolName }; - return WriteVariabile(comando, syncronous); - } - - public bool WriteVariabile(TcAdsSymbolInfo symbol, object value, bool syncronous = false) - { - var comando = new ComandiADS { Value = value, ComandoScrittua = true, Symbol = symbol }; - return WriteVariabile(comando, syncronous); - } - - private bool WriteVariabile(ComandiADS comando, bool syncronous) - { - bool test = true; - CodaComandi.Enqueue(comando); - if (syncronous) test = comando.Updating.Wait(3000); - if (!test) Debug.Print("Errore attesa lettura: " + comando.SymbolName); - if (comando.Error) Debug.Print("Errore ADS durante la scrittura della variabile: " + comando.SymbolName); - return !comando.Error; - } - - - - public EnuStates Status - { - get - { - var stato = ReadVariabile("VarADS.StatoMacchina"); - if (stato != null) _status = (EnuStates)stato; - else - { - throw new Exception("Errore lettura stato"); - } - return _status; - } - } - } - -} \ No newline at end of file diff --git a/Test-Beckhoff/App.config b/Test-Beckhoff/App.config deleted file mode 100644 index 56efbc7b..00000000 --- a/Test-Beckhoff/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Test-Beckhoff/Form1.Designer.cs b/Test-Beckhoff/Form1.Designer.cs deleted file mode 100644 index cee84f61..00000000 --- a/Test-Beckhoff/Form1.Designer.cs +++ /dev/null @@ -1,62 +0,0 @@ - -namespace Test_Beckhoff -{ - partial class Form1 - { - /// - /// Variabile di progettazione necessaria. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Pulire le risorse in uso. - /// - /// ha valore true se le risorse gestite devono essere eliminate, false in caso contrario. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Codice generato da Progettazione Windows Form - - /// - /// Metodo necessario per il supporto della finestra di progettazione. Non modificare - /// il contenuto del metodo con l'editor di codice. - /// - private void InitializeComponent() - { - this.button1 = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // button1 - // - this.button1.Location = new System.Drawing.Point(51, 49); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 23); - this.button1.TabIndex = 0; - this.button1.Text = "Start ADS"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); - // - // Form1 - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.button1); - this.Name = "Form1"; - this.Text = "Form1"; - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.Button button1; - } -} - diff --git a/Test-Beckhoff/Form1.cs b/Test-Beckhoff/Form1.cs deleted file mode 100644 index e81a3b2a..00000000 --- a/Test-Beckhoff/Form1.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Test_Beckhoff -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - - private void button1_Click(object sender, EventArgs e) - { - //var myADS = new ADS("local", 851); - var myADS = new ADS("5.97.72.66.1.1", 851); - - var myArtCorr = myADS.ReadVariabile("VarADS.NomeDisegno"); - - myADS.WriteVariabile("VarADS.NomeDisegnoRichiesto", "NUOVO DISEGNO"); - - myADS.WriteVariabile("VarADS.bCambioArticolo", 1); - - myADS.StatusChanged += MyADS_StatusChanged; - } - - private void MyADS_StatusChanged(ADS sender, EnuStates newStatus) - { - // notifica evento valore modificato (stato) - } - } -} diff --git a/Test-Beckhoff/Form1.resx b/Test-Beckhoff/Form1.resx deleted file mode 100644 index 1af7de15..00000000 --- a/Test-Beckhoff/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Test-Beckhoff/Program.cs b/Test-Beckhoff/Program.cs deleted file mode 100644 index 231025a5..00000000 --- a/Test-Beckhoff/Program.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Test_Beckhoff -{ - static class Program - { - /// - /// Punto di ingresso principale dell'applicazione. - /// - [STAThread] - static void Main() - { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); - } - } -} diff --git a/Test-Beckhoff/Properties/AssemblyInfo.cs b/Test-Beckhoff/Properties/AssemblyInfo.cs deleted file mode 100644 index b438c3e1..00000000 --- a/Test-Beckhoff/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// Le informazioni generali relative a un assembly sono controllate dal seguente -// set di attributi. Modificare i valori di questi attributi per modificare le informazioni -// associate a un assembly. -[assembly: AssemblyTitle("Test-Beckhoff")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Test-Beckhoff")] -[assembly: AssemblyCopyright("Copyright © 2021")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Se si imposta ComVisible su false, i tipi in questo assembly non saranno visibili -// ai componenti COM. Se è necessario accedere a un tipo in questo assembly da -// COM, impostare su true l'attributo ComVisible per tale tipo. -[assembly: ComVisible(false)] - -// Se il progetto viene esposto a COM, il GUID seguente verrà utilizzato come ID della libreria dei tipi -[assembly: Guid("41930054-510f-4893-8973-d50cd2241c5c")] - -// Le informazioni sulla versione di un assembly sono costituite dai seguenti quattro valori: -// -// Versione principale -// Versione secondaria -// Numero di build -// Revisione -// -// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build -// usando l'asterisco '*' come illustrato di seguito: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Test-Beckhoff/Properties/Resources.Designer.cs b/Test-Beckhoff/Properties/Resources.Designer.cs deleted file mode 100644 index 52603366..00000000 --- a/Test-Beckhoff/Properties/Resources.Designer.cs +++ /dev/null @@ -1,70 +0,0 @@ -//------------------------------------------------------------------------------ -// -// Codice generato da uno strumento. -// Versione runtime:4.0.30319.42000 -// -// Le modifiche apportate a questo file possono causare un comportamento non corretto e andranno perse se -// il codice viene rigenerato. -// -//------------------------------------------------------------------------------ - - -namespace Test_Beckhoff.Properties -{ - /// - /// Classe di risorse fortemente tipizzata per la ricerca di stringhe localizzate e così via. - /// - // Questa classe è stata generata automaticamente dalla classe StronglyTypedResourceBuilder - // tramite uno strumento quale ResGen o Visual Studio. - // Per aggiungere o rimuovere un membro, modificare il file .ResX, quindi eseguire di nuovo ResGen - // con l'opzione /str oppure ricompilare il progetto VS. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { - } - - /// - /// Restituisce l'istanza di ResourceManager memorizzata nella cache e usata da questa classe. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Test_Beckhoff.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Esegue l'override della proprietà CurrentUICulture del thread corrente per tutte - /// le ricerche di risorse che utilizzano questa classe di risorse fortemente tipizzata. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { - return resourceCulture; - } - set - { - resourceCulture = value; - } - } - } -} diff --git a/Test-Beckhoff/Properties/Resources.resx b/Test-Beckhoff/Properties/Resources.resx deleted file mode 100644 index af7dbebb..00000000 --- a/Test-Beckhoff/Properties/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Test-Beckhoff/Properties/Settings.Designer.cs b/Test-Beckhoff/Properties/Settings.Designer.cs deleted file mode 100644 index cea3795d..00000000 --- a/Test-Beckhoff/Properties/Settings.Designer.cs +++ /dev/null @@ -1,29 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -namespace Test_Beckhoff.Properties -{ - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { - return defaultInstance; - } - } - } -} diff --git a/Test-Beckhoff/Properties/Settings.settings b/Test-Beckhoff/Properties/Settings.settings deleted file mode 100644 index 39645652..00000000 --- a/Test-Beckhoff/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/Test-Beckhoff/Test-Beckhoff.csproj b/Test-Beckhoff/Test-Beckhoff.csproj deleted file mode 100644 index 0832b717..00000000 --- a/Test-Beckhoff/Test-Beckhoff.csproj +++ /dev/null @@ -1,99 +0,0 @@ - - - - - Debug - AnyCPU - {41930054-510F-4893-8973-D50CD2241C5C} - WinExe - Test_Beckhoff - Test-Beckhoff - v4.7.2 - 512 - true - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - False - ..\ExtLibs\AdsApi\.NET\v4.0.30319\TwinCAT.Ads.dll - - - - - - Form - - - Form1.cs - - - - - Form1.cs - - - ResXFileCodeGenerator - Resources.Designer.cs - Designer - - - True - Resources.resx - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - True - Settings.settings - True - - - - - - - - {00020430-0000-0000-C000-000000000046} - 2 - 0 - 0 - primary - False - True - - - - \ No newline at end of file