Aggiunto bozza progetto S7net per bench lettura

This commit is contained in:
Samuele Locatelli
2020-05-02 17:43:49 +02:00
parent 0c2a244115
commit 11ea38f08a
27 changed files with 6251 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Siemens-S7-Test", "Siemens-S7-Test\Siemens-S7-Test.csproj", "{A0168CBE-9DA5-4E41-82FF-AFD39C982717}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A0168CBE-9DA5-4E41-82FF-AFD39C982717}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A0168CBE-9DA5-4E41-82FF-AFD39C982717}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A0168CBE-9DA5-4E41-82FF-AFD39C982717}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A0168CBE-9DA5-4E41-82FF-AFD39C982717}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C43DB985-D122-49F0-AE6E-DADEFFC1AD3D}
EndGlobalSection
EndGlobal
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
<appSettings>
<add key="appName" value="Siemens.S7.Test"/>
<add key="verbose" value="false"/>
<!--conf file-->
<add key="dataPath" value="DATA"/>
<add key="dataConfPath" value="DATA\CONF"/>
<add key="dataDatPath" value="DATA\DAT"/>
<add key="MMapR" value="MMapR.map"/>
<add key="MMapW" value="MMapW.map"/>
<add key="charSep" value="|"/>
</appSettings>
</configuration>
@@ -0,0 +1,136 @@
using System;
using System.Globalization;
using System.Numerics;
namespace Siemens_S7_Test
{
public class BinaryFormatter : IFormatProvider, ICustomFormatter
{
// IFormatProvider.GetFormat implementation.
public object GetFormat(Type formatType)
{
// Determine whether custom formatting object is requested.
if (formatType == typeof(ICustomFormatter))
return this;
else
return null;
}
// Format number in binary (B), octal (O), or hexadecimal (H).
public string Format(string format, object arg, IFormatProvider formatProvider)
{
// Handle format string.
int baseNumber;
// Handle null or empty format string, string with precision specifier.
string thisFmt = String.Empty;
// Extract first character of format string (precision specifiers
// are not supported).
if (!String.IsNullOrEmpty(format))
thisFmt = format.Length > 1 ? format.Substring(0, 1) : format;
// Get a byte array representing the numeric value.
byte[] bytes;
if (arg is sbyte)
{
string byteString = ((sbyte)arg).ToString("X2");
bytes = new byte[1] { Byte.Parse(byteString, System.Globalization.NumberStyles.HexNumber) };
}
else if (arg is byte)
{
bytes = new byte[1] { (byte)arg };
}
else if (arg is short)
{
bytes = BitConverter.GetBytes((short)arg);
}
else if (arg is int)
{
bytes = BitConverter.GetBytes((int)arg);
}
else if (arg is long)
{
bytes = BitConverter.GetBytes((long)arg);
}
else if (arg is ushort)
{
bytes = BitConverter.GetBytes((ushort)arg);
}
else if (arg is uint)
{
bytes = BitConverter.GetBytes((uint)arg);
}
else if (arg is ulong)
{
bytes = BitConverter.GetBytes((ulong)arg);
}
else if (arg is BigInteger)
{
bytes = ((BigInteger)arg).ToByteArray();
}
else
{
try
{
return HandleOtherFormats(format, arg);
}
catch (FormatException e)
{
throw new FormatException(String.Format("The format of '{0}' is invalid.", format), e);
}
}
switch (thisFmt.ToUpper())
{
// Binary formatting.
case "B":
baseNumber = 2;
break;
case "O":
baseNumber = 8;
break;
case "H":
baseNumber = 16;
break;
// Handle unsupported format strings.
default:
try
{
return HandleOtherFormats(format, arg);
}
catch (FormatException e)
{
throw new FormatException(String.Format("The format of '{0}' is invalid.", format), e);
}
}
// Return a formatted string.
string numericString = String.Empty;
for (int ctr = bytes.GetUpperBound(0); ctr >= bytes.GetLowerBound(0); ctr--)
{
string byteString = Convert.ToString(bytes[ctr], baseNumber);
if (baseNumber == 2)
byteString = new String('0', 8 - byteString.Length) + byteString;
else if (baseNumber == 8)
byteString = new String('0', 4 - byteString.Length) + byteString;
// Base is 16.
else
byteString = new String('0', 2 - byteString.Length) + byteString;
numericString += byteString + " ";
}
return numericString.Trim();
}
private string HandleOtherFormats(string format, object arg)
{
if (arg is IFormattable)
return ((IFormattable)arg).ToString(format, CultureInfo.CurrentCulture);
else if (arg != null)
return arg.ToString();
else
return String.Empty;
}
}
}
@@ -0,0 +1,14 @@
# Commenti con cancelletto, struttura un variabile per riga, tipo chiave|valore (occhio che il separatore è configurato da .cofig come "charSep"); spazi e tabulazioni dovrei trimmarli in acquisizione (qui inseriti per comodità di lettura)
# PARAMETRI della DB600
000|P0_ID |WORD
002|P0_SET_HMI |4BYTE
006|P0_SET_PLC |4BYTE
010|P0_VAL_MAX |4BYTE
014|P0_VAL_MIN |4BYTE
018|P0_UN_MEAS |WORD
020|P1_ID |WORD
022|P1_SET_HMI |4BYTE
026|P1_SET_PLC |4BYTE
030|P1_VAL_MAX |4BYTE
034|P1_VAL_MIN |4BYTE
038|P1_UN_MEAS |WORD
@@ -0,0 +1,14 @@
# Commenti con cancelletto, struttura un variabile per riga, tipo chiave|valore (occhio che il separatore è configurato da .cofig come "charSep"); spazi e tabulazioni dovrei trimmarli in acquisizione (qui inseriti per comodità di lettura)
# PARAMETRI della DB600
000|P0_ID |WORD
002|P0_SET_HMI |4BYTE
006|P0_SET_PLC |4BYTE
010|P0_VAL_MAX |4BYTE
014|P0_VAL_MIN |4BYTE
018|P0_UN_MEAS |WORD
020|P1_ID |WORD
022|P1_SET_HMI |4BYTE
026|P1_SET_PLC |4BYTE
030|P1_VAL_MAX |4BYTE
034|P1_VAL_MIN |4BYTE
038|P1_UN_MEAS |WORD
+53
View File
@@ -0,0 +1,53 @@
Interfaccia con TORRI
DA PLC
- un set di 8 bit di stato macchina
- power on (oppure se vedo spenta...)
- RUN (in lavorazione, semaforo verde)
- contapezzi
- allarme
- in manuale
- un set di 16 byte - 128 allarmi (da confermare)
- ogni bit corrisponde ad un allarme, secondo tabella codificata
- contatori pezzi
- num pz totali
- TempoCiclo ULTIMO pezzo
- bit pezzo buono
- bit pezzo scarto
- bit pezzo da riprendere
- misure
- misura H1
- misura H2
- dati macchina
- override speed
- override feed
- giri mandrino pezzo
- giri mandrino mola
- autospegnimento attivo (0=spento, 1 = contapezzi, 2 = fine pallet 1, 3=finepallet 2, 4 = fine pallet 1 & 2)
- num pezzi a spegnimento (SE condizione 1 con contapezzi)
- tempo teorico allo spegnimento
- bit conferma lettura stringa
- bit conferma lettura inizio commessa
- bit conferma lettura fine commessa
VERSO PLC
bit
- bit che indica "nuovi dati stringa da leggere"
- bit inizio commessa
- bit fuine commessa
stringhe
- codice commessa
- codice articolo
- codice programma
- codice macchina (x controllo coerenza)
- dir programma Fissa su macchcina o parametro
num int
- quantità lotto
ATTENZIONE: letture real devono essere tenute arrotondando alla 4° cifra decimale (NON OLTRE CHE INVENTA)
Avremo 2 DB: 700 scrive PLC, 701 scrive sw esterno
+41
View File
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<!-- optional, add some variables
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<!--
Write events to a file with the date in the filename.
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
</targets>
<rules>
<!-- add your logging rules here -->
<!--
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
<logger name="*" minlevel="Debug" writeTo="f" />
-->
</rules>
</nlog>
File diff suppressed because it is too large Load Diff
+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Siemens_S7_Test
{
static class Program
{
/// <summary>
/// Punto di ingresso principale dell'applicazione.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TestMainForm());
}
}
}
@@ -0,0 +1,36 @@
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-S7")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Test-S7")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[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("a0168cbe-9da5-4e41-82ff-afd39c982717")]
// 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")]
@@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Siemens_S7_Test.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.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() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Siemens_S7_Test.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
@@ -0,0 +1,26 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Siemens_S7_Test.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.5.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;
}
}
}
}
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A0168CBE-9DA5-4E41-82FF-AFD39C982717}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>Siemens_S7_Test</RootNamespace>
<AssemblyName>Siemens-S7-Test</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.7.0\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="S7.Net, Version=0.4.0.0, Culture=neutral, PublicKeyToken=d5812d469e84c693, processorArchitecture=MSIL">
<HintPath>..\packages\S7netplus.0.4.0\lib\net452\S7.Net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Numerics" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BinaryFormatter.cs" />
<Compile Include="connParam.cs" />
<Compile Include="memAddress.cs" />
<Compile Include="TestMainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="TestMainForm.Designer.cs">
<DependentUpon>TestMainForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ThermoObj.cs" />
<Compile Include="utils.cs" />
<EmbeddedResource Include="TestMainForm.resx">
<DependentUpon>TestMainForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<Content Include="Interfaccia.txt" />
<Content Include="logs\.placeholder.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="NLog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="DATA\CONF\MMapR.map">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="DATA\CONF\MMapW.map">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="NLog.xsd">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="resources\MHT\MMapR.map">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="resources\MHT\MMapW.map">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
</Project>
+640
View File
@@ -0,0 +1,640 @@
namespace Siemens_S7_Test
{
partial class TestMainForm
{
/// <summary>
/// Variabile di progettazione necessaria.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Pulire le risorse in uso.
/// </summary>
/// <param name="disposing">ha valore true se le risorse gestite devono essere eliminate, false in caso contrario.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Codice generato da Progettazione Windows Form
/// <summary>
/// Metodo necessario per il supporto della finestra di progettazione. Non modificare
/// il contenuto del metodo con l'editor di codice.
/// </summary>
private void InitializeComponent()
{
this.txtIP = new System.Windows.Forms.TextBox();
this.lblIP = new System.Windows.Forms.Label();
this.cbCpuType = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txtMemArea = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.txtMemSize = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnReadString = new System.Windows.Forms.Button();
this.btnReadDWord = new System.Windows.Forms.Button();
this.btnReadWord = new System.Windows.Forms.Button();
this.btnReadReal = new System.Windows.Forms.Button();
this.btnReadByte = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.txtOut = new System.Windows.Forms.TextBox();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.txtSlot = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.txtRack = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.tslConn = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar();
this.tslRTime = new System.Windows.Forms.ToolStripStatusLabel();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.btnStrWrite = new System.Windows.Forms.Button();
this.btnNumWriteB = new System.Windows.Forms.Button();
this.btnNumWriteDW = new System.Windows.Forms.Button();
this.btnNumWriteW = new System.Windows.Forms.Button();
this.txtWriteVal2 = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.txtWriteVal1 = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.txtWriteAddr2 = new System.Windows.Forms.TextBox();
this.label10 = new System.Windows.Forms.Label();
this.txtWriteAddr1 = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.btnReadStruct = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.statusStrip1.SuspendLayout();
this.groupBox4.SuspendLayout();
this.SuspendLayout();
//
// txtIP
//
this.txtIP.Location = new System.Drawing.Point(85, 23);
this.txtIP.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtIP.Name = "txtIP";
this.txtIP.Size = new System.Drawing.Size(109, 22);
this.txtIP.TabIndex = 0;
this.txtIP.Text = "192.168.0.102";
this.txtIP.TextChanged += new System.EventHandler(this.txtIP_TextChanged);
//
// lblIP
//
this.lblIP.AutoSize = true;
this.lblIP.Location = new System.Drawing.Point(16, 26);
this.lblIP.Name = "lblIP";
this.lblIP.Size = new System.Drawing.Size(63, 17);
this.lblIP.TabIndex = 1;
this.lblIP.Text = "IP ADDR";
//
// cbCpuType
//
this.cbCpuType.FormattingEnabled = true;
this.cbCpuType.Items.AddRange(new object[] {
"S7200",
"S7300",
"S7400",
"S71200",
"S71500"});
this.cbCpuType.Location = new System.Drawing.Point(85, 62);
this.cbCpuType.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.cbCpuType.Name = "cbCpuType";
this.cbCpuType.Size = new System.Drawing.Size(109, 24);
this.cbCpuType.TabIndex = 2;
this.cbCpuType.Text = "S71500";
this.cbCpuType.SelectedIndexChanged += new System.EventHandler(this.cbCpuType_SelectedIndexChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(7, 64);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 17);
this.label1.TabIndex = 3;
this.label1.Text = "CPU Type";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(9, 23);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 17);
this.label2.TabIndex = 5;
this.label2.Text = "MEM AREA";
//
// txtMemArea
//
this.txtMemArea.Location = new System.Drawing.Point(156, 20);
this.txtMemArea.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtMemArea.Name = "txtMemArea";
this.txtMemArea.Size = new System.Drawing.Size(117, 22);
this.txtMemArea.TabIndex = 4;
this.txtMemArea.Text = "DB600.DBB0";
this.txtMemArea.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.txtMemArea.TextChanged += new System.EventHandler(this.txtMemArea_TextChanged);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(9, 80);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(113, 17);
this.label3.TabIndex = 7;
this.label3.Text = "MEM SIZE BYTE";
//
// txtMemSize
//
this.txtMemSize.Location = new System.Drawing.Point(156, 78);
this.txtMemSize.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtMemSize.Name = "txtMemSize";
this.txtMemSize.Size = new System.Drawing.Size(39, 22);
this.txtMemSize.TabIndex = 6;
this.txtMemSize.Text = "2";
this.txtMemSize.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.txtMemSize.TextChanged += new System.EventHandler(this.txtMemSize_TextChanged);
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.btnReadStruct);
this.groupBox1.Controls.Add(this.btnReadString);
this.groupBox1.Controls.Add(this.btnReadDWord);
this.groupBox1.Controls.Add(this.btnReadWord);
this.groupBox1.Controls.Add(this.btnReadReal);
this.groupBox1.Controls.Add(this.btnReadByte);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.txtMemArea);
this.groupBox1.Controls.Add(this.txtMemSize);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Location = new System.Drawing.Point(468, 12);
this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox1.Size = new System.Drawing.Size(387, 105);
this.groupBox1.TabIndex = 8;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Memoria: READ param";
//
// btnReadString
//
this.btnReadString.Location = new System.Drawing.Point(201, 75);
this.btnReadString.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnReadString.Name = "btnReadString";
this.btnReadString.Size = new System.Drawing.Size(101, 25);
this.btnReadString.TabIndex = 11;
this.btnReadString.Text = "R String";
this.btnReadString.UseVisualStyleBackColor = true;
this.btnReadString.Click += new System.EventHandler(this.btnReadString_Click);
//
// btnReadDWord
//
this.btnReadDWord.Location = new System.Drawing.Point(308, 47);
this.btnReadDWord.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnReadDWord.Name = "btnReadDWord";
this.btnReadDWord.Size = new System.Drawing.Size(72, 25);
this.btnReadDWord.TabIndex = 10;
this.btnReadDWord.Text = "R DW";
this.btnReadDWord.TextImageRelation = System.Windows.Forms.TextImageRelation.TextAboveImage;
this.btnReadDWord.UseVisualStyleBackColor = true;
this.btnReadDWord.Click += new System.EventHandler(this.btnReadDWord_Click);
//
// btnReadWord
//
this.btnReadWord.Location = new System.Drawing.Point(308, 18);
this.btnReadWord.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnReadWord.Name = "btnReadWord";
this.btnReadWord.Size = new System.Drawing.Size(72, 25);
this.btnReadWord.TabIndex = 10;
this.btnReadWord.Text = "R W";
this.btnReadWord.UseVisualStyleBackColor = true;
this.btnReadWord.Click += new System.EventHandler(this.btnReadWord_Click);
//
// btnReadReal
//
this.btnReadReal.Location = new System.Drawing.Point(235, 48);
this.btnReadReal.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnReadReal.Name = "btnReadReal";
this.btnReadReal.Size = new System.Drawing.Size(67, 25);
this.btnReadReal.TabIndex = 9;
this.btnReadReal.Text = "R REAL";
this.btnReadReal.UseVisualStyleBackColor = true;
this.btnReadReal.Click += new System.EventHandler(this.btnReadReal_Click);
//
// btnReadByte
//
this.btnReadByte.Location = new System.Drawing.Point(156, 47);
this.btnReadByte.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnReadByte.Name = "btnReadByte";
this.btnReadByte.Size = new System.Drawing.Size(73, 25);
this.btnReadByte.TabIndex = 9;
this.btnReadByte.Text = "R Byte";
this.btnReadByte.UseVisualStyleBackColor = true;
this.btnReadByte.Click += new System.EventHandler(this.btnReadByte_Click);
//
// textBox1
//
this.textBox1.BackColor = System.Drawing.SystemColors.Menu;
this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox1.Location = new System.Drawing.Point(12, 44);
this.textBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(127, 33);
this.textBox1.TabIndex = 8;
this.textBox1.Text = "Indicare tipo memoria e size del tipo";
//
// groupBox2
//
this.groupBox2.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.groupBox2.AutoSize = true;
this.groupBox2.Controls.Add(this.txtOut);
this.groupBox2.Location = new System.Drawing.Point(12, 190);
this.groupBox2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox2.Size = new System.Drawing.Size(843, 402);
this.groupBox2.TabIndex = 9;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Risultati";
//
// txtOut
//
this.txtOut.BackColor = System.Drawing.SystemColors.Desktop;
this.txtOut.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtOut.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.txtOut.ForeColor = System.Drawing.Color.Yellow;
this.txtOut.Location = new System.Drawing.Point(3, 17);
this.txtOut.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtOut.Multiline = true;
this.txtOut.Name = "txtOut";
this.txtOut.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtOut.Size = new System.Drawing.Size(837, 383);
this.txtOut.TabIndex = 0;
this.txtOut.Text = "...";
//
// groupBox3
//
this.groupBox3.Controls.Add(this.textBox2);
this.groupBox3.Controls.Add(this.label6);
this.groupBox3.Controls.Add(this.txtSlot);
this.groupBox3.Controls.Add(this.label5);
this.groupBox3.Controls.Add(this.txtRack);
this.groupBox3.Controls.Add(this.label4);
this.groupBox3.Controls.Add(this.cbCpuType);
this.groupBox3.Controls.Add(this.txtIP);
this.groupBox3.Controls.Add(this.lblIP);
this.groupBox3.Controls.Add(this.label1);
this.groupBox3.Location = new System.Drawing.Point(12, 12);
this.groupBox3.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox3.Size = new System.Drawing.Size(448, 105);
this.groupBox3.TabIndex = 10;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "Parametri PLC";
//
// textBox2
//
this.textBox2.BackColor = System.Drawing.SystemColors.Menu;
this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.textBox2.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBox2.Location = new System.Drawing.Point(301, 38);
this.textBox2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(140, 48);
this.textBox2.TabIndex = 7;
this.textBox2.Text = "S7-1200/S7-1500: 0/1\r\nS7-300/S7-400: 0/2\r\nSlot > 0 se eth ext";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(301, 14);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(114, 17);
this.label6.TabIndex = 6;
this.label6.Text = "Note Rack / Slot:";
//
// txtSlot
//
this.txtSlot.Location = new System.Drawing.Point(253, 62);
this.txtSlot.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtSlot.Name = "txtSlot";
this.txtSlot.Size = new System.Drawing.Size(41, 22);
this.txtSlot.TabIndex = 5;
this.txtSlot.Text = "1";
this.txtSlot.TextChanged += new System.EventHandler(this.txtSlot_TextChanged);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(208, 64);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(32, 17);
this.label5.TabIndex = 4;
this.label5.Text = "Slot";
//
// txtRack
//
this.txtRack.Location = new System.Drawing.Point(253, 23);
this.txtRack.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtRack.Name = "txtRack";
this.txtRack.Size = new System.Drawing.Size(41, 22);
this.txtRack.TabIndex = 5;
this.txtRack.Text = "0";
this.txtRack.TextChanged += new System.EventHandler(this.txtRack_TextChanged);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(208, 26);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(40, 17);
this.label4.TabIndex = 4;
this.label4.Text = "Rack";
//
// statusStrip1
//
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.tslConn,
this.toolStripStatusLabel1,
this.toolStripProgressBar1,
this.tslRTime});
this.statusStrip1.Location = new System.Drawing.Point(0, 596);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 13, 0);
this.statusStrip1.Size = new System.Drawing.Size(869, 28);
this.statusStrip1.TabIndex = 11;
this.statusStrip1.Text = "statusStrip1";
//
// tslConn
//
this.tslConn.Name = "tslConn";
this.tslConn.Size = new System.Drawing.Size(72, 22);
this.tslConn.Text = "Conn: ND";
//
// toolStripStatusLabel1
//
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new System.Drawing.Size(13, 22);
this.toolStripStatusLabel1.Text = "|";
//
// toolStripProgressBar1
//
this.toolStripProgressBar1.Name = "toolStripProgressBar1";
this.toolStripProgressBar1.Size = new System.Drawing.Size(100, 20);
//
// tslRTime
//
this.tslRTime.Name = "tslRTime";
this.tslRTime.Size = new System.Drawing.Size(37, 22);
this.tslRTime.Text = "...ms";
//
// groupBox4
//
this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox4.Controls.Add(this.btnStrWrite);
this.groupBox4.Controls.Add(this.btnNumWriteB);
this.groupBox4.Controls.Add(this.btnNumWriteDW);
this.groupBox4.Controls.Add(this.btnNumWriteW);
this.groupBox4.Controls.Add(this.txtWriteVal2);
this.groupBox4.Controls.Add(this.label9);
this.groupBox4.Controls.Add(this.txtWriteVal1);
this.groupBox4.Controls.Add(this.label8);
this.groupBox4.Controls.Add(this.txtWriteAddr2);
this.groupBox4.Controls.Add(this.label10);
this.groupBox4.Controls.Add(this.txtWriteAddr1);
this.groupBox4.Controls.Add(this.label7);
this.groupBox4.Location = new System.Drawing.Point(12, 117);
this.groupBox4.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox4.Size = new System.Drawing.Size(843, 71);
this.groupBox4.TabIndex = 12;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Memoria: WRITE param";
//
// btnStrWrite
//
this.btnStrWrite.Location = new System.Drawing.Point(799, 25);
this.btnStrWrite.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnStrWrite.Name = "btnStrWrite";
this.btnStrWrite.Size = new System.Drawing.Size(41, 23);
this.btnStrWrite.TabIndex = 10;
this.btnStrWrite.Text = "SW";
this.btnStrWrite.UseVisualStyleBackColor = true;
this.btnStrWrite.Click += new System.EventHandler(this.btnStrWrite_Click);
//
// btnNumWriteB
//
this.btnNumWriteB.Location = new System.Drawing.Point(329, 5);
this.btnNumWriteB.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnNumWriteB.Name = "btnNumWriteB";
this.btnNumWriteB.Size = new System.Drawing.Size(48, 23);
this.btnNumWriteB.TabIndex = 10;
this.btnNumWriteB.Text = "B";
this.btnNumWriteB.UseVisualStyleBackColor = true;
this.btnNumWriteB.Click += new System.EventHandler(this.btnNumWriteB_Click);
//
// btnNumWriteDW
//
this.btnNumWriteDW.Location = new System.Drawing.Point(329, 44);
this.btnNumWriteDW.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnNumWriteDW.Name = "btnNumWriteDW";
this.btnNumWriteDW.Size = new System.Drawing.Size(48, 23);
this.btnNumWriteDW.TabIndex = 10;
this.btnNumWriteDW.Text = "DW";
this.btnNumWriteDW.UseVisualStyleBackColor = true;
this.btnNumWriteDW.Click += new System.EventHandler(this.btnNumWriteDW_Click);
//
// btnNumWriteW
//
this.btnNumWriteW.Location = new System.Drawing.Point(329, 23);
this.btnNumWriteW.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnNumWriteW.Name = "btnNumWriteW";
this.btnNumWriteW.Size = new System.Drawing.Size(48, 23);
this.btnNumWriteW.TabIndex = 10;
this.btnNumWriteW.Text = "W";
this.btnNumWriteW.UseVisualStyleBackColor = true;
this.btnNumWriteW.Click += new System.EventHandler(this.btnNumWriteW_Click);
//
// txtWriteVal2
//
this.txtWriteVal2.Location = new System.Drawing.Point(612, 25);
this.txtWriteVal2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtWriteVal2.Name = "txtWriteVal2";
this.txtWriteVal2.Size = new System.Drawing.Size(187, 22);
this.txtWriteVal2.TabIndex = 8;
this.txtWriteVal2.Text = "SAMUELEL";
this.txtWriteVal2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// label9
//
this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(571, 27);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(36, 17);
this.label9.TabIndex = 9;
this.label9.Text = "STR";
//
// txtWriteVal1
//
this.txtWriteVal1.Location = new System.Drawing.Point(237, 25);
this.txtWriteVal1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtWriteVal1.Name = "txtWriteVal1";
this.txtWriteVal1.Size = new System.Drawing.Size(85, 22);
this.txtWriteVal1.TabIndex = 8;
this.txtWriteVal1.Text = "987654321";
this.txtWriteVal1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(197, 27);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(39, 17);
this.label8.TabIndex = 9;
this.label8.Text = "NUM";
//
// txtWriteAddr2
//
this.txtWriteAddr2.Location = new System.Drawing.Point(448, 25);
this.txtWriteAddr2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtWriteAddr2.Name = "txtWriteAddr2";
this.txtWriteAddr2.Size = new System.Drawing.Size(116, 22);
this.txtWriteAddr2.TabIndex = 6;
this.txtWriteAddr2.Text = "DB600.DBB2";
this.txtWriteAddr2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// label10
//
this.label10.AutoSize = true;
this.label10.Location = new System.Drawing.Point(389, 27);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(59, 17);
this.label10.TabIndex = 7;
this.label10.Text = "ADDR 2";
//
// txtWriteAddr1
//
this.txtWriteAddr1.Location = new System.Drawing.Point(71, 25);
this.txtWriteAddr1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.txtWriteAddr1.Name = "txtWriteAddr1";
this.txtWriteAddr1.Size = new System.Drawing.Size(123, 22);
this.txtWriteAddr1.TabIndex = 6;
this.txtWriteAddr1.Text = "DB600.DBB0";
this.txtWriteAddr1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(5, 27);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(59, 17);
this.label7.TabIndex = 7;
this.label7.Text = "ADDR 1";
//
// btnReadStruct
//
this.btnReadStruct.Location = new System.Drawing.Point(308, 75);
this.btnReadStruct.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.btnReadStruct.Name = "btnReadStruct";
this.btnReadStruct.Size = new System.Drawing.Size(72, 25);
this.btnReadStruct.TabIndex = 12;
this.btnReadStruct.Text = "R Struc";
this.btnReadStruct.TextImageRelation = System.Windows.Forms.TextImageRelation.TextAboveImage;
this.btnReadStruct.UseVisualStyleBackColor = true;
this.btnReadStruct.Click += new System.EventHandler(this.btnReadStruct_Click);
//
// TestMainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(869, 624);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "TestMainForm";
this.Text = "SIEMENS S7 TEST";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.groupBox4.ResumeLayout(false);
this.groupBox4.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txtIP;
private System.Windows.Forms.Label lblIP;
private System.Windows.Forms.ComboBox cbCpuType;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtMemArea;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtMemSize;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.TextBox txtOut;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.TextBox txtSlot;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox txtRack;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button btnReadByte;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel tslConn;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
private System.Windows.Forms.ToolStripProgressBar toolStripProgressBar1;
private System.Windows.Forms.ToolStripStatusLabel tslRTime;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Button btnStrWrite;
private System.Windows.Forms.Button btnNumWriteW;
private System.Windows.Forms.TextBox txtWriteVal2;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox txtWriteVal1;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.TextBox txtWriteAddr1;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox txtWriteAddr2;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Button btnReadString;
private System.Windows.Forms.Button btnReadWord;
private System.Windows.Forms.Button btnReadDWord;
private System.Windows.Forms.Button btnReadReal;
private System.Windows.Forms.Button btnNumWriteB;
private System.Windows.Forms.Button btnNumWriteDW;
private System.Windows.Forms.Button btnReadStruct;
}
}
+727
View File
@@ -0,0 +1,727 @@
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;
using S7.Net;
using System.Net.NetworkInformation;
using System.Net;
using NLog;
using System.Diagnostics;
namespace Siemens_S7_Test
{
public partial class TestMainForm : Form
{
/// <summary>
/// Configurazione valori da LEGGERE dal PLC
/// </summary>
public otherData[] memMapR;
/// <summary>
/// Configurazione valori da SCRIVERE nel PLC
/// </summary>
public otherData[] memMapW;
/// <summary>
/// Byte dimensione buffer dati memoria (da file map)
/// </summary>
public int numByte = 0;
/// <summary>
/// Lungh massima stringhe
/// </summary>
protected int maxStrChar = 20;
/// <summary>
/// Oggetto PLC da ri-utilizzare...
/// </summary>
protected Plc currPLC;
/// <summary>
/// indica se serva refresh parametri e quindi PLC...
/// </summary>
bool needRefresh = true;
/// <summary>
/// Oggetto cronometro x test vari...
/// </summary>
protected Stopwatch sw = new Stopwatch();
/// <summary>
/// parametri di connessione
/// </summary>
protected connParam parametri;
/// <summary>
/// titolo x log/debug
/// </summary>
protected string titolo = "";
/// <summary>
/// contenuto x log/debug
/// </summary>
protected string contenuto = "";
/// <summary>
/// oggetto logging
/// </summary>
public static Logger lg;
public TestMainForm()
{
InitializeComponent();
myInit();
}
/// <summary>
/// inizializzo
/// </summary>
private void myInit()
{
lg = LogManager.GetCurrentClassLogger();
// inizializzo parametri...
parametri = new connParam()
{
ipAdrr = "127.0.0.1",
tipoCpu = CpuType.S7200,
slot = 0,
rack = 0
};
setParamPlc();
}
/// <summary>
/// Imposto parametri PLC
/// </summary>
private void setParamPlc()
{
txtOut.Text = "";
// SE è necessario refresh...
if (needRefresh)
{
lg.Info("Refreshing connection...");
try
{
short.TryParse(txtSlot.Text, out parametri.slot);
short.TryParse(txtRack.Text, out parametri.rack);
parametri.tipoCpu = (CpuType)Enum.Parse(typeof(CpuType), cbCpuType.SelectedItem.ToString());
parametri.ipAdrr = txtIP.Text.Trim();
titolo = "PARAM PLC (pre connect)";
contenuto = string.Format("IP: {0}{1}", parametri.ipAdrr, Environment.NewLine);
contenuto += string.Format("CPU: {0}{1}", parametri.tipoCpu, Environment.NewLine);
contenuto += string.Format("RACK: {0}{1}", parametri.rack, Environment.NewLine);
contenuto += string.Format("SLOT: {0}", parametri.slot, Environment.NewLine);
}
catch (Exception exc)
{
lg.Error(exc, "Errore in parse parametri");
}
// ora tento avvio PLC... SE PING OK...
if (testPing() == IPStatus.Success)
{
try
{
currPLC = new Plc(parametri.tipoCpu, parametri.ipAdrr, parametri.rack, parametri.slot);
currPLC.Open();
if (currPLC.IsConnected) titolo = "CONNESSIONE AVVENUTA";
}
catch (Exception exc)
{
lg.Error(exc, "Errore in INIT PLC");
}
needRefresh = false;
}
// carico conf vettore memoria...
loadMemConf();
// mostra output
showOut(titolo, contenuto);
}
}
/// <summary>
/// Caricamento conf memoria DB del SIEMENS
/// </summary>
private void loadMemConf()
{
// carico conf memoria
utils.loadConfFile(ref memMapR, filePath("MMapR"), 1, ref numByte);
utils.loadConfFile(ref memMapW, filePath("MMapW"), 1, ref numByte);
}
/// <summary>
/// Restituisce path completo file da chaive configurazione
/// </summary>
/// <param name="keyFile">chaive conf x file richiesto</param>
/// <returns></returns>
protected string filePath(string keyFile)
{
return string.Format(@"{0}\{1}", utils.confDir, utils.CRS(keyFile));
}
/// <summary>
/// Esecuzione lettura!
/// </summary>
private void eseguiLetturaByte()
{
sw.Restart();
if (testCncConn())
{
// decodifico memoria...
memAddress memoria = new memAddress(txtMemArea.Text);
int numByte = 1;
int.TryParse(txtMemSize.Text, out numByte);
//var readVal = currPLC.Read("DB600.DBD0");
Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
sw.Stop();
tslRTime.Text = string.Format("{0}", sw.Elapsed);
titolo = string.Format("READ BLOCK MEM BYTE: {0} --> {1} byte", txtMemArea.Text, numByte);
contenuto = "";
string byteVal = "";
for (int i = 0; i < memByteRead.Length; i++)
{
byteVal = Convert.ToString(memByteRead[i], 2).PadLeft(8, '0');
contenuto += string.Format("B{0:000}: {1} | {2}{3}", i, byteVal, memByteRead[i], Environment.NewLine);
}
showOut(titolo, contenuto);
}
}
/// <summary>
/// Esecuzione lettura WORD!
/// </summary>
private void eseguiLetturaWord()
{
sw.Restart();
if (testCncConn())
{
// decodifico memoria...
memAddress memoria = new memAddress(txtMemArea.Text);
int numByte = 1;
int.TryParse(txtMemSize.Text, out numByte);
Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
sw.Stop();
tslRTime.Text = string.Format("{0}", sw.Elapsed);
titolo = string.Format("READ BLOCK MEM WORD: {0} --> {1} byte", txtMemArea.Text, numByte);
contenuto = "";
ushort shortVal = 0;
string byteValA = "";
string byteValB = "";
for (int i = 0; i < memByteRead.Length / 2; i++)
{
byteValA = Convert.ToString(memByteRead[i * 2], 2).PadLeft(8, '0');
byteValB = Convert.ToString(memByteRead[i * 2 + 1], 2).PadLeft(8, '0');
shortVal = S7.Net.Types.Word.FromByteArray(memByteRead.Skip(2 * i).Take(2).ToArray());
contenuto += string.Format("W{0:000}: {1} | {2}-{3}{4}", i, shortVal, byteValA, byteValB, Environment.NewLine);
}
showOut(titolo, contenuto);
}
}
/// <summary>
/// Esecuzione lettura come struct
/// </summary>
private void eseguiLetturaStruct()
{
sw.Restart();
if (testCncConn())
{
int numByte = 1;
int.TryParse(txtMemSize.Text, out numByte);
titolo = string.Format("READ STRUCT: {0} --> {1} byte", txtMemArea.Text, numByte);
//leggo a ciclo una singola struct...
int numPar = 50;
ThermoParam objPar = new ThermoParam();
List<ThermoParam> ElencoParametri = new List<ThermoParam>();
for (int i = 0; i < numPar; i++)
{
objPar = (ThermoParam)currPLC.ReadStruct<ThermoParam>(600, i * 20);
ElencoParametri.Add(objPar);
}
sw.Stop();
tslRTime.Text = string.Format("{0}", sw.Elapsed);
foreach (var item in ElencoParametri)
{
contenuto += $"Id: {item.Id}{Environment.NewLine}";
contenuto += $"SetpointHMI: {item.SetpointHMI}{Environment.NewLine}";
contenuto += $"SetpointPLC: {item.SetpointPLC}{Environment.NewLine}";
contenuto += $"ValMin: {item.ValMin}{Environment.NewLine}";
contenuto += $"ValMax: {item.ValMax}{Environment.NewLine}";
contenuto += $"UnitMeasure: {item.UnitMeasure}{Environment.NewLine}";
contenuto += $"---------{Environment.NewLine}";
}
#if false
// decodifico memoria...
memAddress memoria = new memAddress(txtMemArea.Text);
Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
contenuto = "";
ushort shortVal = 0;
string byteValA = "";
string byteValB = "";
for (int i = 0; i < memByteRead.Length / 2; i++)
{
byteValA = Convert.ToString(memByteRead[i * 2], 2).PadLeft(8, '0');
byteValB = Convert.ToString(memByteRead[i * 2 + 1], 2).PadLeft(8, '0');
shortVal = S7.Net.Types.Word.FromByteArray(memByteRead.Skip(2 * i).Take(2).ToArray());
contenuto += string.Format("W{0:000}: {1} | {2}-{3}{4}", i, shortVal, byteValA, byteValB, Environment.NewLine);
}
#endif
showOut(titolo, contenuto);
}
}
/// <summary>
/// Esecuzione lettura DWORD!
/// </summary>
private void eseguiLetturaDWord()
{
sw.Restart();
if (testCncConn())
{
// decodifico memoria...
memAddress memoria = new memAddress(txtMemArea.Text);
int numByte = 1;
int.TryParse(txtMemSize.Text, out numByte);
Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
sw.Stop();
tslRTime.Text = string.Format("{0}", sw.Elapsed);
titolo = string.Format("READ BLOCK MEM WORD: {0} --> {1} byte", txtMemArea.Text, numByte);
contenuto = "";
uint intVal = 0;
string byteValA = "";
string byteValB = "";
string byteValC = "";
string byteValD = "";
for (int i = 0; i < memByteRead.Length / 4; i++)
{
byteValA = Convert.ToString(memByteRead[i * 4], 2).PadLeft(8, '0');
byteValB = Convert.ToString(memByteRead[i * 4 + 1], 2).PadLeft(8, '0');
byteValC = Convert.ToString(memByteRead[i * 4 + 2], 2).PadLeft(8, '0');
byteValD = Convert.ToString(memByteRead[i * 4 + 3], 2).PadLeft(8, '0');
intVal = S7.Net.Types.DWord.FromByteArray(memByteRead.Skip(4 * i).Take(4).ToArray());
contenuto += string.Format("W{0:000}: {1} | {2}-{3}-{4}-{5}{6}", i, intVal, byteValA, byteValB, byteValC, byteValD, Environment.NewLine);
}
showOut(titolo, contenuto);
}
}
/// <summary>
/// Esecuzione lettura Real!
/// </summary>
private void eseguiLetturaReal()
{
sw.Restart();
if (testCncConn())
{
// decodifico memoria...
memAddress memoria = new memAddress(txtMemArea.Text);
int numByte = 1;
int.TryParse(txtMemSize.Text, out numByte);
Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
titolo = string.Format("READ BLOCK MEM WORD: {0} --> {1} byte", txtMemArea.Text, numByte);
contenuto = "";
double realVal = 0;
string byteValA = "";
string byteValB = "";
string byteValC = "";
string byteValD = "";
for (int i = 0; i < memByteRead.Length / 4; i++)
{
byteValA = Convert.ToString(memByteRead[i * 4], 2).PadLeft(8, '0');
byteValB = Convert.ToString(memByteRead[i * 4 + 1], 2).PadLeft(8, '0');
byteValC = Convert.ToString(memByteRead[i * 4 + 2], 2).PadLeft(8, '0');
byteValD = Convert.ToString(memByteRead[i * 4 + 3], 2).PadLeft(8, '0');
realVal = S7.Net.Types.Double.FromByteArray(memByteRead.Skip(4 * i).Take(4).ToArray());
contenuto += string.Format("W{0:000}: {1} | {2}-{3}-{4}-{5}{6}", i, realVal, byteValA, byteValB, byteValC, byteValD, Environment.NewLine);
}
showOut(titolo, contenuto);
}
sw.Stop();
tslRTime.Text = string.Format("{0}", sw.Elapsed);
}
/// <summary>
/// Esecuzione lettura tipo STRING!
/// </summary>
private void eseguiLetturaString()
{
sw.Restart();
if (testCncConn())
{
// decodifico memoria...
memAddress memoria = new memAddress(txtMemArea.Text);
int numByte = 1;
int.TryParse(txtMemSize.Text, out numByte);
Byte[] memByteRead = currPLC.ReadBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, numByte);
sw.Stop();
tslRTime.Text = string.Format("{0}", sw.Elapsed);
titolo = string.Format("READ BLOCK MEM STRING: {0} --> {1} byte", txtMemArea.Text, numByte);
contenuto = "";
string byteVal = "";
// i primi 2 byte sono LUNGHEZZA MAX e lungh effettiva quindi setto il NUM BYTE....
for (int i = 0; i < 2; i++)
{
byteVal = Convert.ToString(memByteRead[i], 2).PadLeft(8, '0');
contenuto += string.Format("B{0:000}: {1} | {2}{3}", i, byteVal, memByteRead[i], Environment.NewLine);
}
// prendo 2° valore (num max valori)
numByte = memByteRead[1];
// poi prendo la stringa...
string outVal = "";
for (int i = 2; i < numByte + 2; i++)
{
outVal += Char.ConvertFromUtf32(memByteRead[i]);
}
contenuto += string.Format("{0}{1}", outVal, Environment.NewLine);
showOut(titolo, contenuto);
}
}
/// <summary>
/// Test connessione CNC
/// </summary>
/// <returns></returns>
private bool testCncConn()
{
bool answ = false;
IPStatus pingStatus = testPing();
// se passa il ping faccio il resto...
if (pingStatus != IPStatus.Success)
{
titolo = "Errore ping";
contenuto = string.Format("Reply Status per {0}: {1}", parametri.ipAdrr, pingStatus);
showOut(titolo, contenuto);
}
else
{
if (!currPLC.IsConnected) currPLC.Open();
bool excludeAvailable = true;
if (excludeAvailable)
{
if (!currPLC.IsConnected)
{
titolo = "Errore connessione";
//contenuto = string.Format("{0} | {1}", currPLC.LastErrorCode, currPLC.LastErrorString);
//currPLC.ClearLastError();
contenuto = "!currPLC.IsConnected";
showOut(titolo, contenuto);
tslConn.Text = "NO Connection";
}
else
{
tslConn.Text = "Connection OK";
answ = true;
}
}
else
{
if (!currPLC.IsAvailable)
{
titolo = "Errore Disponibilità";
//contenuto = string.Format("{0} | {1}", currPLC.LastErrorCode, currPLC.LastErrorString);
//currPLC.ClearLastError();
contenuto = "!currPLC.IsAvailable";
showOut(titolo, contenuto);
}
else
{
if (!currPLC.IsConnected)
{
titolo = "Errore connessione";
//contenuto = string.Format("{0} | {1}", currPLC.LastErrorCode, currPLC.LastErrorString);
//currPLC.ClearLastError();
contenuto = "!currPLC.IsConnected";
showOut(titolo, contenuto);
tslConn.Text = "NO Connection";
}
else
{
tslConn.Text = "Connection OK";
answ = true;
}
}
}
}
return answ;
}
/// <summary>
/// test ping all'indirizzo impostato nei parametri
/// </summary>
/// <returns></returns>
private IPStatus testPing()
{
IPStatus answ = IPStatus.Unknown; ;
IPAddress address;
PingReply reply;
Ping pingSender = new Ping();
address = IPAddress.Loopback;
IPAddress.TryParse(parametri.ipAdrr, out address);
reply = pingSender.Send(address, 100);
answ = reply.Status;
return answ;
}
/// <summary>
/// formatta un numero in forma binaria 0/1 a 32 bit (4 byte)
/// </summary>
/// <param name="valore"></param>
/// <returns></returns>
public static string binaryForm(int valore)
{
string answ = "";
try
{
answ = string.Format(new BinaryFormatter(), "{0:B}", valore);
}
catch
{ }
return answ;
}
protected void showOut(string title, string content)
{
string outText = "";
// a video
outText += string.Format("{0}--------------------------------------------------------------------------------------{0}", Environment.NewLine);
outText += string.Format("- {0}{1}", title, Environment.NewLine);
outText += string.Format("--------------------------------------------------------------------------------------{0}", Environment.NewLine);
outText += string.Format("{0}{1}", content, Environment.NewLine);
outText += string.Format("--------------------------------------------------------------------------------------{0}{0}", Environment.NewLine);
// aggiorno visualizzazione
txtOut.Text += outText;
// loggo!
lg.Info(outText);
}
/// <summary>
/// Esecuzione SCRITTURA Byte!
/// </summary>
private void eseguiScritturaByte()
{
sw.Restart();
if (testCncConn())
{
// decodifico memoria...
memAddress memoria = new memAddress(txtWriteAddr1.Text);
byte num2write = 0;
string val2write = txtWriteVal2.Text;
byte.TryParse(txtWriteVal1.Text, out num2write);
byte[] DB_Byte = new byte[1];
DB_Byte[0] = num2write;
currPLC.WriteBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, DB_Byte);
titolo = string.Format("WRITE BLOCK MEM: {0}", txtWriteAddr1.Text);
contenuto = "";
contenuto += string.Format("DT: {0} | DbNum: {1} | indiceMem: {2} | num2write: {3}{4}{4}", DataType.DataBlock, memoria.DbNum, memoria.indiceMem, num2write, Environment.NewLine);
string byteVal = "";
for (int i = 0; i < DB_Byte.Length; i++)
{
byteVal = Convert.ToString(DB_Byte[i], 2).PadLeft(8, '0');
contenuto += string.Format("B{0:000}: {1} | {2}{3}", i, byteVal, DB_Byte[i], Environment.NewLine);
}
showOut(titolo, contenuto);
}
sw.Stop();
tslRTime.Text = string.Format("{0}", sw.Elapsed);
}
/// <summary>
/// Esecuzione SCRITTURA WORD!
/// </summary>
private void eseguiScritturaWord()
{
sw.Restart();
if (testCncConn())
{
// decodifico memoria...
memAddress memoria = new memAddress(txtWriteAddr1.Text);
UInt16 num2write = 0;
string val2write = txtWriteVal2.Text;
UInt16.TryParse(txtWriteVal1.Text, out num2write);
byte[] DB_Byte = new byte[2];
S7.Net.Types.Word.ToByteArray(num2write).CopyTo(DB_Byte, 0);
currPLC.WriteBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, DB_Byte);
titolo = string.Format("WRITE BLOCK MEM: {0}", txtWriteAddr1.Text);
contenuto = "";
contenuto += string.Format("DT: {0} | DbNum: {1} | indiceMem: {2} | num2write: {3}{4}{4}", DataType.DataBlock, memoria.DbNum, memoria.indiceMem, num2write, Environment.NewLine);
string byteVal = "";
for (int i = 0; i < DB_Byte.Length; i++)
{
byteVal = Convert.ToString(DB_Byte[i], 2).PadLeft(8, '0');
contenuto += string.Format("B{0:000}: {1} | {2}{3}", i, byteVal, DB_Byte[i], Environment.NewLine);
}
showOut(titolo, contenuto);
}
sw.Stop();
tslRTime.Text = string.Format("{0}", sw.Elapsed);
}
/// <summary>
/// Esecuzione SCRITTURA DWORD!
/// </summary>
private void eseguiScritturaDWord()
{
sw.Restart();
if (testCncConn())
{
// decodifico memoria...
memAddress memoria = new memAddress(txtWriteAddr1.Text);
uint num2write = 0;
string val2write = txtWriteVal2.Text;
uint.TryParse(txtWriteVal1.Text, out num2write);
byte[] DB_Byte = new byte[4];
S7.Net.Types.DWord.ToByteArray(num2write).CopyTo(DB_Byte, 0);
currPLC.WriteBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, DB_Byte);
titolo = string.Format("WRITE BLOCK MEM: {0}", txtWriteAddr1.Text);
contenuto = "";
contenuto += string.Format("DT: {0} | DbNum: {1} | indiceMem: {2} | num2write: {3}{4}{4}", DataType.DataBlock, memoria.DbNum, memoria.indiceMem, num2write, Environment.NewLine);
string byteVal = "";
for (int i = 0; i < DB_Byte.Length; i++)
{
byteVal = Convert.ToString(DB_Byte[i], 2).PadLeft(8, '0');
contenuto += string.Format("B{0:000}: {1} | {2}{3}", i, byteVal, DB_Byte[i], Environment.NewLine);
}
showOut(titolo, contenuto);
}
sw.Stop();
tslRTime.Text = string.Format("{0}", sw.Elapsed);
}
/// <summary>
/// Esecuzione SCRITTURA String!
/// </summary>
private void eseguiScritturaString()
{
sw.Restart();
if (testCncConn())
{
// decodifico memoria...
memAddress memoria = new memAddress(txtWriteAddr2.Text);
int num2write = 0;
// verifico di no sforare con lunghezza
string val2write = txtWriteVal2.Text;
// se è maggiore di maxStrChar TRIMMA:::
if (val2write.Length > maxStrChar)
{
val2write = val2write.Substring(0, 20);
}
// scambio spazi con underscore... e MAIUSCOLO!!!
val2write = val2write.Replace(' ', '_').ToUpper();
num2write = val2write.Length;
byte[] DB_Byte = new byte[maxStrChar + 2];
// primi 2 byte sono 20 (fix) e lung effettiva...
DB_Byte[0] = 20;
DB_Byte[1] = (byte)num2write;
// converto 1-1 i char in byte...
for (int i = 0; i < num2write; i++)
{
DB_Byte[2 + i] = (byte)(val2write[i]);
}
currPLC.WriteBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, DB_Byte);
titolo = string.Format("WRITE BLOCK MEM: {0}", txtWriteAddr1.Text);
contenuto = "";
contenuto += string.Format("DT: {0} | DbNum: {1} | indiceMem: {2} | stringa: {3}{4}{4}", DataType.DataBlock, memoria.DbNum, memoria.indiceMem, num2write, Environment.NewLine);
showOut(titolo, contenuto);
}
sw.Stop();
tslRTime.Text = string.Format("{0}", sw.Elapsed);
}
/// <summary>
/// Scrivo memoria tipo STRING
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStrWrite_Click(object sender, EventArgs e)
{
setParamPlc();
eseguiScritturaString();
}
private void txtIP_TextChanged(object sender, EventArgs e)
{
needRefresh = true;
}
private void txtRack_TextChanged(object sender, EventArgs e)
{
needRefresh = true;
}
private void cbCpuType_SelectedIndexChanged(object sender, EventArgs e)
{
needRefresh = true;
}
private void txtSlot_TextChanged(object sender, EventArgs e)
{
needRefresh = true;
}
private void txtMemArea_TextChanged(object sender, EventArgs e)
{
needRefresh = true;
}
private void txtMemSize_TextChanged(object sender, EventArgs e)
{
needRefresh = true;
}
private void btnReadByte_Click(object sender, EventArgs e)
{
setParamPlc();
eseguiLetturaByte();
}
private void btnReadWord_Click(object sender, EventArgs e)
{
setParamPlc();
eseguiLetturaWord();
}
private void btnReadString_Click(object sender, EventArgs e)
{
setParamPlc();
eseguiLetturaString();
}
private void btnReadDWord_Click(object sender, EventArgs e)
{
setParamPlc();
eseguiLetturaDWord();
}
/// <summary>
/// Lettura real
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnReadReal_Click(object sender, EventArgs e)
{
setParamPlc();
eseguiLetturaReal();
}
private void btnNumWriteB_Click(object sender, EventArgs e)
{
setParamPlc();
eseguiScritturaByte();
}
private void btnNumWriteDW_Click(object sender, EventArgs e)
{
setParamPlc();
eseguiScritturaDWord();
}
private void btnNumWriteW_Click(object sender, EventArgs e)
{
setParamPlc();
eseguiScritturaWord();
}
private void btnReadStruct_Click(object sender, EventArgs e)
{
// effettua lettura intera struct...
setParamPlc();
eseguiLetturaStruct();
}
}
}
+123
View File
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
+40
View File
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Siemens_S7_Test
{
public struct ThermoParam
{
public ushort Id;
public UInt32 SetpointHMI;
public UInt32 SetpointPLC;
public UInt32 ValMax;
public UInt32 ValMin;
public ushort UnitMeasure;
}
public class ParamsList
{
public ThermoParam par_000 { get; set; }
public ThermoParam par_001 { get; set; }
public ThermoParam par_002 { get; set; }
//public List<ThermoParam> Elenco { get; set; }
//public ParamsList()
//{
// Elenco = new List<ThermoParam>();
// ThermoParam currParam = new ThermoParam();
// // inizializzo subito coi valori...
// for (ushort i = 0; i < 2; i++)
// {
// currParam = new ThermoParam()
// {
// Id = i
// };
// Elenco.Add(currParam);
// }
//}
}
}
+18
View File
@@ -0,0 +1,18 @@
using S7.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Siemens_S7_Test
{
public class connParam
{
public string ipAdrr = "";
public CpuType tipoCpu = CpuType.S7300;
public short slot = 0;
public short rack = 0;
}
}
@@ -0,0 +1 @@

