Per impostare la comunicazione con un dispositivo Allen Bradley è necessario impostare la proprietà "Name" dell'ioserver a "ABEthernetIP"
Le variabili sono lette e scritte per nome, è quindi necessario inserire nella proprietà "Address" della variable il nome della variabile che si vuole gestire.
I tipi di dato gestiti sono:
La lettura dei tag viene effettuate per nome e non per indirizzamento e dimensione come per altri driver (ad esempio Modbus, Siemens, Omron, ecc...) quindi per qualsiasi tag può essere utilizzato il tipo "Variant". È auspicabile utilizzare tipi di dato non "Variant" nel caso in cui il valore letto dal dispositivo debba poi essere convertito, scalato o soggetto a qualche trasformazione.
Il campo area non è utilizzato.
Sono implementate le letture e scrittura multiple.
La porta socket da utilizzare per la comunicazione è la: 44818
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace TestEthernetIP { public partial class Form1 : Form { private IToolS.Components.Communication.Group m_group1; private IToolS.Components.Communication.Client m_client1; private IToolS.Components.IOServers.IOServer m_ioServer1; private IToolS.Components.Communication.Variable m_variable1; private IToolS.Components.Communication.Variable m_variable2; private IToolS.Components.Communication.Variable m_variable3; private IToolS.Components.Communication.Variable m_variable4; private IToolS.Components.Communication.Variable m_variable5; private IToolS.Windows.Forms.Variables.VariablesWindow variablesWindow1; /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; public Form1() { InitializeComponent(); m_group1 = new IToolS.Components.Communication.Group(); m_variable1 = new IToolS.Components.Communication.Variable(); m_variable2 = new IToolS.Components.Communication.Variable(); m_variable3 = new IToolS.Components.Communication.Variable(); m_variable4 = new IToolS.Components.Communication.Variable(); m_variable5 = new IToolS.Components.Communication.Variable(); m_client1 = new IToolS.Components.Communication.Client(); m_ioServer1 = new IToolS.Components.IOServers.IOServer(); m_group1.Items.Add(m_variable1); m_group1.Items.Add(m_variable2); m_group1.Items.Add(m_variable3); m_group1.Items.Add(m_variable4); m_group1.Items.Add(m_variable5); m_variable1.Address = "Fix_INT_Tag"; m_variable1.VariableName = "variable1"; m_variable2.Address = "Counter_INT"; m_variable2.VariableName = "variable2"; m_variable3.Address = "Fix_SINT_Tag"; m_variable3.VariableName = "variable3"; m_variable3.VariableType = "Byte"; m_variable4.Address = "Counter_SINT"; m_variable4.VariableName = "variable4"; m_variable4.VariableType = "Byte"; m_variable5.Address = "Fix_BOOL_Tag"; m_variable5.VariableName = "variable5"; m_variable5.VariableType = "Bool"; m_client1.ClientName = "client1"; m_client1.Group = this.m_group1; m_client1.IOServer = this.m_ioServer1; m_client1.UpdateTime = 500; m_ioServer1.Name = "ABEthernetIP"; m_ioServer1.NetConfig.Address = "172.17.251.120"; m_ioServer1.NetConfig.Port = 44818; } /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.variablesWindow1 = new IToolS.Windows.Forms.Variables.VariablesWindow(); ((System.ComponentModel.ISupportInitialize)(this.variablesWindow1)).BeginInit(); this.SuspendLayout(); // // variablesWindow1 // this.variablesWindow1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.variablesWindow1.ColumnColor = System.Drawing.SystemColors.Control; this.variablesWindow1.EditKeyboardConfig.Font = new System.Drawing.Font("Tahoma", 8F); this.variablesWindow1.Fields = new string[] { "VariableName", "VariableType", "Area", "Address", "Value"}; this.variablesWindow1.Group = this.m_group1; this.variablesWindow1.KeyboardConfig.Font = new System.Drawing.Font("Tahoma", 8F); this.variablesWindow1.Location = new System.Drawing.Point(12, 12); this.variablesWindow1.Name = "variablesWindow1"; this.variablesWindow1.Size = new System.Drawing.Size(646, 260); this.variablesWindow1.TabIndex = 2; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(670, 304); this.Controls.Add(this.variablesWindow1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.variablesWindow1)).EndInit(); this.ResumeLayout(false); } #endregion private void Form1_Load(object sender, EventArgs e) { m_client1.Start(); } } }
IToolS Blog