Files
Mapo-IOB-WIN/IOB-WIN/IobFanuc.cs
T

822 lines
28 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IOB_UT;
using CncLib.CNC;
using System.Net.NetworkInformation;
using System.Net;
using NLog;
namespace IOB_WIN
{
public class IobFanuc : IobGeneric
{
/// <summary>
/// Contapezzi attuale
/// </summary>
protected Int32 contapezzi;
/// <summary>
/// Ultima lettura variabile contapezzi da CNC
/// </summary>
protected Int32 lastCountCNC;
/// <summary>
/// Area memoria G (copia)
/// </summary>
protected byte[] MemBlockG = new byte[2];
/// <summary>
/// Area memoria X (copia)
/// </summary>
protected byte[] MemBlockX = new byte[2];
/// <summary>
/// Area memoria Y (copia)
/// </summary>
protected byte[] MemBlockY = new byte[2];
/// <summary>
/// Ultimo invio contapezzi (x invio delayed)
/// </summary>
protected DateTime lastPzCountSend;
/// <summary>
/// Ritardo minimo x invio contapezzi
/// </summary>
protected int pzCountDelay;
/// <summary>
/// LookUpTable di decodifica da CNC a segnali tipo bitmap MAPO
/// </summary>
Dictionary<string, string> signLUT = new Dictionary<string, string>();
/// <summary>
/// wrapper chiamata lettura/scrittura SINGOLO BYTE...
/// </summary>
/// <param name="bWrite"></param>
/// <param name="MemType"></param>
/// <param name="memIndex"></param>
/// <param name="Value"></param>
/// <returns></returns>
public bool FanucMemRW(bool bWrite, FANUC.MemType MemType, Int32 memIndex, ref byte Value)
{
bool answ = false;
if (FANUC_ref.Connected)
{
try
{
parentForm.commPlcActive = true;
answ = FANUC_ref.F_RW_Byte(bWrite, MemType, memIndex, ref Value);
}
catch
{ }
}
parentForm.commPlcActive = false;
return answ;
}
/// <summary>
/// wrapper chiamata lettura/scrittura MULTI BYTE...
/// </summary>
/// <param name="bWrite"></param>
/// <param name="MemType"></param>
/// <param name="memIndex"></param>
/// <param name="MATRICE Value"></param>
/// <returns></returns>
public bool FanucMemRW(bool bWrite, FANUC.MemType MemType, Int32 memIndex, ref byte[] Value)
{
bool answ = false;
if (FANUC_ref.Connected)
{
try
{
parentForm.commPlcActive = true;
answ = FANUC_ref.F_RW_Byte(bWrite, MemType, memIndex, ref Value);
}
catch
{ }
}
parentForm.commPlcActive = false;
return answ;
}
/// <summary>
/// Oggetto MAIN x connessione FANUC
/// </summary>
protected FANUC FANUC_ref;
/// <summary>
/// estende l'init della classe base...
/// </summary>
/// <param name="caller"></param>
/// <param name="adpConf"></param>
public IobFanuc(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
{
// i dati RAW principali sono 6 byte...
RawInput = new byte[6];
// gestione invio ritardato contapezzi
pzCountDelay = utils.CRI("pzCountDelay");
lastPzCountSend = DateTime.Now;
// inizializzo correttamente aree memoria secondo CONF - iniFileName
IniFile fIni = new IniFile(IOBConf.iniFileName);
// inizializzo aree di memoria correnti...
MemBlockG = new byte[fIni.ReadInteger("MEMORY", "AREAG_SIZE", 8)];
MemBlockX = new byte[fIni.ReadInteger("MEMORY", "AREAX_SIZE", 8)];
MemBlockY = new byte[fIni.ReadInteger("MEMORY", "AREAY_SIZE", 8)];
// loggo aree di memoria avviate...
lgInfo(string.Format("Avviare area di memoria MemBlockG: {0} byte", MemBlockG.Length));
lgInfo(string.Format("Avviare area di memoria MemBlockX: {0} byte", MemBlockX.Length));
lgInfo(string.Format("Avviare area di memoria MemBlockY: {0} byte", MemBlockY.Length));
// effettuo lettura della conf sigLUT... cercando 1:1 i bit...
string currBit = "";
string memArea = "";
for (int i = 0; i < 8; i++)
{
currBit = string.Format("BIT{0}", i);
memArea = fIni.ReadString("MEMORY", currBit, "");
// se trovo un valore...
if (memArea != "") signLUT.Add(currBit, memArea);
}
// è little endian (NON serve conversione)
hasBigEndian = false;
lgInfo("Start init Adapter FANUC all'IP {0}:{1} per IOB {2}", IOBConf.cncIpAddr, IOBConf.cncPort, IOBConf.codIOB);
// Creo oggetto connessione NC
parentForm.commPlcActive = true;
Runtime.CreateNC(CNC.NcType.FANUC, IOBConf.cncIpAddr, IOBConf.cncPort);
parentForm.commPlcActive = false;
// aggiungo referenza obj FANUC
FANUC_ref = (FANUC)Runtime.NC;
if (utils.CRB("verbose")) lgInfo("FANUC_ref da CncLib");
// disconnetto e connetto...
if (utils.CRB("verbose")) lgInfo("FANUC: tryDisconnect");
tryDisconnect();
lgInfo("FANUC: tryConnect");
tryConnect();
if (utils.CRB("enableContapezzi"))
{
lgInfo("FANUC: inizio gestione contapezzi");
try
{
// verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area)
if (currIobConf.optPar.Count > 0 && currIobConf.optPar["PZCOUNT_MODE"] != "")
{
if (currIobConf.optPar["PZCOUNT_MODE"] == "STD")
{
// legge da IO server ULTIMO valore CONTPEZZI al riavvio...
lgInfo("Lettura contapezzi dall'url {0}", urlGetPzCount);
string currServerCount = utils.callUrl(urlGetPzCount);
if (currServerCount != "")
{
int.TryParse(currServerCount, out contapezzi);
lgInfo("Ricevuta conferma da server di {0} pezzi registrati per ODL", currServerCount);
}
else
{
contapezzi = 0;
lgInfo("Errore lettura contapezzi (empty)");
}
// per adesso imposto lettura fanuc == contapezzi (poi farà vera lettura...)
lastCountCNC = contapezzi;
}
else
{
contapezzi = 0;
lgInfo("Contapezzi STD disabilitato: modalità {0}", currIobConf.optPar["PZCOUNT_MODE"]);
}
}
else
{
contapezzi = 0;
lgInfo("Parametro mancante PZCOUNT_MODE");
}
}
catch (Exception exc)
{
lgError(exc, "Errore in contapezzi FANUC");
}
}
// finisco INIT ADAPTER
lgInfo("End init Adapter FANUC");
}
/// <summary>
/// Override disconnessione
/// </summary>
public override void tryDisconnect()
{
if (connectionOk)
{
string szStatusConnection = "";
try
{
FANUC_ref.Disconnect(ref szStatusConnection);
connectionOk = false;
// resetto timing!
TimingData.resetData();
lgInfo(szStatusConnection);
lgInfo("Effettuata disconnessione adapter FANUC!");
}
catch (Exception exc)
{
lgFatal(exc, "Errore nella disconnessione dall'adapter FANUC");
}
}
else
{
lgError("IMPOSSIBILE effettuare disconnessione: Connessione non disponibile...");
}
}
/// <summary>
/// Override connessione
/// </summary>
public override void tryConnect()
{
if (!connectionOk)
{
// controllo che il ping sia stato tentato almeno pingTestSec fa...
if (DateTime.Now.Subtract(lastPING).TotalSeconds > utils.CRI("pingTestSec"))
{
if (verboseLog || periodicLog) lgInfo("ConnKO - tryConnect");
// in primis salvo data ping...
lastPING = DateTime.Now;
// ora PING!!!
Ping pingSender = new Ping();
IPAddress address = IPAddress.Loopback;
IPAddress.TryParse(currIobConf.cncIpAddr, out address);
PingReply reply = pingSender.Send(address, 100);
// se passa il ping faccio il resto...
if (reply.Status == IPStatus.Success)
{
string szStatusConnection = "";
try
{
// ora provo connessione...
parentForm.commPlcActive = true;
FANUC_ref.Connect(ref szStatusConnection);
parentForm.commPlcActive = false;
lgInfo("szStatusConnection: " + szStatusConnection);
connectionOk = true;
// refresh stato allarmi!!!
if (connectionOk)
{
dtAvvioAdp = DateTime.Now;
if (adpRunning)
{
// carico status allarmi (completo)
lgInfo("Inizio refresh completo stato allarmi...");
forceAlarmCheck();
lgInfo("Completato refresh completo stato allarmi!");
}
else
{
lgInfo("Connessione OK");
}
}
else
{
lgError("Impossibile procedere, connessione mancante...");
}
}
catch (Exception exc)
{
lgFatal(string.Format("Errore nella connessione all'adapter FANUC: {0}{1}{2}", szStatusConnection, Environment.NewLine, exc));
connectionOk = false;
lgInfo(string.Format("Eccezione in TryConnect, Adapter NON running, pausa di {0} msec prima di ulteriori tentativi di riconnessione", utils.CRI("waitRecMSec")));
}
}
else
{
// loggo no risposta ping ...
connectionOk = false;
if (verboseLog || periodicLog) lgInfo(string.Format("Attenzione: controllo PING fallito per IP {0} - {1}", currIobConf.cncIpAddr, reply.Status));
}
}
}
// se non è ancora connesso faccio procesisng memoria caso disconnesso...
if (!connectionOk)
{
// processo semafori ed invio...
processMemoryDiscon();
}
}
/// <summary>
/// lettura principale (bit semafori)
/// </summary>
public override void readSemafori()
{
base.readSemafori();
try
{
if (verboseLog) lgInfo("inizio read semafori");
parentForm.sIN = Semaforo.SV;
// inizio letture, SEMPRE DA ZERO (possibile ottimizzazione...)
int memIndex = 0;
// controllo area Y: se ha dati (> 0 byte) --> leggo!
if (MemBlockY.Length > 0)
{
stopwatch.Restart();
FanucMemRW(R, FANUC.MemType.Y, memIndex, ref MemBlockY);
if (utils.CRB("recTime")) TimingData.addResult(currIobConf.codIOB, string.Format("R{0}-Y", MemBlockY.Length), stopwatch.ElapsedTicks);
// log
if (verboseLog)
{
for (int i = 0; i < MemBlockY.Length; i++)
{
lgInfo(string.Format("MemBlockY{0}: {1}", i, utils.binaryForm((int)MemBlockY[i])));
}
}
}
// controllo area X: se ha dati (> 0 byte) --> leggo!
if (MemBlockX.Length > 0)
{
stopwatch.Restart();
FanucMemRW(R, FANUC.MemType.X, memIndex, ref MemBlockX);
if (utils.CRB("recTime")) TimingData.addResult(currIobConf.codIOB, string.Format("R{0}-X", MemBlockX.Length), stopwatch.ElapsedTicks);
// log
if (verboseLog)
{
for (int i = 0; i < MemBlockX.Length; i++)
{
lgInfo(string.Format("MemBlockX{0}: {1}", i, utils.binaryForm((int)MemBlockX[i])));
}
}
}
stopwatch.Stop();
// salvo il solo BYTE dell'input decifrando il semaforo...
decodeToBitmap();
}
catch (Exception exc)
{
lgError(string.Format("Eccezione in readSemafori:{0}{1}", Environment.NewLine, exc));
connectionOk = false;
}
}
/// <summary>
/// Effettua decodifica aree memoria alla bitmap usata x MAPO
/// </summary>
private void decodeToBitmap()
{
// init a zero...
B_input = 0;
// SE SI E' CONNESSO al FANUC allora è 1=powerON...
if (FANUC_ref.Connected)
{
B_input += 1 << 0;
}
// decodifico impiegando dictionary... cercando il TIPO di memoria & co...
string bKey = "";
string bVal = "";
char area;
// valore INVERTED (default è false)
bool invSignal = false;
string memArea = "";
string[] memIdx;
int bitNum = 0;
int byteNum = 0;
int byte2check = 0;
for (int i = 0; i < 8; i++)
{
bKey = string.Format("BIT{0}", i);
// cerco se ci sia in LUT
if (signLUT.ContainsKey(bKey))
{
// recupero nome variabile...
bVal = signLUT[bKey];
// se l'area è PZCOUNT... processo PUNTUALMENTE il CONTAPEZZI...
if (bVal == "PZCOUNT")
{
// controllo se è passato intervallo minimo tra 2 controlli/elaborazioni x distanziare invio e ridurre letture
if (DateTime.Now >= lastPzCountSend.AddMilliseconds(pzCountDelay))
{
// resetto timer...
lastPzCountSend = DateTime.Now;
// verifico se variato contapezzi in area STD PAR6711... e se passato ritardo minimo...
if (lastCountCNC > contapezzi)
{
// salvo nuovo contapezzi (incremento di 1...)
contapezzi++;
// salvo in semaforo!
B_input += 1 << 2;
// registro contapezzi
lgInfo(string.Format("Contapezzi FANUC: {0} | Contapezzi interno {1}", lastCountCNC, contapezzi));
}
else if (contapezzi > lastCountCNC) // in questo caso resetto
{
contapezzi = lastCountCNC;
}
// invio a server contapezzi (aggiornato)
utils.callUrl(urlSetPzCount + contapezzi.ToString());
}
}
else // area "normale" byte.bit
{
// di norma è segnale normale => 1, altrimenti inverse => 0...
invSignal = false;
// cerco se sia inverse (ultimo char "!") --> registro e elimino char...
invSignal = bVal.StartsWith("!");
// tolgo comunque inversione...
bVal = bVal.Replace("!", "");
// recupero area...
area = bVal[0];
// altrimenti decodifico area...
memArea = bVal.Substring(1, bVal.Length - 1);
memIdx = memArea.Split('.');
// calcolo bit e byte number...
int.TryParse(memIdx[0], out byteNum);
if (memIdx.Length > 1)
{
int.TryParse(memIdx[1], out bitNum);
}
// in base al nome cerco in una delle aree.. e prendo solo solo quel bit di quel byte...
switch (area)
{
case 'G':
byte2check = MemBlockG[byteNum];
break;
case 'X':
byte2check = MemBlockX[byteNum];
break;
case 'Y':
byte2check = MemBlockY[byteNum];
break;
default:
break;
}
// a secondo che sia segnale normale o inverso...
if (invSignal)
{
// controllo se il bit sia NON attivo (basso)... == 0...
if ((byte2check & (1 << bitNum)) == 0)
{
B_input += 1 << i;
}
}
else
{
// controllo se il bit sia attivo (alto)... != 0
if ((byte2check & (1 << bitNum)) != 0)
{
B_input += 1 << i;
}
}
}
}
}
// log opzionale!
if (verboseLog) lgInfo(string.Format("Trasformazione B_input: {0}", B_input));
}
/// <summary>
/// Recupero programma in lavorazione
/// </summary>
/// <returns></returns>
public override string getPrgName()
{
string prgName = "";
// recupero NUOVO prgName...
try
{
// recupero nome programma MAIN
prgName = utils.purgedChar2String(FANUC_ref.getPrgNameMain());
// trimmo path del programma, ovvero "CNCMEMUSERPATH1"
prgName = prgName.Replace(utils.CRS("basePrgMemPath"), "");
}
catch (Exception exc)
{
lgError(string.Format("Eccezione in recupero PRG NAME MAIN:{0}{1}", Environment.NewLine, exc));
connectionOk = false;
}
return prgName;
}
/// <summary>
/// Recupero programma in lavorazione come Dictionary FANUC...
/// - SYSINFO: (prima KEY globale) TUTTI i valori separati da # (x fare check modifica)
/// - altre stringhe: ogni singolo parametro / valore
/// </summary>
/// <returns></returns>
public override Dictionary<string, string> getSysInfo()
{
Dictionary<string, string> outVal = new Dictionary<string, string>();
stopwatch.Restart();
CncLib.Focas1.ODBSYS answ = FANUC_ref.getSysInfo();
if (utils.CRB("recTime")) TimingData.addResult(currIobConf.codIOB, string.Format("SYS-INFO"), stopwatch.ElapsedTicks);
try
{
string cnc_type = new string(answ.cnc_type);
string mt_type = new string(answ.mt_type);
string series = new string(answ.series);
string version = new string(answ.version);
string axes = new string(answ.axes);
//short addInfo = answ.addinfo;
short max_axis = answ.max_axis;
// preparo i singoli valori dell'array...
outVal.Add("SYSINFO", string.Format("{0}#{1}#{2}#{3}#{4}#{5}", cnc_type, mt_type, series, version, axes, max_axis));
outVal.Add("CNC", cnc_type);
outVal.Add("MTT", mt_type);
outVal.Add("SER", series);
outVal.Add("VER", version);
outVal.Add("AXS", string.Format("{0}|{1}", axes, max_axis));
}
catch (Exception exc)
{
lgError(exc, "Errore in getSysInfo");
connectionOk = false;
}
return outVal;
}
/// <summary>
/// Effettua vero processing contapezzi:
/// 6711: pezzi lavorati
/// 6712: pezzi lavorati totali
/// 6713: pezzi richiesti
/// </summary>
public override void processContapezzi()
{
if (utils.CRB("enableContapezzi"))
{
try
{
// verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area)
if (currIobConf.optPar.Count > 0 && currIobConf.optPar["PZCOUNT_MODE"] != "")
{
if (currIobConf.optPar["PZCOUNT_MODE"] == "STD")
{
object output = new object();
// processo parametro contapezzi (lavorati)
stopwatch.Restart();
FANUC_ref.F_RW_Param_Integer(false, 6711, 3, ref output);
if (utils.CRB("recTime")) TimingData.addResult(currIobConf.codIOB, string.Format("R{0}-PAR", 4), stopwatch.ElapsedTicks);
// salvo ultimo conteggio rilevato
Int32.TryParse(output.ToString(), out lastCountCNC);
stopwatch.Stop();
}
}
}
catch (Exception exc)
{
lgError(exc, "Errore in contapezzi FANUC");
connectionOk = false;
}
}
}
/// <summary>
/// Esegue processing MODE (e nel contempo recupera altri dati dell'area G)
/// </summary>
public override void processMode()
{
if (utils.CRB("enableMode"))
{
try
{
// leggo tutto da 0 a 43...
int memIndex = 0;
// controllo modalità lettura memoria
stopwatch.Restart();
FanucMemRW(R, FANUC.MemType.G, memIndex, ref MemBlockG);
if (utils.CRB("recTime")) TimingData.addResult(currIobConf.codIOB, string.Format("R{0}-G-AREA", MemBlockG.Length), stopwatch.ElapsedTicks);
stopwatch.Stop();
// verifico modo con valore corrente, se cambia aggiorno...
CNC_MODE newMode = decodeG43(MemBlockG[43]);
if (newMode != currMode)
{
// aggiorno!
currMode = newMode;
// conversione NUM MODE in descrizione da ENUM
string descrMode = Enum.GetName(typeof(CNC_MODE), currMode);
// accodo x invio
string sVal = string.Format("[CNC_MODE]{0}", descrMode);
// chiamo accodamento...
accodaFLog(sVal, qEncodeFLog("CNC_MODE", descrMode));
}
}
catch (Exception exc)
{
lgError(exc, string.Format("Errore in process Mode G43: {0}{1}", Environment.NewLine, exc));
connectionOk = false;
stopwatch.Stop();
}
}
}
/// <summary>
/// decodifica il modo dai valori del byte G43
/// </summary>
/// <param name="currVal"></param>
/// <returns></returns>
protected CNC_MODE decodeG43(byte currVal)
{
// hard coded da valori tabellari a MODI definiti in CNC_MODE...
CNC_MODE answ = CNC_MODE.ND;
switch (currVal)
{
case 0:
answ = CNC_MODE.MDI;
break;
case 1:
answ = CNC_MODE.MEN;
break;
case 3:
answ = CNC_MODE.EDIT;
break;
case 4:
answ = CNC_MODE.HANDLE_INC;
break;
case 5:
answ = CNC_MODE.JOG;
break;
case 6:
answ = CNC_MODE.TJOG;
break;
case 7:
answ = CNC_MODE.THND;
break;
case 33:
answ = CNC_MODE.RMT;
break;
case 133:
answ = CNC_MODE.REF;
break;
default:
answ = CNC_MODE.ND;
break;
}
return answ;
}
/// <summary>
/// Recupero dati dinamici...
/// </summary>
public override Dictionary<string, string> getDynData()
{
Dictionary<string, string> outVal = new Dictionary<string, string>();
stopwatch.Restart();
CncLib.Focas1.ODBDY2_1 answ = FANUC_ref.getAllDynData();
if (utils.CRB("recTime")) TimingData.addResult(currIobConf.codIOB, string.Format("PROC-DYN-DATA"), stopwatch.ElapsedTicks);
try
{
string actf = answ.actf.ToString();
string acts = answ.acts.ToString();
//string numAlarm = answ.alarm.ToString();
// preparo i singoli valori dell'array...
//outVal.Add("DYNDATA", string.Format("{0}#{1}#{2}", actf, acts, numAlarm));
outVal.Add("DYNDATA", string.Format("FEED {0}#SPEED_RPM {1}", actf, acts));
if (utils.CRB("SendFeedSpeed"))
{
outVal.Add("FEED", actf);
outVal.Add("SPEED_RPM", acts);
//outVal.Add("NUM_ALARM", numAlarm);
}
if (utils.CRB("SendAxPos"))
{
// salvo le posizioni...
CncLib.Focas1.FAXIS posAx = answ.pos;
int[] currPosAbs = posAx.absolute;
int i = 0;
foreach (var item in currPosAbs)
{
i++;
outVal.Add(string.Format("POS_{0:00}", i), item.ToString());
}
}
}
catch (Exception exc)
{
lgError(exc, "Errore in getDynData");
}
stopwatch.Stop();
return outVal;
}
/// <summary>
/// Recupero dati override (da area G che è già stata letta...)
/// </summary>
/// <returns></returns>
public override Dictionary<string, string> getOverrides()
{
Dictionary<string, string> outVal = new Dictionary<string, string>();
outVal.Add("FEED_OVER", MemBlockG[30].ToString());
outVal.Add("RAPID_OVER", MemBlockG[12].ToString());
return outVal;
}
/// <summary>
/// Override salvataggio valori in memoria...
/// </summary>
public override void saveMemDump()
{
dump_MemAreaD();
dump_MemAreaY();
}
/// <summary>
/// Dump PERIODICO area D della memoria
/// </summary>
/// <param name="memIndex">area memoria di partenza</param>
/// <param name="memSyzeByte"></param>
private void dump_MemAreaD(int memIndex, int memSyzeByte)
{
// leggo TUTTI i 9999 byte della memoria D...
byte[] MemBlockD = new byte[memSyzeByte];
if (verboseLog) lgInfo("START MemDump AreaD");
stopwatch.Restart();
FanucMemRW(R, FANUC.MemType.D, memIndex, ref MemBlockD);
if (utils.CRB("recTime")) TimingData.addResult(currIobConf.codIOB, string.Format("R{0}-MemDumpD", MemBlockD.Length), stopwatch.ElapsedTicks);
if (verboseLog) lgInfo("END MemDump AreaD");
// file out!
string nomeFile = "";
Dictionary<string, string> mappaValori = new Dictionary<string, string>();
// salvo in file i dati letti come DWord (4byte)
nomeFile = string.Format(@"{0}\SAMPLES\MemDump_D_DW_{1:yyyyMMdd_HHmmss}.dat", utils.dataDatDir, DateTime.Now);
for (int i = 0; i < MemBlockD.Length / 4; i++)
{
mappaValori.Add(i.ToString("0000"), BitConverter.ToUInt32(MemBlockD, i * 4).ToString());
}
utils.WritePlain(mappaValori, nomeFile);
}
/// <summary>
/// Dump area D della memoria
/// </summary>
private void dump_MemAreaD()
{
// faccio chaimate e salvo in file dump...
int memIndex = 0;
// leggo TUTTI i 9999 byte della memoria D...
byte[] MemBlockD = new byte[9999];
if (verboseLog) lgInfo("START MemDump AreaD");
stopwatch.Restart();
FanucMemRW(R, FANUC.MemType.D, memIndex, ref MemBlockD);
if (utils.CRB("recTime")) TimingData.addResult(currIobConf.codIOB, string.Format("R{0}-MemDumpD", MemBlockD.Length), stopwatch.ElapsedTicks);
if (verboseLog) lgInfo("END MemDump AreaD");
//
string nomeFile = "";
// salvo in file i dati letti come BYTE
nomeFile = string.Format(@"{0}\MemDump_D_Byte.dat", utils.dataDatDir);
Dictionary<string, string> mappaValori = new Dictionary<string, string>();
for (int i = 0; i < MemBlockD.Length; i++)
{
mappaValori.Add(i.ToString("0000"), MemBlockD[i].ToString());
}
utils.WritePlain(mappaValori, nomeFile);
// salvo in file i dati letti come DWord (4byte)
nomeFile = string.Format(@"{0}\MemDump_D_DW.dat", utils.dataDatDir);
mappaValori = new Dictionary<string, string>();
for (int i = 0; i < MemBlockD.Length / 4; i++)
{
mappaValori.Add(i.ToString("0000"), BitConverter.ToUInt32(MemBlockD, i * 4).ToString());
}
utils.WritePlain(mappaValori, nomeFile);
// salvo in file i dati letti come DWord (4byte)
nomeFile = string.Format(@"{0}\MemDump_D_W.dat", utils.dataDatDir);
mappaValori = new Dictionary<string, string>();
for (int i = 0; i < MemBlockD.Length / 2; i++)
{
mappaValori.Add(i.ToString("0000"), BitConverter.ToUInt16(MemBlockD, i * 2).ToString());
}
utils.WritePlain(mappaValori, nomeFile);
}
/// <summary>
/// Dump area Y della memoria
/// </summary>
private void dump_MemAreaY()
{
// faccio chaimate e salvo in file dump...
int memIndex = 0;
// leggo TUTTI i 9999 byte della memoria Y...
byte[] MemBlockY = new byte[10];
stopwatch.Restart();
if (verboseLog) lgInfo("START MemDump AreaY");
FanucMemRW(R, FANUC.MemType.Y, memIndex, ref MemBlockY);
if (verboseLog) lgInfo("END MemDump AreaY");
if (utils.CRB("recTime")) TimingData.addResult(currIobConf.codIOB, string.Format("R{0}-MemDumpY", MemBlockY.Length), stopwatch.ElapsedTicks);
//
string nomeFile = "";
// salvo in file i dati letti come BYTE
nomeFile = string.Format(@"{0}\MemDump_Y_Byte.dat", utils.dataDatDir);
Dictionary<string, string> mappaValori = new Dictionary<string, string>();
for (int i = 0; i < MemBlockY.Length; i++)
{
mappaValori.Add(i.ToString("0000"), MemBlockY[i].ToString());
}
utils.WritePlain(mappaValori, nomeFile);
// salvo in file i dati letti come DWord (4byte)
nomeFile = string.Format(@"{0}\MemDump_Y_DW.dat", utils.dataDatDir);
mappaValori = new Dictionary<string, string>();
for (int i = 0; i < MemBlockY.Length / 4; i++)
{
mappaValori.Add(i.ToString("0000"), BitConverter.ToUInt32(MemBlockY, i * 4).ToString());
}
utils.WritePlain(mappaValori, nomeFile);
// salvo in file i dati letti come DWord (4byte)
nomeFile = string.Format(@"{0}\MemDump_Y_W.dat", utils.dataDatDir);
mappaValori = new Dictionary<string, string>();
for (int i = 0; i < MemBlockY.Length / 2; i++)
{
mappaValori.Add(i.ToString("0000"), BitConverter.ToUInt16(MemBlockY, i * 2).ToString());
}
utils.WritePlain(mappaValori, nomeFile);
}
}
}