Mappato tutte le memorie in R e W x scambio dati con Siemens (x testing)
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27004.2009
|
||||
VisualStudioVersion = 15.0.27130.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test-S7", "Test-S7\Test-S7.csproj", "{A0168CBE-9DA5-4E41-82FF-AFD39C982717}"
|
||||
EndProject
|
||||
|
||||
@@ -3,4 +3,14 @@
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</startup>
|
||||
<appSettings>
|
||||
<add key="appName" value="S7.Test"/>
|
||||
<!--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,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
|
||||
@@ -39,6 +39,7 @@
|
||||
<HintPath>..\packages\S7netplus.0.1.7\lib\net45\S7.Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@@ -63,6 +64,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="utils.cs" />
|
||||
<EmbeddedResource Include="TestMainForm.resx">
|
||||
<DependentUpon>TestMainForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
@@ -82,6 +84,12 @@
|
||||
<Content Include="NLog.config">
|
||||
<CopyToOutputDirectory>Always</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>
|
||||
|
||||
@@ -17,6 +17,18 @@ namespace Test_S7
|
||||
{
|
||||
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>
|
||||
@@ -113,10 +125,31 @@ namespace Test_S7
|
||||
}
|
||||
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()
|
||||
|
||||
@@ -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 Test_S7
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user