+35
View File
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Siemens_S7_Test
{
public class memAddress
{
/// <summary>
/// Indice DB
/// </summary>
public int DbNum = 0;
/// <summary>
/// Tipo Memoria (DBD, DBW...)
/// </summary>
public string tipoMem = "";
/// <summary>
/// Indice partenza memoria (es DBD0 --> 0)
/// </summary>
public int indiceMem = 0;
/// <summary>
/// Inizializza da un formato stringa
/// </summary>
/// <param name="strFormat"></param>
public memAddress(string strFormat)
{
string[] memComp = strFormat.Split('.');
int.TryParse(memComp[0].Replace("DB", ""), out DbNum);
tipoMem = memComp[1].Substring(2, 1);
int.TryParse(memComp[1].Replace("DB", "").Replace(tipoMem, ""), out indiceMem);
}
}
}
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NLog" version="4.7.0" targetFramework="net462" />
<package id="NLog.Config" version="4.7.0" targetFramework="net462" />
<package id="NLog.Schema" version="4.7.0" targetFramework="net462" />
<package id="S7netplus" version="0.4.0" targetFramework="net462" />
</packages>
@@ -0,0 +1,36 @@
# Commenti con cancelletto, struttura un variabile per riga, tipo chiave|valore (occhio che il separatore è configurato da .cofig come "charSep"); spazi e tabulazioni dovrei trimmarli in acquisizione (qui inseriti per comodità di lettura)
# Segnali BIT per gestione MAPO-IOB-WIN "base"
0.0|IOB_POWER_ON |BIT
0.1|IOB_RUN |BIT
0.2|IOB_COUNT |BIT
0.3|IOB_ALARM |BIT
0.4|IOB_MANUAL |BIT
# segnali BIT x ACK
0.5|ACK_STR |BIT
0.6|ACK_ST_COM |BIT
0.7|ACK_END_COM |BIT
#bit x definizione ultimo pezzo (OK/SCARTO/RILAVORAZIONE)
1.0|LAST_PZ_OK |BIT
1.1|LAST_PZ_KO |BIT
1.2|LAST_PZ_RIL |BIT
# Vettori allarmi (banchi da 32)
002|ALARMS_001 |4BYTE
006|ALARMS_033 |4BYTE
010|ALARMS_065 |4BYTE
014|ALARMS_097 |4BYTE
# Altro valori byte numerici (0..255)
018|AUTO_POWER_OFF |BYTE
019|OVR_SPEED |BYTE
020|OVR_FEED |BYTE
021|CURR_MODE |BYTE
# valori word come UINT 16bit/Word
022|COUNT_TOT |WORD
024|RPM_PEZZO |WORD
026|RPM_MOLA |WORD
028|NUM_PZ_STOP |WORD
030|MIN_TEO_STOP |WORD
032|LOAD_PEZZO |WORD
034|LOAD_MOLA |WORD
036|TC_LAST_PZ |REAL
040|MIS_H1_LAST_PZ |REAL
044|MIS_H2_LAST_PZ |REAL
@@ -0,0 +1,27 @@
# Commenti con cancelletto, struttura un variabile per riga, tipo chiave|valore (occhio che il separatore è configurato da .cofig come "charSep"); spazi e tabulazioni dovrei trimmarli in acquisizione (qui inseriti per comodità di lettura)
# Segnali BIT per gestione richeista lettura valori
0.0|SIG_STR |BIT
0.1|SIG_ST_COM |BIT
0.2|SIG_END_COM |BIT
# valori word come UINT 16bit/Word
002|NUM_PZ_LOTTO |WORD
# dati COMMESSA
006|L_MAX_COMM |BYTE
007|L_ACT_COMM |BYTE
008|COD_COMMESSA |20CHAR
# dati ARTICOLO
006|L_MAX_ART |BYTE
007|L_ACT_ART |BYTE
008|COD_ARTICOLO |20CHAR
# dati PROGRAMMA
006|L_MAX_PROG |BYTE
007|L_ACT_PROG |BYTE
008|COD_PROGRAMMA |20CHAR
# dati MACCHINA
006|L_MAX_MACC |BYTE
007|L_ACT_MACC |BYTE
008|COD_MACCHINA |20CHAR
# dati DIRECTORY
006|L_MAX_DIR |BYTE
007|L_ACT_DIR |BYTE
008|COD_DIRECTORY |20CHAR
+266
View File
@@ -0,0 +1,266 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using NLog;
using System.Windows.Forms;
namespace Siemens_S7_Test
{
public class utils
{
/// <summary>
/// wrapper di log
/// </summary>
public static Logger lg;
/// <summary>
/// folder archiviazione dati configurazione (DATA\CONF)
/// </summary>
public static string confDir
{
get
{
return string.Format(@"{0}\{1}", Application.StartupPath, CRS("dataConfPath"));
}
}
/// <summary>
/// legge conf in formato char
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static char CRC(string key)
{
char answ = '-';
try
{
answ = ConfigurationManager.AppSettings[key].ToCharArray()[0];
}
catch
{ }
return answ;
}
/// <summary>
/// legge conf in formato stringa
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static string CRS(string key)
{
string answ = "";
try
{
answ = ConfigurationManager.AppSettings[key].ToString();
}
catch
{ }
return answ;
}
/// <summary>
/// legge conf in formato INT
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static Int32 CRI(string key)
{
int answ = 0;
try
{
answ = Convert.ToInt32(CRS(key));
}
catch
{ }
return answ;
}
/// <summary>
/// legge conf in formato BOOLean
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static bool CRB(string key)
{
bool answ = false;
try
{
answ = Convert.ToBoolean(CRS(key));
}
catch
{ }
return answ;
}
/// <summary>
/// Decodifica file allarme
/// </summary>
/// <param name="linea"></param>
/// <param name="separator"></param>
/// <param name="memPre">tipo memoria (R/D/...)</param>
/// <param name="baseAddr">indirizzo di partenza memoria</param>
/// <param name="memSize">dimensione singolo slot in byte</param>
/// <returns></returns>
protected static otherData decodeOtherData(string linea, char separator, string memPre, int baseAddr, int memSize)
{
string[] valori = linea.Split(separator);
int shift = 0;
try
{
shift = Convert.ToInt32(valori[0]) - 1;
}
catch
{ }
string memAddr = string.Format("{0}{1}", memPre, baseAddr + shift * memSize);
return new otherData(valori[0], memAddr, valori[1].Trim(), valori[2].Trim());
}
/// <summary>
/// Decodifica file MAP (caso ESA/IOT)
/// </summary>
/// <param name="linea"></param>
/// <param name="separator"></param>
/// <param name="ByteNum">indirizzo Byte: indirizzo di partenza memoria</param>
/// <param name="memSize">dimensione singolo slot in byte</param>
/// <param name="BitNum">indirizzo bit: numero riga x calcolo indice bit</param>
/// <returns></returns>
protected static otherData decodeBitData(string linea, char separator, int ByteNum, int memSize, int BitNum)
{
string[] valori = linea.Split(separator);
int shift = 0;
try
{
shift = Convert.ToInt32(valori[0]) - 1;
}
catch
{ }
int resto = 0;
Math.DivRem(BitNum, 8, out resto);
string memAddr = string.Format("{0}.{1}", ByteNum + shift * memSize, resto);
return new otherData(valori[0], memAddr, valori[1].Trim(), valori[2].Trim());
}
/// <summary>
/// Decodifica file MAP (caso FANUC/OSAI/...)
/// </summary>
/// <param name="linea"></param>
/// <param name="separator"></param>
/// <param name="memPre">tipo memoria (R/D/...)</param>
/// <param name="baseAddr">indirizzo Byte: indirizzo di partenza memoria</param>
/// <param name="memSize">dimensione singolo slot in byte</param>
/// <param name="numRiga">indirizzo bit: numero riga x calcolo indice bit</param>
/// <returns></returns>
protected static otherData decodeBitData(string linea, char separator, string memPre, int baseAddr, int memSize, int numRiga)
{
string[] valori = linea.Split(separator);
int shift = 0;
try
{
shift = (Convert.ToInt32(valori[0]) - 1) / (8 * memSize);
}
catch
{ }
int resto = 0;
Math.DivRem(numRiga, 8 * memSize, out resto);
string memAddr = string.Format("{0}{1}.{2}", memPre, baseAddr + shift, resto);
return new otherData(valori[0], memAddr, valori[1].Trim(), valori[2].Trim());
}
/// <summary>
/// Legge il file di conf di una MAP di informazioni da gestire con lettura set memoria
/// </summary>
/// <param name="vettoreConf">nome vettore memoria</param>
/// <param name="nomeFile">file origine</param>
/// <param name="memSize">dimensione (in byte) della memoria</param>
/// <param name="numVett">dimensione (in byte) della memoria</param>
public static void loadConfFile(ref otherData[] vettoreConf, string nomeFile, int memSize, ref int numVett)
{
otherData lastData = new otherData();
int totRighe = 0;
string linea;
totRighe = File.ReadLines(nomeFile).Count();
// creo un vettore della dimensione corretta... conta anche commenti tanto poi riduco...
vettoreConf = new otherData[File.ReadLines(nomeFile).Count()];
// carica da file...
StreamReader file = new StreamReader(nomeFile);
// leggo 1 linea alla volta...
int numRiga = 0;
int bitNum = 0;
int byteNum = 0;
while ((linea = file.ReadLine()) != null)
{
// SE non è un commento...
if (linea.Substring(0, 1) != "#")
{
// se finisce per BIT allora processo bit-a-bit...
if (linea.EndsWith("BOOL"))
{
try
{
string[] memIdx = linea.Split(utils.CRC("charSep"))[0].Split('.');
// calcolo bit e byte number...
int.TryParse(memIdx[0], out byteNum);
if (memIdx.Length > 1)
{
int.TryParse(memIdx[1], out bitNum);
}
else
{
bitNum = 0;
}
}
catch
{
byteNum = 0;
bitNum = 0;
}
lastData = decodeBitData(linea, utils.CRC("charSep"), byteNum, 1, bitNum);
vettoreConf[numRiga] = lastData;
}
else
{
lastData = decodeOtherData(linea, utils.CRC("charSep"), "", 1, memSize);
vettoreConf[numRiga] = lastData;
}
numRiga++;
}
}
// salvo lunghezza file...
try
{
numVett = Convert.ToInt32(lastData.memAddr) + 1;
}
catch
{
numVett = numRiga + 1;
}
// chiudo file
file.Close();
// ora trimmo vettore al solo numero VERO dei valori caricati...
Array.Resize<otherData>(ref vettoreConf, numRiga);
if (utils.CRB("verbose")) lg.Info(string.Format("Fine caricamento vettore di {0} variabili per file {1}", numRiga, nomeFile));
}
}
/// <summary>
/// Dato generico (per decodifica)
/// </summary>
public class otherData
{
public string codNum;
public string memAddr;
public string varName;
public string dataType;
public otherData()
{
codNum = "";
memAddr = "";
varName = "";
dataType = "";
}
public otherData(string _codNum, string _memAddr, string _varName, string _dataType)
{
codNum = _codNum;
memAddr = _memAddr;
varName = _varName;
dataType = _dataType;
}
}
}