324 lines
11 KiB
C#
324 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CMSCncLib.CNC;
|
|
|
|
namespace MTC_Sim
|
|
{
|
|
public class AdapterFanuc : AdapterGeneric
|
|
{
|
|
protected FANUC FANUC_ref;
|
|
|
|
protected StatusBitMap CurrStatus;
|
|
protected StFlag8 Status8;
|
|
protected StFlag32 Status32;
|
|
|
|
/// <summary>
|
|
/// estende l'init della classe base...
|
|
/// </summary>
|
|
/// <param name="caller"></param>
|
|
/// <param name="adpConf"></param>
|
|
public AdapterFanuc(CMS_MachineSim caller, AdapterConf adpConf) : base(caller, adpConf)
|
|
{
|
|
Runtime.CreateNC();
|
|
|
|
FANUC_ref = (FANUC)Runtime.NC;
|
|
|
|
string szStatusConnection = "";
|
|
FANUC_ref.Connect(ref szStatusConnection);
|
|
|
|
}
|
|
/// <summary>
|
|
/// Effettuo lettura dei 16 byte di strobe/status
|
|
/// </summary>
|
|
public override void getStrobeStatus()
|
|
{
|
|
base.getStrobeStatus();
|
|
|
|
// se non sono connesso esco
|
|
if (!FANUC_ref.Connected) return;
|
|
|
|
// hard coded: leggo le 16 word standard dello strobe... R10516--> R10532
|
|
FANUC_ref.F_RW_Byte(R, FANUC.MemType.R, 10516, ref Strobes);
|
|
}
|
|
/// <summary>
|
|
/// processing strobe!
|
|
/// </summary>
|
|
public override void processStrobe()
|
|
{
|
|
}
|
|
/// <summary>
|
|
/// processing strobe degli allarmi
|
|
/// </summary>
|
|
public override void processAlarm()
|
|
{
|
|
base.processAlarm();
|
|
// controllo TUTTI i flag: se ce ne sono di alzati DEVO processare...
|
|
if (STRB_DW0 != StFlag32.NONE)
|
|
{
|
|
// blocco memoria x lettura dati
|
|
byte[] MemBlock = new byte[4];
|
|
StFlag32 AlarmBlock = 0;
|
|
allarme currAllarm;
|
|
// primo blocco memoria allarmi
|
|
int memIndex = 10532;
|
|
// verifico gli allarmi di tutti i bit alzati...
|
|
for (int i = 0; i < 32; i++)
|
|
{
|
|
if (STRB_DW0.getBit<StFlag32>(i))
|
|
{
|
|
// recupero tutti i 32 bit del blocco
|
|
FANUC_ref.F_RW_Byte(R, FANUC.MemType.R, memIndex + i * 4, ref MemBlock);
|
|
AlarmBlock = (StFlag32)BitConverter.ToUInt32(MemBlock, 0);
|
|
for (int j = 0; j < 32; j++)
|
|
{
|
|
// converto!
|
|
// e aggiungo allarmi sollevati al corretto controller allarmi...
|
|
if (AlarmBlock.getBit<StFlag32>(j))
|
|
{
|
|
// recupero allarme da oggetto in memoria...
|
|
currAllarm= elencoAllarmi[i * 32 + j];
|
|
// in base al gruppo decido dove assegnare come CONDITION...
|
|
switch(currAllarm.gruppo)
|
|
{
|
|
case "PLC":
|
|
mAlarmPLC.Add(MTConnect.Condition.Level.FAULT, currAllarm.descrizione, currAllarm.codNum, "", "");
|
|
break;
|
|
case "CNC":
|
|
default:
|
|
mAlarmCNC.Add(MTConnect.Condition.Level.FAULT, currAllarm.descrizione, currAllarm.codNum, "", "");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// processing!
|
|
/// </summary>
|
|
public override void processStatus()
|
|
{
|
|
base.processStrobe();
|
|
|
|
// update status da DW3
|
|
|
|
// EMstop: verifico BIT e di conseguenza imposto
|
|
if (STRB_DW3.HasFlag(StFlag32.B00))
|
|
{
|
|
mEStop.Value = "TRIGGERED";
|
|
}
|
|
else
|
|
{
|
|
mEStop.Value = "ARMED";
|
|
}
|
|
|
|
// HARD CODE: forzo path 1 (indice 0...)
|
|
int idxPath = 0;
|
|
// switch su run mode...
|
|
switch (STRB_DW3)
|
|
{
|
|
case StFlag32.B01:
|
|
vettPath[idxPath].mPathRunMode.Value = "AUTO";
|
|
break;
|
|
case StFlag32.B02:
|
|
vettPath[idxPath].mPathRunMode.Value = "EDIT";
|
|
break;
|
|
case StFlag32.B03:
|
|
vettPath[idxPath].mPathRunMode.Value = "MDI";
|
|
break;
|
|
case StFlag32.B04:
|
|
vettPath[idxPath].mPathRunMode.Value = "REF";
|
|
break;
|
|
case StFlag32.B05:
|
|
vettPath[idxPath].mPathRunMode.Value = "JOG";
|
|
break;
|
|
case StFlag32.B06:
|
|
vettPath[idxPath].mPathRunMode.Value = "JOGINC";
|
|
break;
|
|
case StFlag32.B07:
|
|
vettPath[idxPath].mPathRunMode.Value = "HANDLE";
|
|
break;
|
|
}
|
|
// switch su EXE mode...
|
|
switch (STRB_DW3)
|
|
{
|
|
case StFlag32.B08:
|
|
vettPath[idxPath].mPathExeMode.Value = "RUN";
|
|
break;
|
|
case StFlag32.B09:
|
|
vettPath[idxPath].mPathExeMode.Value = "READY";
|
|
break;
|
|
case StFlag32.B10:
|
|
vettPath[idxPath].mPathExeMode.Value = "HOLD";
|
|
break;
|
|
case StFlag32.B11:
|
|
vettPath[idxPath].mPathExeMode.Value = "FEEDHOLD";
|
|
break;
|
|
}
|
|
|
|
// verifico tipo path...
|
|
if (STRB_DW3.HasFlag(StFlag32.B12))
|
|
{
|
|
vettPath[idxPath].mPathType.Value = "LAVORO";
|
|
}
|
|
else
|
|
{
|
|
vettPath[idxPath].mPathType.Value = "ASSERV";
|
|
}
|
|
|
|
|
|
|
|
#if false
|
|
|
|
// IPOTESI DA VERIFICARE!!!
|
|
// leggo primo byte, i cui bit indicano run mode (3450.0 --> 3450.7)
|
|
RunStatus = (StFlag8)status[0];
|
|
// leggo primo byte, i cui bit indicano run mode (3451.0 --> 3451.7)
|
|
ExeStatus = (StFlag8)status[1];
|
|
|
|
// se devo prendere sotto insiemi di byte --> BitConverter
|
|
//BitConverter.ToUInt32
|
|
|
|
// check bit 0... SE è presente
|
|
Status8.Has(StFlag8.B0);
|
|
|
|
// check bit 0... SE è SOLO QUELLO
|
|
Status8.Is(StFlag8.B0);
|
|
|
|
// check bit 18...
|
|
Status8.Has(StFlag32.B18);
|
|
#endif
|
|
}
|
|
|
|
public override void getCurrProgramData()
|
|
{
|
|
// serve?!?
|
|
base.getCurrProgramData();
|
|
}
|
|
|
|
public override void getPath()
|
|
{
|
|
base.getPath();
|
|
|
|
// ciclo sui PATH!!! FARE!!!!
|
|
|
|
// byte x lettura memoria... 8byte --> 64 bit!
|
|
byte[] status = new byte[8];
|
|
// variabili che utilizzerò...
|
|
StFlag8 RunStatus;
|
|
StFlag8 ExeStatus;
|
|
|
|
|
|
// se non sono connesso esco
|
|
if (!FANUC_ref.Connected) return;
|
|
|
|
// hard coded: leggo 8 word (byte) dalla memoria 3450--> 3457
|
|
FANUC_ref.F_RW_Byte(R, FANUC.MemType.D, 3450, ref status);
|
|
|
|
#if false
|
|
// imposto RUN mode
|
|
mMode.Value = parentForm.datiProd.RunMode;
|
|
|
|
// imposto EXE mode
|
|
mExec.Value = parentForm.datiProd.ExeMode;
|
|
|
|
vettPath[PtData.PathSel].mPathFeed.Value = PtData.PathFeedrate;
|
|
vettPath[PtData.PathSel].mPathFeedOver.Value = PtData.PathFeedrateOver;
|
|
vettPath[PtData.PathSel].mPathRapidOver.Value = PtData.PathRapidOver;
|
|
vettPath[PtData.PathSel].mPathPosActX.Value = PtData.PathPosAct.x;
|
|
vettPath[PtData.PathSel].mPathPosActY.Value = PtData.PathPosAct.y;
|
|
vettPath[PtData.PathSel].mPathPosActZ.Value = PtData.PathPosAct.z;
|
|
vettPath[PtData.PathSel].mPathPosActI.Value = PtData.PathPosAct.i;
|
|
vettPath[PtData.PathSel].mPathPosActJ.Value = PtData.PathPosAct.j;
|
|
vettPath[PtData.PathSel].mPathPosActK.Value = PtData.PathPosAct.k;
|
|
#endif
|
|
|
|
// HARD CODE: forzo path 1 (indice 0...)
|
|
int idxPath = 0;
|
|
|
|
|
|
|
|
// IPOTESI DA VERIFICARE!!!
|
|
// leggo primo byte, i cui bit indicano run mode (3450.0 --> 3450.7)
|
|
RunStatus = (StFlag8)status[0];
|
|
// leggo primo byte, i cui bit indicano run mode (3451.0 --> 3451.7)
|
|
ExeStatus = (StFlag8)status[1];
|
|
|
|
// se devo prendere sotto insiemi di byte --> BitConverter
|
|
//BitConverter.ToUInt32
|
|
|
|
// RUN STATUS: verifico BIT e di conseguenza imposto
|
|
switch (RunStatus)
|
|
{
|
|
case StFlag8.NONE:
|
|
break;
|
|
case StFlag8.B0:
|
|
vettPath[idxPath].mPathRunMode.Value = "AUTO";
|
|
break;
|
|
case StFlag8.B1:
|
|
vettPath[idxPath].mPathRunMode.Value = "EDIT";
|
|
break;
|
|
case StFlag8.B2:
|
|
vettPath[idxPath].mPathRunMode.Value = "MDI";
|
|
break;
|
|
case StFlag8.B3:
|
|
break;
|
|
case StFlag8.B4:
|
|
vettPath[idxPath].mPathRunMode.Value = "REF";
|
|
break;
|
|
case StFlag8.B5:
|
|
vettPath[idxPath].mPathRunMode.Value = "JOG";
|
|
break;
|
|
case StFlag8.B6:
|
|
vettPath[idxPath].mPathRunMode.Value = "JOGINC";
|
|
break;
|
|
case StFlag8.B7:
|
|
vettPath[idxPath].mPathRunMode.Value = "HANDLE";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
// EXE STATUS: verifico BIT e di conseguenza imposto
|
|
switch (ExeStatus)
|
|
{
|
|
case StFlag8.NONE:
|
|
break;
|
|
case StFlag8.B0:
|
|
break;
|
|
case StFlag8.B1:
|
|
break;
|
|
case StFlag8.B2:
|
|
break;
|
|
case StFlag8.B3:
|
|
break;
|
|
case StFlag8.B4:
|
|
break;
|
|
case StFlag8.B5:
|
|
break;
|
|
case StFlag8.B6:
|
|
break;
|
|
case StFlag8.B7:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
#if false
|
|
// check bit 0... SE è presente
|
|
Status8.Has(StFlag8.B0);
|
|
|
|
// check bit 0... SE è SOLO QUELLO
|
|
Status8.Is(StFlag8.B0);
|
|
|
|
// check bit 18...
|
|
Status8.Has(StFlag32.B18);
|
|
#endif
|
|
}
|
|
|
|
}
|
|
}
|