992 lines
30 KiB
C#
992 lines
30 KiB
C#
using IOB_UT;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.NetworkInformation;
|
|
using OmronFinsTCP;
|
|
|
|
namespace IOB_WIN
|
|
{
|
|
public class IobOmron : IobGeneric
|
|
{
|
|
|
|
#if false
|
|
/// <summary>
|
|
/// Enum segnali status macchina (ByteStatus) come flag
|
|
/// </summary>
|
|
[Flags]
|
|
public enum bitStatus
|
|
{
|
|
NONE = 0,
|
|
POWER_ON = 1 << 0,
|
|
AUTO = 1 << 1,
|
|
RUN = 1 << 2,
|
|
ERROR = 1 << 3,
|
|
ALARM = 1 << 4,
|
|
EMERG_OK = 1 << 5,
|
|
DOOR_CLOSED = 1 << 6,
|
|
READY_LOAD = 1 << 7
|
|
}
|
|
/// <summary>
|
|
/// Enum segnali macchina ulteriori (ByteSignals)
|
|
/// </summary>
|
|
[Flags]
|
|
public enum bitSignals
|
|
{
|
|
NONE = 0,
|
|
TRANSF_AUTO = 1 << 0,
|
|
PUNZ_AUTO = 1 << 1,
|
|
BARR_TAV_RIPR = 1 << 2,
|
|
ARIA_OK = 1 << 3,
|
|
CONS_TRANS_OK = 1 << 4,
|
|
TAV_A = 1 << 5,
|
|
TAV_B = 1 << 6,
|
|
RICH_ACCESSO = 1 << 7
|
|
}
|
|
#endif
|
|
|
|
/// <summary>
|
|
/// LookUpTable di decodifica da CNC a segnali tipo bitmap MAPO
|
|
/// </summary>
|
|
Dictionary<string, string> signLUT = new Dictionary<string, string>();
|
|
/// <summary>
|
|
/// Oggetto MAIN x connessione OMRON
|
|
/// </summary>
|
|
protected OmronFinsTCP.Net.EtherNetPLC OMRON_ref;
|
|
/// <summary>
|
|
/// Array delle risposte dal controllo OMRON
|
|
/// </summary>
|
|
protected System.Collections.ArrayList resDataArray;
|
|
/// <summary>
|
|
/// Comando inviato al robot
|
|
/// </summary>
|
|
protected string comando;
|
|
/// <summary>
|
|
/// Variabile verifica thread comunicazione
|
|
/// </summary>
|
|
protected bool threadOk = false;
|
|
/// <summary>
|
|
/// Nome e seriale macchina
|
|
/// </summary>
|
|
protected string macName = "";
|
|
/// <summary>
|
|
/// Variabile STATUS corrente (8bit INT)
|
|
/// </summary>
|
|
protected string cStatus;
|
|
/// <summary>
|
|
/// Variabile SIGNALS corrente (8bit INT)
|
|
/// </summary>
|
|
protected string cSignals;
|
|
/// <summary>
|
|
/// Num pezzi prelevati
|
|
/// </summary>
|
|
protected int numPzPrel;
|
|
/// <summary>
|
|
/// Ultimo TC registrato da robot
|
|
/// </summary>
|
|
protected decimal lastRecTC;
|
|
/// <summary>
|
|
/// Ultima missione svolta da robot
|
|
/// </summary>
|
|
protected string lastMissRobot;
|
|
|
|
/// <summary>
|
|
/// estende l'init della classe base...
|
|
/// </summary>
|
|
/// <param name="caller"></param>
|
|
/// <param name="adpConf"></param>
|
|
public IobOmron(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
|
|
{
|
|
// gestione invio ritardato contapezzi
|
|
pzCountDelay = utils.CRI("pzCountDelay");
|
|
lastPzCountSend = DateTime.Now;
|
|
lastWarnODL = DateTime.Now;
|
|
|
|
OMRON_ref = new OmronFinsTCP.Net.EtherNetPLC();
|
|
OMRON_ref.Link("192.168.250.1", 9600, 500);
|
|
short[] response;
|
|
short[] response2;
|
|
short bit1;
|
|
short bit2;
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 20, 2, out response);
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 22, 2, out response2);
|
|
|
|
// legge delle coppie di valori INT, vanno trasformati in HEX e POI accodati, dove il primo è x 1 e il secondo x 10000 (in pratica va in testa)
|
|
|
|
// esempio 12540 --> diviso in 1 | 2540 --> in HEX diventa 1 | 9472, ma il 9472 va su byte[0] e 1 su byte[1]
|
|
|
|
|
|
// spostamento memorie: canale 65, 65.0 (era 50.15) x reset fineciclo; 65.1, era 53.10 scrittura pesatura
|
|
OMRON_ref.ReadWord(OmronFinsTCP.Net.PlcMemory.CIO, 0, out bit1);
|
|
OMRON_ref.ReadWord(OmronFinsTCP.Net.PlcMemory.CIO, 4, out bit2);
|
|
|
|
short[] valoriWord = new short[10];
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
valoriWord[i] = (short)i;
|
|
}
|
|
|
|
OMRON_ref.WriteWords(OmronFinsTCP.Net.PlcMemory.WR, 0, 10, valoriWord);
|
|
|
|
// init connessione
|
|
setConnection();
|
|
|
|
// test completo funzionalità OMRON, da TOGLIERE in prod...
|
|
#if DEBUG
|
|
omronFullTest();
|
|
#endif
|
|
}
|
|
/// <summary>
|
|
/// Test completo funzioni OMRON
|
|
/// </summary>
|
|
private void omronFullTest()
|
|
{
|
|
// faccio un try-catch di test vari...
|
|
#if false
|
|
try
|
|
{
|
|
//string connPar = string.Format("TCP {0}", cIobConf.cncIpAddr);
|
|
//OMRON_ref = new KRcc.Commu(connPar);
|
|
//OMRON_ref = new KRcc.Commu("TCP 192.168.0.92");
|
|
if (OMRON_ref.IsConnected)
|
|
{
|
|
// connect ok
|
|
resDataArray = OMRON_ref.command("where", 3000);
|
|
// WHERE [RET]
|
|
// Console.WriteLine(resDataArray[1]);
|
|
// [0] = 0
|
|
// [1] = JT1 JT2 JT3 JT4 JT5 JT6
|
|
// -23.205 - 39.967 - 13.176 95.663 71.402 - 21.512
|
|
// X[mm] Y[mm] Z[mm] O[deg] A[deg] T[deg]
|
|
// - 489.620 693.940 1564.733 92.612 131.285 7.482
|
|
|
|
threadOk = commThreadOk;
|
|
macName = machineName;
|
|
cStatus = currBitmapStatus;
|
|
cSignals = currBitmapSignals;
|
|
lastCountCNC = pzCounter;
|
|
numPzPrel = pzPrelevati;
|
|
lastRecTC = lastTC;
|
|
lastMissRobot = lastMission;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{ // e.Message = "can't connect TCP/IP" or // "can't login"
|
|
Console.WriteLine(e.Message);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Processo i task richiesti e li elimino dalla coda 1:1
|
|
/// </summary>
|
|
/// <param name="task2exe"></param>
|
|
public override Dictionary<string, string> executeTasks(Dictionary<string, string> task2exe)
|
|
{
|
|
// Verificare il protocollo: dovrebbe togliere SOLO i task eseguiti...
|
|
Dictionary<string, string> taskDone = new Dictionary<string, string>();
|
|
bool taskOk = false;
|
|
string taskVal = "";
|
|
#if false
|
|
|
|
// cerco task specifici: se ho startSetup --> imposto bit DBB701.DBB0.4
|
|
foreach (var item in task2exe)
|
|
{
|
|
taskOk = false;
|
|
taskVal = "";
|
|
// converto richiesta in enum...
|
|
taskType tName = taskType.nihil;
|
|
Enum.TryParse(item.Key, out tName);
|
|
// controllo sulla KEY
|
|
switch (tName)
|
|
{
|
|
case taskType.nihil:
|
|
case taskType.fixStopSetup:
|
|
case taskType.setArt:
|
|
case taskType.setComm:
|
|
case taskType.setProg:
|
|
case taskType.sendWatchDogMes2Plc:
|
|
taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC";
|
|
break;
|
|
case taskType.forceResetPzCount:
|
|
// reset contapezzi inizio setup
|
|
taskOk = resetContapezziCNC();
|
|
taskVal = taskOk ? "FORCE RESET PZ COUNT" : "FORCE RESET DISABLED | NO EXEC";
|
|
break;
|
|
case taskType.forceSetPzCount:
|
|
// reset contapezzi inizio setup
|
|
int newPzCount = 0;
|
|
int.TryParse(item.Value, out newPzCount);
|
|
if (newPzCount >= 0)
|
|
{
|
|
taskOk = setContapezziCNC(newPzCount);
|
|
taskVal = taskOk ? $"FORCE SET PZ COUNT TO {newPzCount}" : $"FORCE SET PZ COUNT TO {newPzCount} | NO EXEC";
|
|
}
|
|
else
|
|
{
|
|
taskVal = $"ERROR IN FORCE SET PZ COUNT TO {newPzCount}";
|
|
}
|
|
break;
|
|
case taskType.startSetup:
|
|
// reset contapezzi inizio setup
|
|
taskOk = resetContapezziCNC();
|
|
taskVal = taskOk ? "RESET: SETUP START" : "PZ RESET DISABLED | NO EXEC";
|
|
break;
|
|
case taskType.stopSetup:
|
|
// reset contapezzi fine setup // reset contapezzi fine setup SE ESPLICITAMENTE IMPOSTATO
|
|
if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET_stopSetup") == "TRUE")
|
|
{
|
|
resetContapezziCNC();
|
|
}
|
|
taskVal = taskOk ? "RESET: SETUP END" : "PZ RESET DISABLED | NO EXEC";
|
|
break;
|
|
default:
|
|
taskVal = "SKIPPED | NO EXEC";
|
|
break;
|
|
}
|
|
taskDone.Add(item.Key, taskVal);
|
|
}
|
|
#endif
|
|
|
|
return taskDone;
|
|
}
|
|
/// <summary>
|
|
/// Effettua reset del contapezzi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override bool resetContapezziCNC()
|
|
{
|
|
bool answ = false;
|
|
#if false
|
|
// ...SE abilitato da conf IOB
|
|
if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET") == "TRUE")
|
|
{
|
|
// scrivo valore 0 x il contapezzi
|
|
try
|
|
{
|
|
pzCounter = 0;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgError(exc, "Errore in RESET contapezzi OMRON");
|
|
connectionOk = false;
|
|
}
|
|
answ = true;
|
|
}
|
|
else
|
|
{
|
|
lgError("Impossibile effettuare RESET contapezzi OMRON, mancanza parametro OPT:ENABLE_PZ_RESET");
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Effettua IMPOSTAZIONE FORZATA del contapezzi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override bool setContapezziCNC(int newPzCount)
|
|
{
|
|
bool answ = false;
|
|
#if false
|
|
// ...SE abilitato da conf IOB
|
|
if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET") == "TRUE")
|
|
{
|
|
// scrivo valore 0 x il contapezzi
|
|
try
|
|
{
|
|
pzCounter = newPzCount;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgError(exc, "Errore in SET contapezzi OMRON");
|
|
connectionOk = false;
|
|
}
|
|
answ = true;
|
|
}
|
|
else
|
|
{
|
|
lgError("Impossibile effettuare SET contapezzi OMRON, mancanza parametro OPT:ENABLE_PZ_RESET");
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposto connessione
|
|
/// </summary>
|
|
protected virtual void setConnection()
|
|
{
|
|
// Creo oggetto connessione NC
|
|
parentForm.commPlcActive = true;
|
|
lgInfo("Start init Adapter OMRON all'IP {0} | --> IOB {1}", cIobConf.cncIpAddr, cIobConf.codIOB);
|
|
|
|
// inizializzo correttamente aree memoria secondo CONF - iniFileName
|
|
IniFile fIni = new IniFile(cIobConf.iniFileName);
|
|
// fix enable prgName
|
|
enablePrgName = fIni.ReadBoolean("CNC", "GETPRGNAME", true);
|
|
|
|
#if false
|
|
// SE è necessario refresh...
|
|
if (needRefresh)
|
|
{
|
|
lgInfo("Refreshing connection...");
|
|
// ora tento avvio PLC... SE PING OK...
|
|
if (testPing == IPStatus.Success)
|
|
{
|
|
try
|
|
{
|
|
string connPar = string.Format("TCP {0}", cIobConf.cncIpAddr);
|
|
OMRON_ref = new KRcc.Commu(connPar);
|
|
//OMRON_ref = new KRcc.Commu("TCP 192.168.0.92");
|
|
// disconnetto e connetto...
|
|
if (utils.CRB("verbose"))
|
|
{
|
|
lgInfo("OMRON: tryDisconnect");
|
|
}
|
|
|
|
//tryDisconnect();
|
|
//lgInfo("OMRON: tryConnect");
|
|
//tryConnect();
|
|
lgInfo("End init Adapter OMRON");
|
|
if (utils.CRB("verbose"))
|
|
{
|
|
lgInfo("OMRON CONNESSIONE AVVENUTA");
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgError(exc, "Errore in INIT OMRON Commu");
|
|
}
|
|
needRefresh = false;
|
|
}
|
|
parentForm.commPlcActive = false;
|
|
// gestione pzCounter
|
|
if (utils.CRB("enableContapezzi"))
|
|
{
|
|
lgInfo("OMRON: inizio gestione contapezzi");
|
|
try
|
|
{
|
|
// verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area)
|
|
if (cIobConf.optPar.Count > 0 && getOptPar("PZCOUNT_MODE") != "")
|
|
{
|
|
if (getOptPar("PZCOUNT_MODE").StartsWith("STD"))
|
|
{
|
|
pzCntReload(true);
|
|
// refresh associazione Macchina - IOB
|
|
sendM2IOB();
|
|
// per adesso imposto lettura fanuc == contapezzi (poi farà vera lettura...)
|
|
lastCountCNC = contapezzi;
|
|
}
|
|
else
|
|
{
|
|
contapezzi = 0;
|
|
lgInfo("Contapezzi STD disabilitato: modalità {0}", getOptPar("PZCOUNT_MODE"));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
contapezzi = 0;
|
|
lgInfo("Parametro mancante PZCOUNT_MODE");
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgError(exc, "Errore in contapezzi OMRON");
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
/// <summary>
|
|
/// Override disconnessione
|
|
/// </summary>
|
|
public override void tryDisconnect()
|
|
{
|
|
#if false
|
|
if (connectionOk)
|
|
{
|
|
string szStatusConnection = "";
|
|
try
|
|
{
|
|
OMRON_ref.disconnect();
|
|
connectionOk = false;
|
|
lgInfo(szStatusConnection);
|
|
lgInfo("Effettuata disconnessione adapter OMRON!");
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgFatal(exc, "Errore nella disconnessione dall'adapter OMRON");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lgError("IMPOSSIBILE effettuare disconnessione OMRON: Connessione non disponibile...");
|
|
}
|
|
#endif
|
|
}
|
|
/// <summary>
|
|
/// Override connessione
|
|
/// </summary>
|
|
public override void tryConnect()
|
|
{
|
|
#if false
|
|
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("OMRON: ConnKO - tryConnect");
|
|
}
|
|
// in primis salvo data ping...
|
|
lastPING = DateTime.Now;
|
|
// se passa il ping faccio il resto...
|
|
if (testPing == IPStatus.Success)
|
|
{
|
|
string szStatusConnection = "";
|
|
try
|
|
{
|
|
// ora provo connessione...
|
|
parentForm.commPlcActive = true;
|
|
string connPar = string.Format("TCP {0}", cIobConf.cncIpAddr);
|
|
OMRON_ref.connect(connPar);
|
|
parentForm.commPlcActive = false;
|
|
lgInfo("szStatusConnection: " + OMRON_ref.IsConnected);
|
|
connectionOk = true;
|
|
// refresh stato allarmi!!!
|
|
if (connectionOk)
|
|
{
|
|
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 OMRON: {0}{1}{2}", szStatusConnection, Environment.NewLine, exc));
|
|
connectionOk = false;
|
|
lgInfo(string.Format("Eccezione in TryConnect, Adapter OMRON 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: OMRON controllo PING fallito per IP {0}", cIobConf.cncIpAddr));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// se non è ancora connesso faccio procesisng memoria caso disconnesso...
|
|
if (!connectionOk)
|
|
{
|
|
// processo semafori ed invio...
|
|
processMemoryDiscon();
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// Oggetto per lettura counter pezzi PRELEVATI
|
|
/// </summary>
|
|
protected int pzPrelevati
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
#if false
|
|
if (OMRON_ref.IsConnected)
|
|
{
|
|
resDataArray = OMRON_ref.command("TYPE i_prelevati", 3000); // num pz prelevati --> "0\r\n"
|
|
int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out answ);
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Oggetto per lettura ULTIMO TC rilevato
|
|
/// </summary>
|
|
protected decimal lastTC
|
|
{
|
|
get
|
|
{
|
|
decimal answ = 0;
|
|
#if false
|
|
if (OMRON_ref.IsConnected)
|
|
{
|
|
resDataArray = OMRON_ref.command("TYPE r_tempo", 3000); // ultimo TCiclo rilevato --> " 349.19\r\n"
|
|
decimal.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", "").Replace(".", ","), out answ);
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Oggetto per lettura/scrittura counter pezzi robot
|
|
/// </summary>
|
|
protected int pzCounter
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
#if false
|
|
if (OMRON_ref.IsConnected)
|
|
{
|
|
resDataArray = OMRON_ref.command("TYPE i_cicli", 3000); // num cicli depositati/fatti --> " 0\r\n"
|
|
int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out answ);
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
#if false
|
|
if (OMRON_ref.IsConnected)
|
|
{
|
|
comando = string.Format("i_cicli={0}", value);
|
|
// scrivo valore cicli
|
|
resDataArray = OMRON_ref.command(comando, 3000); // imposto cicli depositati/fatti --> " 0\r\n"
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Verifica se il thread 4 di comm sia attivo
|
|
/// </summary>
|
|
protected bool commThreadOk
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
#if false
|
|
if (OMRON_ref.IsConnected)
|
|
{
|
|
int retVal = 0;
|
|
resDataArray = OMRON_ref.command("TYPE TASK (1004)", 3000); // thread 4 ok --> " 1\r\n"
|
|
int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out retVal);
|
|
answ = (retVal == 1);
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Recupera nome e seriale macchina
|
|
/// </summary>
|
|
protected string machineName
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
#if false
|
|
if (OMRON_ref.IsConnected)
|
|
{
|
|
resDataArray = OMRON_ref.command("TYPE $id_true", 3000); // id macchina --> "BX100N-B001 Sn. 2366\r\n"
|
|
answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "");
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Recupera ultima missione svolta
|
|
/// </summary>
|
|
protected string lastMission
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
#if false
|
|
if (OMRON_ref.IsConnected)
|
|
{
|
|
resDataArray = OMRON_ref.command("TYPE $exe", 3000); // missione --> "\r\n" (vuoto, no missione)
|
|
answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "");
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Restituisce stato macchina nel formato (da sx a dx):
|
|
/// B0: POWER_ON
|
|
/// B1: AUTO
|
|
/// B2: RUN
|
|
/// B3: ERROR
|
|
/// B4: ALLARME
|
|
/// B5: EMERGENZA OK
|
|
/// B6: PORTA CHIUSA
|
|
/// B7: PRONTO AL LOAD
|
|
/// </summary>
|
|
protected string currBitmapStatus
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
#if false
|
|
if (OMRON_ref.IsConnected)
|
|
{
|
|
resDataArray = OMRON_ref.command("TYPE $status", 3000); // status --> "0|0|1|0|0|1|0|0\r\n"
|
|
answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "").Replace("|", "");
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Restituisce SEGNALI macchina nel formato:
|
|
/// B0: Transfer in auto
|
|
/// B1: Punzonatrice in AUTO
|
|
/// B2: Barriera tavola ripristinata
|
|
/// B3: Aria in linea OK
|
|
/// B4: Console Transfer in fuori ingombro
|
|
/// B5: TAV A
|
|
/// B6: TAV B
|
|
/// B7: Richiesta accesso attiva
|
|
/// </summary>
|
|
protected string currBitmapSignals
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
#if false
|
|
if (OMRON_ref.IsConnected)
|
|
{
|
|
resDataArray = OMRON_ref.command("TYPE $signal", 3000); // segnali --> "1|0|1|1|1|0|0|0\r\n"
|
|
answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "").Replace("|", "");
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua salvataggio del programma corrente
|
|
/// </summary>
|
|
/// <param name="progDir">Dir di riferimento</param>
|
|
/// <param name="progName">Nome Programma (se mancasse *.as lo aggiunge)</param>
|
|
private void saveProgram(string progDir = "prog", string progName = "current.as")
|
|
{
|
|
#if false
|
|
// path completo
|
|
progName = progName.EndsWith(".as") ? progName : progName + ".as";
|
|
string prgPath = progName;// string.Format("{0}/{1}", progDir, progName);
|
|
if (OMRON_ref.IsConnected)
|
|
{
|
|
// comandi x setup programma...
|
|
resDataArray = OMRON_ref.command("ferma", 3000); // ferma processi (all) --> ""
|
|
resDataArray = OMRON_ref.command("togli", 3000); // toglie processi da pronta esecuzione --> ""
|
|
|
|
//resp = com.command("SAVE nome_del_file", 3000); // salvataggio file... FORSE --> "\u0005\u0002Bnome_del_file.as\u0017" --> verificare DOVE salva...
|
|
|
|
int ret = OMRON_ref.save(prgPath); // SAVE current.as[RET]
|
|
if (ret == 0)
|
|
{
|
|
// Success
|
|
}
|
|
if (ret == -1)
|
|
{
|
|
// Communication error
|
|
}
|
|
if (ret == -2)
|
|
{
|
|
// Robot Controller error
|
|
}
|
|
if (ret == -3)
|
|
{
|
|
// Internal error
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
/// <summary>
|
|
/// Effettua invio del programma di alvorazione al ROBOT
|
|
/// <param name="progDir">Dir di riferimento</param>
|
|
/// <param name="progName">Nome Programma (se mancasse *.as lo aggiunge)</param>
|
|
/// </summary>
|
|
private void sendProgram(string progDir = "prog", string progName = "default.as")
|
|
{
|
|
#if false
|
|
// path completo
|
|
progName = progName.EndsWith(".as") ? progName : progName + ".as";
|
|
string prgPath = progName;// string.Format("{0}/{1}", progDir, progName);
|
|
|
|
// comandi x setup programma...
|
|
resDataArray = OMRON_ref.command("ferma", 3000); // ferma processi (all) --> ""
|
|
resDataArray = OMRON_ref.command("togli", 3000); // toglie processi da pronta esecuzione --> ""
|
|
|
|
if (OMRON_ref.IsConnected)
|
|
{
|
|
// carico...
|
|
OMRON_ref.asInquiry = delegate (string as_msg)
|
|
{
|
|
Console.WriteLine(as_msg); if (as_msg.StartsWith("Are you sure ?"))
|
|
{
|
|
return "0\n"; // 0 [RET]
|
|
}
|
|
|
|
if (as_msg.StartsWith("Load data?"))
|
|
{
|
|
return "1\n"; // 1 [RET]
|
|
}
|
|
|
|
return null;
|
|
};
|
|
int retLoad = OMRON_ref.load(prgPath, "/Q"); // LOAD/Q default.as[RET]
|
|
}
|
|
#endif
|
|
}
|
|
|
|
|
|
#region Metodi specifici (da verificare/completare in implementazione)
|
|
|
|
|
|
/// <summary>
|
|
/// Effettua vero processing contapezzi
|
|
/// </summary>
|
|
public override void processContapezzi()
|
|
{
|
|
if (utils.CRB("enableContapezzi"))
|
|
{
|
|
#if false
|
|
try
|
|
{
|
|
// hard coded... !!!FARE!!! rivedere megio conf
|
|
lastCountCNC = pzCounter;
|
|
// verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area)
|
|
if (cIobConf.optPar.Count > 0 && getOptPar("PZCOUNT_MODE") != "")
|
|
{
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgError(exc, "Errore in contapezzi OMRON");
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Effettua processing del recupero delle OVERRIDE (spindle, feedrate, rapid)
|
|
/// </summary>
|
|
public override void processOverride()
|
|
{
|
|
}
|
|
/// <summary>
|
|
/// lettura bit semafori
|
|
/// </summary>
|
|
public override void readSemafori()
|
|
{
|
|
base.readSemafori();
|
|
if (verboseLog)
|
|
{
|
|
lgInfo("inizio read semafori");
|
|
}
|
|
|
|
parentForm.sIN = Semaforo.SV;
|
|
|
|
// effettuo TUTTE le letture
|
|
threadOk = commThreadOk;
|
|
cStatus = currBitmapStatus;
|
|
cSignals = currBitmapSignals;
|
|
lastCountCNC = pzCounter;
|
|
// decodifica e gestione
|
|
decodeToBaseBitmap();
|
|
decodeOtherData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua decodifica aree memoria alla bitmap usata x MAPO
|
|
/// </summary>
|
|
private void decodeToBaseBitmap()
|
|
{
|
|
// init a zero...
|
|
B_input = 0;
|
|
#if false
|
|
/* -----------------------------------------------------
|
|
* bitmap MAPO
|
|
* B0: POWER_ON
|
|
* B1: RUN
|
|
* B2: pzCount
|
|
* B3: allarme
|
|
* B4: manuale
|
|
* B5: emergenza
|
|
* B6: error prog
|
|
* B7: auto mode
|
|
----------------------------------------------------- */
|
|
// bit 0 (poweron) imposto a 1 SE connected...
|
|
B_input = OMRON_ref.IsConnected ? 1 : 0;
|
|
// RUN
|
|
if (cStatus[2] == '1')
|
|
{
|
|
B_input += (1 << 1);
|
|
}
|
|
// ERROR prog/macchina
|
|
if (cStatus[3] == '1')
|
|
{
|
|
B_input += (1 << 6);
|
|
}
|
|
// allarme
|
|
if (cStatus[4] == '1')
|
|
{
|
|
B_input += (1 << 3);
|
|
}
|
|
// Automatico (porta chiusa)
|
|
if (cStatus[6] == '1' || cStatus[1] == '1')
|
|
{
|
|
B_input += (1 << 4);
|
|
}
|
|
// NON EMERGENZA (1=armed, 0=triggered)
|
|
if (cStatus[5] == '0')
|
|
{
|
|
B_input += (1 << 5);
|
|
}
|
|
|
|
// process ODL e contapezzi
|
|
string currODL = "";
|
|
try
|
|
{
|
|
currODL = utils.callUrl(urlGetCurrODL);
|
|
// solo SE HO un ODL...
|
|
if (currODL == "" || currODL == "0")
|
|
{
|
|
if (periodicLog)
|
|
{
|
|
lgInfo(string.Format("OMRON | Lettura ODL andata a vuoto: currODL: {0}", currODL));
|
|
}
|
|
}
|
|
else
|
|
{ // se variato o scaduto timeout log...
|
|
if (periodicLog || (currIdxODL.ToString() != currODL))
|
|
{
|
|
lgInfo(string.Format("OMRON | Lettura ODL, currODL: {0} --> currIdxODL prec: {1}", currODL, currIdxODL));
|
|
}
|
|
// provo a salvare nuovo ODL
|
|
int.TryParse(currODL, out currIdxODL);
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
if (DateTime.Now.Subtract(lastWarnODL).TotalSeconds > 15)
|
|
{
|
|
lgError(exc, "Errore in fase di chiamata URL x ODL corrente | URL chiamato: {0}", urlGetCurrODL);
|
|
lastWarnODL = DateTime.Now;
|
|
}
|
|
}
|
|
if (currODL != null && currODL != "" && currODL != "0")
|
|
{
|
|
// ora processo il contapezzi...
|
|
// controllo se è passato intervallo minimo tra 2 controlli/elaborazioni x distanziare invio e ridurre letture
|
|
if (DateTime.Now >= lastPzCountSend.AddMilliseconds(pzCountDelay))
|
|
{
|
|
// se sono differenti MOSTRO...
|
|
if (lastCountCNC != contapezzi)
|
|
{
|
|
// registro contapezzi
|
|
lgInfo(string.Format("Differenza Contapezzi: READ: {0} | Interno {1}", lastCountCNC, contapezzi));
|
|
}
|
|
// verifico se variato contapezzi... 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 OMRON: {0} | Contapezzi interno {1}", lastCountCNC, contapezzi));
|
|
}
|
|
|
|
// invio a server contapezzi (aggiornato)
|
|
string retVal = utils.callUrl(urlSetPzCount + contapezzi.ToString());
|
|
// verifica se tutto OK
|
|
if (retVal != "OK")
|
|
{
|
|
// errore salvataggio contapezzi
|
|
lgInfo(string.Format("Errore salvataggio Contapezzi OMRON {0} | Contapezzi interno {1} | Errore salvataggio: {2}", lastCountCNC, contapezzi, retVal));
|
|
}
|
|
// resetto timer...
|
|
lastPzCountSend = DateTime.Now;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (DateTime.Now >= lastPzCountSend.AddMilliseconds(pzCountDelay))
|
|
{
|
|
lgInfo(string.Format("Attenzione: mancanza ODL non procedo con gestione contapezzi. Contapezzi OMRON {0} | Contapezzi interno {1}", lastCountCNC, contapezzi));
|
|
// resetto timer...
|
|
lastPzCountSend = DateTime.Now;
|
|
}
|
|
}
|
|
|
|
// log opzionale!
|
|
if (verboseLog)
|
|
{
|
|
lgInfo(string.Format("Trasformazione B_input: {0}", B_input));
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// Decodifica il resto dell'area x i dati accessori (allarmi, ...)
|
|
/// </summary>
|
|
private void decodeOtherData()
|
|
{
|
|
if (verboseLog)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero programma in lavorazione
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string getPrgName()
|
|
{
|
|
// valore non presente in vers default... se gestito fare override
|
|
string prgName = "";
|
|
return prgName;
|
|
}
|
|
/// <summary>
|
|
/// Recupero info sistema generiche
|
|
/// <returns></returns>
|
|
public override Dictionary<string, string> getSysInfo()
|
|
{
|
|
// valore non presente in vers default... se gestito fare override
|
|
Dictionary<string, string> outVal = new Dictionary<string, string>();
|
|
outVal.Add("MACHINE", machineName);
|
|
return outVal;
|
|
}
|
|
/// <summary>
|
|
/// Recupero dati dinamici...
|
|
/// </summary>
|
|
public override Dictionary<string, string> getDynData()
|
|
{
|
|
// valore non presente in vers default... se gestito fare override
|
|
Dictionary<string, string> outVal = new Dictionary<string, string>();
|
|
outVal.Add("LAST_MISS", lastMissRobot);
|
|
outVal.Add("LAST_TC", lastTC.ToString());
|
|
outVal.Add("NUM_PZ_PREL", pzPrelevati.ToString());
|
|
outVal.Add("NUM_PZ_LAV", pzCounter.ToString());
|
|
outVal.Add("CURR_SIGNALS", currBitmapSignals.ToString());
|
|
return outVal;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|