Completata review del simulatore/demo dell'adapter...

This commit is contained in:
Samuele E. Locatelli
2016-05-13 18:11:31 +02:00
parent 719b291747
commit d2459eaebc
13 changed files with 415 additions and 342 deletions
+1 -1
View File
@@ -12,6 +12,7 @@
<DataItem category="SAMPLE" id="POWER" type="WATTAGE"/>
<DataItem category="EVENT" id="OperatorId" type="MESSAGE"/>
<DataItem category="EVENT" id="FUNCT_MODE" type="MESSAGE"/>
<DataItem category="EVENT" id="UserAction" type="MESSAGE"/>
<DataItem category="CONDITION" id="CNC" type="SYSTEM"/>
<DataItem category="CONDITION" id="PLC" type="LOGIC"/>
</DataItems>
@@ -152,7 +153,6 @@
<DataItem category="EVENT" id="Path_01_ActiveAxes" type="ACTIVE_AXES"/>
<DataItem category="EVENT" id="Path_01_CodG_Act" type="MESSAGE"/>
<DataItem category="EVENT" id="Path_01_SubMode" type="MESSAGE"/>
<DataItem category="EVENT" id="Path_01_UserAction" type="MESSAGE"/>
<DataItem category="EVENT" id="Path_01_PartId" type="PART_ID"/>
<DataItem category="EVENT" id="Path_01_PZ_TOT" type="PART_COUNT"/>
<DataItem category="EVENT" id="Path_01_Cod_M" type="MESSAGE"/>
Binary file not shown.
@@ -241,10 +241,6 @@
<Key>Path_01_SubMode</Key>
<Value>FLAG#R10528.0:R10531.7</Value>
</dataRef>
<dataRef>
<Key>Path_01_UserAction</Key>
<Value>STROBE#R10520.4:R10520.6</Value>
</dataRef>
</dataRefList>
</element>
</Path>
+64 -13
View File
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<AdapterConf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<etipoAdapt>Demo</etipoAdapt>
<Version>1</Version>
<NomeAdapt>CMS_ADAPTER_00</NomeAdapt>
<TipoAdapt>Demo</TipoAdapt>
<TipoAdapt>DEMO</TipoAdapt>
<VacuumPump>
<element>
<ident>VacPump_01</ident>
@@ -33,7 +32,7 @@
<ident>VacAct_01</ident>
<alias>Attuatore vuoto 1</alias>
<fonte>Random</fonte>
<dataRefList>
<dataRefList>ù
<dataRef>
<Key>VacAct_01_Count</Key>
<Value>0#15</Value>
@@ -156,39 +155,91 @@
<dataRefList>
<dataRef>
<Key>Path_01_FeedRate</Key>
<Value>0#15</Value>
<Value>INT#D8888.0</Value>
</dataRef>
<dataRef>
<Key>Path_01_FeedOverr</Key>
<Value>16#31</Value>
<Value>INT#D8888.0</Value>
</dataRef>
<dataRef>
<Key>Path_01_SpeedOverr</Key>
<Value>32#47</Value>
<Key>Path_01_RapidOverr</Key>
<Value>INT#D8888.0</Value>
</dataRef>
<dataRef>
<Key>Path_01_PosActX</Key>
<Value>48#63</Value>
<Value>FLOAT#D7777.0</Value>
</dataRef>
<dataRef>
<Key>Path_01_PosActY</Key>
<Value>64#79</Value>
<Value>FLOAT#D7777.1</Value>
</dataRef>
<dataRef>
<Key>Path_01_PosActZ</Key>
<Value>80#95</Value>
<Value>FLOAT#D7777.2</Value>
</dataRef>
<dataRef>
<Key>Path_01_PosActI</Key>
<Value>96#111</Value>
<Value>FLOAT#D7777.3</Value>
</dataRef>
<dataRef>
<Key>Path_01_PosActJ</Key>
<Value>112#127</Value>
<Value>FLOAT#D7777.4</Value>
</dataRef>
<dataRef>
<Key>Path_01_PosActK</Key>
<Value>128#143</Value>
<Value>FLOAT#D7777.5</Value>
</dataRef>
<dataRef>
<Key>Path_01_Type</Key>
<Value>FLAG#R10528.12</Value>
</dataRef>
<dataRef>
<Key>Path_01_PartId</Key>
<Value>INT#D9999</Value>
</dataRef>
<dataRef>
<Key>Path_01_PZ_TOT</Key>
<Value>INT#D9999</Value>
</dataRef>
<dataRef>
<Key>Path_01_Cod_M</Key>
<Value>STROBE#R10520.0</Value>
</dataRef>
<dataRef>
<Key>Path_01_Cod_S</Key>
<Value>STROBE#R10520.1</Value>
</dataRef>
<dataRef>
<Key>Path_01_Cod_T</Key>
<Value>STROBE#R10520.2</Value>
</dataRef>
<dataRef>
<Key>Path_01_RUN_MODE</Key>
<Value>FLAG#R10528.1:R10528.7</Value>
</dataRef>
<dataRef>
<Key>Path_01_EXE_MODE</Key>
<Value>FLAG#R10528.8:R10528.11</Value>
</dataRef>
<dataRef>
<Key>Path_01_CurrProg</Key>
<Value>STRING#D0000</Value>
</dataRef>
<dataRef>
<Key>Path_01_CurrProg_RowNum</Key>
<Value>INT#D0001.0</Value>
</dataRef>
<dataRef>
<Key>Path_01_ActiveAxes</Key>
<Value>CLASS</Value>
</dataRef>
<dataRef>
<Key>Path_01_CodG_Act</Key>
<Value>CLASS</Value>
</dataRef>
<dataRef>
<Key>Path_01_SubMode</Key>
<Value>FLAG#R10528.0:R10531.7</Value>
</dataRef>
</dataRefList>
</element>
+14 -46
View File
@@ -19,6 +19,7 @@ namespace MTC_Sim
/// <param name="adpConf"></param>
public AdapterDemo(CMS_MachineSim caller, AdapterConf adpConf) : base(caller, adpConf)
{
if (utils.CRB("verbose")) lg.Info("Start init Adapter DEMO");
// IMPLICITO: carica da metodo base tutte le specifiche del conf...
@@ -83,55 +84,22 @@ namespace MTC_Sim
}
protected void addSystemAlarm(int numAllarme)
{
mAlarmSystem.Add(Condition.Level.FAULT, string.Format("ERR_{0:###}: Errore", numAllarme), string.Format("ERR_{0:###}", numAllarme));
}
protected void addPlcAlarm(int numAllarme)
{
mAlarmPLC.Add(Condition.Level.FAULT, string.Format("ERR_{0:###}: Errore", numAllarme), string.Format("ERR_{0:###}", numAllarme));
}
protected void addCncAlarm(int numAllarme)
{
mAlarmCNC.Add(Condition.Level.FAULT, string.Format("ERR_{0:###}: Errore", numAllarme), string.Format("ERR_{0:###}", numAllarme));
}
protected void addGenericAlarm(DataRefItem<int, string> allarme)
{
mAlarmGeneral.Add(Condition.Level.FAULT, string.Format("ERR_{0:###}: Errore {1}", allarme.Key, allarme.Value), string.Format("ERR_{0:###}_{1}", allarme.Key, allarme.Value));
}
public override void processStrobe()
{
base.processStrobe();
if (parentForm.systemAlarm.Count > 0)
{
foreach (Int32 alarm in parentForm.systemAlarm)
{
addSystemAlarm(alarm);
}
}
if (parentForm.plcAlarm.Count > 0)
{
foreach (Int32 alarm in parentForm.plcAlarm)
{
addPlcAlarm(alarm);
}
}
if (parentForm.cncAlarm.Count > 0)
{
foreach (Int32 alarm in parentForm.cncAlarm)
{
addCncAlarm(alarm);
}
}
if (parentForm.genericAlarm.Count > 0)
{
foreach (DataRefItem<int, string> alarm in parentForm.genericAlarm)
{
addGenericAlarm(alarm);
}
}
// qui forzo la gestione di update dei path & co...
getPath();
getUnOp();
getAxis();
}
/// <summary>
/// non fa nulla perché recupera allarmi in vettore al singolo cambio...
/// </summary>
/// <param name="Alarm2Refresh"></param>
/// <param name="giveAck"></param>
public override void refreshAlarmState(StFlag32 Alarm2Refresh, bool giveAck)
{
base.refreshAlarmState(Alarm2Refresh, giveAck);
}
public override void getPath()
+13 -47
View File
@@ -23,7 +23,7 @@ namespace MTC_Sim
FANUC_ref = (FANUC)Runtime.NC;
if (utils.CRB("verbose")) lg.Info("FANUC_ref da CMSCncLib");
// disconnetto e connetto...
if (utils.CRB("verbose")) lg.Info("FANUC: tryDisconnect");
tryDisconnect();
@@ -177,7 +177,7 @@ namespace MTC_Sim
reloadDataFromFile();
// memorizzo allarme nel vettore ack....
retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, 1, bitNum);
retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
}
// AREA strobe USER ACTION
@@ -193,7 +193,7 @@ namespace MTC_Sim
gestStrobeUserAction(bitNum, ref retACK_DW1, ref UserAction, "# RESET # ");
// se ci sono state azioni (1 o +) le invio...
if (UserAction != "") vettPath[idxPath].mPathUserAction.Value = UserAction.Trim();
if (UserAction != "") mUserAction.Value = UserAction.Trim();
}
else
{
@@ -241,7 +241,7 @@ namespace MTC_Sim
}
}
// memorizzo allarme nel vettore ack....
retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, 1, bitNum);
retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
}
}
/// <summary>
@@ -266,7 +266,7 @@ namespace MTC_Sim
// salvo evento UserAction in variabile...
UserAction += azione;
// memorizzo allarme nel vettore ack....
retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, 1, bitNum);
retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
}
}
/// <summary>
@@ -338,7 +338,7 @@ namespace MTC_Sim
}
// segnalo allarme letto! memorizzo allarme nel vettore ack....
retACK_DW0 = utils.setBitOnStFlag(retACK_DW0, 1, i);
retACK_DW0 = utils.setBitOnStFlag(retACK_DW0, true, i);
}
}
// scrivo ack se richiesto!!!
@@ -380,47 +380,13 @@ namespace MTC_Sim
}
}
}
/// <summary>
/// processing strobe degli allarmi
/// </summary>
public override void processAlarm()
{
base.processAlarm();
if (AlarmFlags != null)
{
// variabili helper
StFlag32 AlarmBlock = 0;
allarme currAllarm;
// controllo TUTTI i bit della variabile COMPLETA degli status allarmi: se ce ne sono di alzati DEVO processare...
for (int i = 0; i < AlarmFlags.Length / 4; i++)
{
// leggo 32bit alla volta...
AlarmBlock = (StFlag32)BitConverter.ToUInt32(AlarmFlags, i * 4);
for (int j = 0; j < 32; j++)
{
// converto! e aggiungo allarmi sollevati al corretto controller allarmi...
if (AlarmBlock.HasFlag((StFlag32)Math.Pow(2, 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 strobe degli allarmi
///// </summary>
//public override void processAlarm()
//{
// base.processAlarm();
//}
/// <summary>
/// processing!
/// </summary>
+45 -46
View File
@@ -293,10 +293,6 @@ namespace MTC_Sim
/// </summary>
public Event mPathSubMode;
/// <summary>
/// Azione utente START/STOP/RESET
/// </summary>
public Event mPathUserAction;
/// <summary>
/// Allarmi CNC del PATH
/// </summary>
public Condition mPathAlarmCNC;
@@ -341,7 +337,6 @@ namespace MTC_Sim
mPathActiveAxes = new Event(dataRefList[19].Key);
mPathCodG_Act = new Event(dataRefList[20].Key);
mPathSubMode = new Event(dataRefList[21].Key);
mPathUserAction = new Event(dataRefList[22].Key);
mPathAlarmCNC = new Condition(string.Format("{0}_AlarmCNC", ident));
mPathAlarmPLC = new Condition(string.Format("{0}_AlarmPLC", ident));
}
@@ -689,6 +684,10 @@ namespace MTC_Sim
/// modalità funzionale
/// </summary>
public Event mFunctionalMode = new Event("FUNCT_MODE");
/// <summary>
/// Azioni operatore (Start/Stop/reset)
/// </summary>
public Event mUserAction = new Event("UserAction");
@@ -758,6 +757,7 @@ namespace MTC_Sim
// modalità esecutiva e funzionale
mAdapter.AddDataItem(mFunctionalMode);
mAdapter.AddDataItem(mUserAction);
// Pompe vuoto
vettVacPump = new VacuumPomp[adpConf.nVacuumPump];
@@ -812,6 +812,7 @@ namespace MTC_Sim
for (int i = 0; i < adpConf.nPath; i++)
{
vettPath[i] = new Path(adpConf.Path[i]);
mAdapter.AddDataItem(vettPath[i].mPathAlias);
mAdapter.AddDataItem(vettPath[i].mPathFeed);
mAdapter.AddDataItem(vettPath[i].mPathFeedOver);
mAdapter.AddDataItem(vettPath[i].mPathRapidOver);
@@ -833,7 +834,12 @@ namespace MTC_Sim
mAdapter.AddDataItem(vettPath[i].mPathCurrProg);
mAdapter.AddDataItem(vettPath[i].mPathCurrProgRowNum);
mAdapter.AddDataItem(vettPath[i].mPathActiveAxes);
mAdapter.AddDataItem(vettPath[i].mPathCodG_Act);
mAdapter.AddDataItem(vettPath[i].mPathSubMode);
// aggiungo condizioni allarme...
mAdapter.AddDataItem(vettPath[i].mPathAlarmCNC);
mAdapter.AddDataItem(vettPath[i].mPathAlarmPLC);
// altre aggiunte
}
// UnOp
@@ -932,7 +938,7 @@ namespace MTC_Sim
string linea;
totRighe = File.ReadLines(fileName).Count();
// inizializzo
elencoSubMode.Clear();
elencoSubMode = new Dictionary<string, string>();
// carica da file...
System.IO.StreamReader file = new System.IO.StreamReader(fileName);
// leggo 1 linea alla volta...
@@ -1219,7 +1225,39 @@ namespace MTC_Sim
/// </summary>
public virtual void processAlarm()
{
// da gestire su ogni adapter...
if (AlarmFlags != null)
{
// variabili helper
StFlag32 AlarmBlock = 0;
allarme currAllarm;
// controllo TUTTI i bit della variabile COMPLETA degli status allarmi: se ce ne sono di alzati DEVO processare...
for (int i = 0; i < AlarmFlags.Length / 4; i++)
{
// leggo 32bit alla volta...
AlarmBlock = (StFlag32)BitConverter.ToUInt32(AlarmFlags, i * 4);
for (int j = 0; j < 32; j++)
{
// converto! e aggiungo allarmi sollevati al corretto controller allarmi...
if (AlarmBlock.HasFlag((StFlag32)Math.Pow(2, 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>
@@ -1250,45 +1288,6 @@ namespace MTC_Sim
public void checkPath()
{
#if false
// controllo feed e velocità
if (utils.IsSetAny(STROBE_PLC, Strobe.FEED_SPEED))
{
// leggo i valori feed/speed
mPathFeed.Value = FeedRate;
mPathFeedOver.Value = FeedRateOver;
mPathSpeedOver.Value = SpeedRateOver;
// alzo flag lettura...
if (utils.IsSetAll(STROBE_PLC, Strobe.FEED_SPEED)) STROBE_ADP = STROBE_ADP | Strobe.FEED_SPEED;
}
else
{
// resetto eventuali flag di lettura...
if (utils.IsSetAll(STROBE_ADP, Strobe.FEED_SPEED)) STROBE_ADP -= Strobe.FEED_SPEED;
}
// controllo posizione...
if (utils.IsSetAny(STROBE_PLC, Strobe.POS_ACT))
{
// leggo i valori posizione attuale
mPathPosActX.Value = PosAct.x;
mPathPosActY.Value = PosAct.y;
mPathPosActZ.Value = PosAct.z;
mPathPosActI.Value = PosAct.i;
mPathPosActJ.Value = PosAct.j;
mPathPosActK.Value = PosAct.k;
// alzo flag lettura...
if (utils.IsSetAll(STROBE_PLC, Strobe.POS_ACT)) STROBE_ADP = STROBE_ADP | Strobe.POS_ACT;
}
else
{
// resetto eventuali flag di lettura...
if (utils.IsSetAll(STROBE_ADP, Strobe.POS_ACT)) STROBE_ADP -= Strobe.POS_ACT;
}
#endif
}
/// <summary>
+14 -29
View File
@@ -1,33 +1,18 @@
#fix simulation:
- meno frequente modifiche produzione...
- posizione attuale/sim meno "ballerina"
ATTENZIONE: aggiungere pos memoria x status e strobe x path
0) chiusura app --> FANUC_ref.disconnect
OK 1) rivedere GetBit (cambiare!!!)
OK 2) strobe allarmi --> su cambio fronte --> serve vettore stato COMPLETO allarmi
OK 3) lo strobe allarmi va inizializzato all'avvio (carica TUTTI i bit...)
OK 4) da strobe allarmi --> vettore allarmi
OK 5) CodS 5 cifre
OK 6) CodM/CodT 3 cifre
7) lettura assi: vedere in progetto CMSConnect in OpPanel di FANUC la RefreshAxisNames()
8) lettura strobe e registrazione NUOVO flusso EVENT x START/STOP/RESET (1 solo con 3 strobe separati) -->gestire!!!
Classi x lettura assi
feedrate C:\Users\samuele.STEAMWAREWIN\Documents\VisualStudioProjects\CMS_orig\A02B-0207-K737_04.20\Document\SpecE\Position\cnc_actf.htm
pos abs C:\Users\samuele.STEAMWAREWIN\Documents\VisualStudioProjects\CMS_orig\A02B-0207-K737_04.20\Document\SpecE\Position\cnc_absolute2.htm
ALL? C:\Users\samuele.STEAMWAREWIN\Documents\VisualStudioProjects\CMS_orig\A02B-0207-K737_04.20\Document\SpecE\Position\cnc_rdaxisdata.htm
OK 00) chiusura app --> FANUC_ref.disconnect
OK 01) rivedere GetBit (cambiare!!!)
OK 02) strobe allarmi --> su cambio fronte --> serve vettore stato COMPLETO allarmi
OK 03) lo strobe allarmi va inizializzato all'avvio (carica TUTTI i bit...)
OK 04) da strobe allarmi --> vettore allarmi
OK 05) CodS 5 cifre
OK 06) CodM/CodT 3 cifre
07) lettura assi: vedere in progetto CMSConnect in OpPanel di FANUC la RefreshAxisNames()
- feedrate C:\Users\samuele.STEAMWAREWIN\Documents\VisualStudioProjects\CMS_orig\A02B-0207-K737_04.20\Document\SpecE\Position\cnc_actf.htm
- pos abs C:\Users\samuele.STEAMWAREWIN\Documents\VisualStudioProjects\CMS_orig\A02B-0207-K737_04.20\Document\SpecE\Position\cnc_absolute2.htm
- ALL? C:\Users\samuele.STEAMWAREWIN\Documents\VisualStudioProjects\CMS_orig\A02B-0207-K737_04.20\Document\SpecE\Position\cnc_rdaxisdata.htm
OK 08) lettura strobe e registrazione NUOVO flusso EVENT x START/STOP/RESET (1 solo con 3 strobe separati) --> gestire!!!
OK 09) update gestione SUB MODE
OK 10) riallineamento simulatore generico
- update gestione SUB MODE
- update gestione 4 nuovi strobe
- riallineamento simulatore generico
+96 -71
View File
@@ -137,6 +137,12 @@
this.tabCtrlMain = new System.Windows.Forms.TabControl();
this.tpStatus = new System.Windows.Forms.TabPage();
this.groupBox6 = new System.Windows.Forms.GroupBox();
this.STATUS_ACK_DW3 = new System.Windows.Forms.TextBox();
this.label52 = new System.Windows.Forms.Label();
this.STATUS_ACK_DW2 = new System.Windows.Forms.TextBox();
this.label51 = new System.Windows.Forms.Label();
this.STATUS_ACK_DW1 = new System.Windows.Forms.TextBox();
this.label50 = new System.Windows.Forms.Label();
this.STATUS_ACK_DW0 = new System.Windows.Forms.TextBox();
this.label48 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
@@ -202,12 +208,7 @@
this.lblCodaM = new System.Windows.Forms.Label();
this.addCodM = new System.Windows.Forms.TextBox();
this.label20 = new System.Windows.Forms.Label();
this.STATUS_ACK_DW1 = new System.Windows.Forms.TextBox();
this.label50 = new System.Windows.Forms.Label();
this.STATUS_ACK_DW2 = new System.Windows.Forms.TextBox();
this.label51 = new System.Windows.Forms.Label();
this.STATUS_ACK_DW3 = new System.Windows.Forms.TextBox();
this.label52 = new System.Windows.Forms.Label();
this.ErrRT_03 = new System.Windows.Forms.CheckBox();
this.groupBox4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.PosAct)).BeginInit();
this.groupBox3.SuspendLayout();
@@ -239,8 +240,9 @@
this.PlcErr_02.Name = "PlcErr_02";
this.PlcErr_02.Size = new System.Drawing.Size(72, 17);
this.PlcErr_02.TabIndex = 6;
this.PlcErr_02.Text = "PlcErr_02";
this.PlcErr_02.Text = "PlcErr_05";
this.PlcErr_02.UseVisualStyleBackColor = true;
this.PlcErr_02.CheckedChanged += new System.EventHandler(this.SysErr_01_CheckedChanged);
//
// gather
//
@@ -451,8 +453,9 @@
this.PlcErr_03.Name = "PlcErr_03";
this.PlcErr_03.Size = new System.Drawing.Size(72, 17);
this.PlcErr_03.TabIndex = 5;
this.PlcErr_03.Text = "PlcErr_03";
this.PlcErr_03.Text = "PlcErr_06";
this.PlcErr_03.UseVisualStyleBackColor = true;
this.PlcErr_03.CheckedChanged += new System.EventHandler(this.SysErr_01_CheckedChanged);
//
// PlcErr_01
//
@@ -461,11 +464,13 @@
this.PlcErr_01.Name = "PlcErr_01";
this.PlcErr_01.Size = new System.Drawing.Size(72, 17);
this.PlcErr_01.TabIndex = 4;
this.PlcErr_01.Text = "PlcErr_01";
this.PlcErr_01.Text = "PlcErr_04";
this.PlcErr_01.UseVisualStyleBackColor = true;
this.PlcErr_01.CheckedChanged += new System.EventHandler(this.SysErr_01_CheckedChanged);
//
// groupBox3
//
this.groupBox3.Controls.Add(this.ErrRT_03);
this.groupBox3.Controls.Add(this.ErrRT_02);
this.groupBox3.Controls.Add(this.CncErr_02);
this.groupBox3.Controls.Add(this.CncErr_03);
@@ -489,10 +494,11 @@
this.ErrRT_02.AutoSize = true;
this.ErrRT_02.Location = new System.Drawing.Point(268, 43);
this.ErrRT_02.Name = "ErrRT_02";
this.ErrRT_02.Size = new System.Drawing.Size(64, 17);
this.ErrRT_02.Size = new System.Drawing.Size(67, 17);
this.ErrRT_02.TabIndex = 10;
this.ErrRT_02.Text = "ERR_fill";
this.ErrRT_02.Text = "ERR_11";
this.ErrRT_02.UseVisualStyleBackColor = true;
this.ErrRT_02.CheckedChanged += new System.EventHandler(this.SysErr_01_CheckedChanged);
//
// CncErr_02
//
@@ -501,8 +507,9 @@
this.CncErr_02.Name = "CncErr_02";
this.CncErr_02.Size = new System.Drawing.Size(76, 17);
this.CncErr_02.TabIndex = 9;
this.CncErr_02.Text = "CncErr_02";
this.CncErr_02.Text = "CncErr_08";
this.CncErr_02.UseVisualStyleBackColor = true;
this.CncErr_02.CheckedChanged += new System.EventHandler(this.SysErr_01_CheckedChanged);
//
// CncErr_03
//
@@ -511,8 +518,9 @@
this.CncErr_03.Name = "CncErr_03";
this.CncErr_03.Size = new System.Drawing.Size(76, 17);
this.CncErr_03.TabIndex = 8;
this.CncErr_03.Text = "CncErr_03";
this.CncErr_03.Text = "CncErr_09";
this.CncErr_03.UseVisualStyleBackColor = true;
this.CncErr_03.CheckedChanged += new System.EventHandler(this.SysErr_01_CheckedChanged);
//
// CncErr_01
//
@@ -521,8 +529,9 @@
this.CncErr_01.Name = "CncErr_01";
this.CncErr_01.Size = new System.Drawing.Size(76, 17);
this.CncErr_01.TabIndex = 7;
this.CncErr_01.Text = "CncErr_01";
this.CncErr_01.Text = "CncErr_07";
this.CncErr_01.UseVisualStyleBackColor = true;
this.CncErr_01.CheckedChanged += new System.EventHandler(this.SysErr_01_CheckedChanged);
//
// SysErr_03
//
@@ -533,16 +542,18 @@
this.SysErr_03.TabIndex = 3;
this.SysErr_03.Text = "SysErr_03";
this.SysErr_03.UseVisualStyleBackColor = true;
this.SysErr_03.CheckedChanged += new System.EventHandler(this.SysErr_01_CheckedChanged);
//
// ErrRT_01
//
this.ErrRT_01.AutoSize = true;
this.ErrRT_01.Location = new System.Drawing.Point(268, 20);
this.ErrRT_01.Name = "ErrRT_01";
this.ErrRT_01.Size = new System.Drawing.Size(78, 17);
this.ErrRT_01.Size = new System.Drawing.Size(67, 17);
this.ErrRT_01.TabIndex = 2;
this.ErrRT_01.Text = "ERR_temp";
this.ErrRT_01.Text = "ERR_10";
this.ErrRT_01.UseVisualStyleBackColor = true;
this.ErrRT_01.CheckedChanged += new System.EventHandler(this.SysErr_01_CheckedChanged);
//
// SysErr_02
//
@@ -553,6 +564,7 @@
this.SysErr_02.TabIndex = 1;
this.SysErr_02.Text = "SysErr_02";
this.SysErr_02.UseVisualStyleBackColor = true;
this.SysErr_02.CheckedChanged += new System.EventHandler(this.SysErr_01_CheckedChanged);
//
// SysErr_01
//
@@ -563,6 +575,7 @@
this.SysErr_01.TabIndex = 0;
this.SysErr_01.Text = "SysErr_01";
this.SysErr_01.UseVisualStyleBackColor = true;
this.SysErr_01.CheckedChanged += new System.EventHandler(this.SysErr_01_CheckedChanged);
//
// groupBox2
//
@@ -1102,9 +1115,9 @@
this.label28.AutoSize = true;
this.label28.Location = new System.Drawing.Point(10, 91);
this.label28.Name = "label28";
this.label28.Size = new System.Drawing.Size(67, 13);
this.label28.Size = new System.Drawing.Size(64, 13);
this.label28.TabIndex = 31;
this.label28.Text = "Speed Over.";
this.label28.Text = "Rapid Over.";
//
// hsPathSpeedOver
//
@@ -1263,10 +1276,61 @@
this.groupBox6.TabStop = false;
this.groupBox6.Text = "ACK ADP --> PLC";
//
// STATUS_ACK_DW3
//
this.STATUS_ACK_DW3.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.STATUS_ACK_DW3.Location = new System.Drawing.Point(85, 118);
this.STATUS_ACK_DW3.Name = "STATUS_ACK_DW3";
this.STATUS_ACK_DW3.Size = new System.Drawing.Size(293, 24);
this.STATUS_ACK_DW3.TabIndex = 59;
//
// label52
//
this.label52.AutoSize = true;
this.label52.Location = new System.Drawing.Point(15, 126);
this.label52.Name = "label52";
this.label52.Size = new System.Drawing.Size(59, 13);
this.label52.TabIndex = 58;
this.label52.Text = "ACK_DW3";
//
// STATUS_ACK_DW2
//
this.STATUS_ACK_DW2.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.STATUS_ACK_DW2.Location = new System.Drawing.Point(85, 83);
this.STATUS_ACK_DW2.Name = "STATUS_ACK_DW2";
this.STATUS_ACK_DW2.Size = new System.Drawing.Size(293, 24);
this.STATUS_ACK_DW2.TabIndex = 57;
//
// label51
//
this.label51.AutoSize = true;
this.label51.Location = new System.Drawing.Point(15, 91);
this.label51.Name = "label51";
this.label51.Size = new System.Drawing.Size(59, 13);
this.label51.TabIndex = 56;
this.label51.Text = "ACK_DW2";
//
// STATUS_ACK_DW1
//
this.STATUS_ACK_DW1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.STATUS_ACK_DW1.Location = new System.Drawing.Point(85, 48);
this.STATUS_ACK_DW1.Name = "STATUS_ACK_DW1";
this.STATUS_ACK_DW1.Size = new System.Drawing.Size(293, 24);
this.STATUS_ACK_DW1.TabIndex = 55;
//
// label50
//
this.label50.AutoSize = true;
this.label50.Location = new System.Drawing.Point(15, 56);
this.label50.Name = "label50";
this.label50.Size = new System.Drawing.Size(59, 13);
this.label50.TabIndex = 54;
this.label50.Text = "ACK_DW1";
//
// STATUS_ACK_DW0
//
this.STATUS_ACK_DW0.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.STATUS_ACK_DW0.Location = new System.Drawing.Point(85, 11);
this.STATUS_ACK_DW0.Location = new System.Drawing.Point(85, 15);
this.STATUS_ACK_DW0.Name = "STATUS_ACK_DW0";
this.STATUS_ACK_DW0.Size = new System.Drawing.Size(293, 24);
this.STATUS_ACK_DW0.TabIndex = 53;
@@ -1349,7 +1413,7 @@
this.tbConf.Location = new System.Drawing.Point(4, 22);
this.tbConf.Name = "tbConf";
this.tbConf.Padding = new System.Windows.Forms.Padding(3);
this.tbConf.Size = new System.Drawing.Size(772, 643);
this.tbConf.Size = new System.Drawing.Size(777, 643);
this.tbConf.TabIndex = 1;
this.tbConf.Text = "XML CONFIG";
//
@@ -1359,7 +1423,7 @@
this.wbXmlConf.Location = new System.Drawing.Point(3, 3);
this.wbXmlConf.MinimumSize = new System.Drawing.Size(20, 20);
this.wbXmlConf.Name = "wbXmlConf";
this.wbXmlConf.Size = new System.Drawing.Size(766, 637);
this.wbXmlConf.Size = new System.Drawing.Size(771, 637);
this.wbXmlConf.TabIndex = 0;
//
// tpSIM
@@ -1379,7 +1443,7 @@
this.tpSIM.Controls.Add(this.groupBox12);
this.tpSIM.Location = new System.Drawing.Point(4, 22);
this.tpSIM.Name = "tpSIM";
this.tpSIM.Size = new System.Drawing.Size(772, 643);
this.tpSIM.Size = new System.Drawing.Size(777, 643);
this.tpSIM.TabIndex = 2;
this.tpSIM.Text = "SIMULATION";
//
@@ -1917,56 +1981,16 @@
this.label20.TabIndex = 52;
this.label20.Text = "AddM";
//
// STATUS_ACK_DW1
// ErrRT_03
//
this.STATUS_ACK_DW1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.STATUS_ACK_DW1.Location = new System.Drawing.Point(85, 48);
this.STATUS_ACK_DW1.Name = "STATUS_ACK_DW1";
this.STATUS_ACK_DW1.Size = new System.Drawing.Size(293, 24);
this.STATUS_ACK_DW1.TabIndex = 55;
//
// label50
//
this.label50.AutoSize = true;
this.label50.Location = new System.Drawing.Point(15, 56);
this.label50.Name = "label50";
this.label50.Size = new System.Drawing.Size(59, 13);
this.label50.TabIndex = 54;
this.label50.Text = "ACK_DW1";
//
// STATUS_ACK_DW2
//
this.STATUS_ACK_DW2.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.STATUS_ACK_DW2.Location = new System.Drawing.Point(85, 83);
this.STATUS_ACK_DW2.Name = "STATUS_ACK_DW2";
this.STATUS_ACK_DW2.Size = new System.Drawing.Size(293, 24);
this.STATUS_ACK_DW2.TabIndex = 57;
//
// label51
//
this.label51.AutoSize = true;
this.label51.Location = new System.Drawing.Point(15, 91);
this.label51.Name = "label51";
this.label51.Size = new System.Drawing.Size(59, 13);
this.label51.TabIndex = 56;
this.label51.Text = "ACK_DW2";
//
// STATUS_ACK_DW3
//
this.STATUS_ACK_DW3.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.STATUS_ACK_DW3.Location = new System.Drawing.Point(85, 118);
this.STATUS_ACK_DW3.Name = "STATUS_ACK_DW3";
this.STATUS_ACK_DW3.Size = new System.Drawing.Size(293, 24);
this.STATUS_ACK_DW3.TabIndex = 59;
//
// label52
//
this.label52.AutoSize = true;
this.label52.Location = new System.Drawing.Point(15, 126);
this.label52.Name = "label52";
this.label52.Size = new System.Drawing.Size(59, 13);
this.label52.TabIndex = 58;
this.label52.Text = "ACK_DW3";
this.ErrRT_03.AutoSize = true;
this.ErrRT_03.Location = new System.Drawing.Point(268, 66);
this.ErrRT_03.Name = "ErrRT_03";
this.ErrRT_03.Size = new System.Drawing.Size(67, 17);
this.ErrRT_03.TabIndex = 11;
this.ErrRT_03.Text = "ERR_12";
this.ErrRT_03.UseVisualStyleBackColor = true;
this.ErrRT_03.CheckedChanged += new System.EventHandler(this.SysErr_01_CheckedChanged);
//
// CMS_MachineSim
//
@@ -2207,6 +2231,7 @@
private System.Windows.Forms.Label label51;
private System.Windows.Forms.TextBox STATUS_ACK_DW1;
private System.Windows.Forms.Label label50;
private System.Windows.Forms.CheckBox ErrRT_03;
}
}
+132 -79
View File
@@ -19,6 +19,7 @@ using NLog;
namespace MTC_Sim
{
using MTConnect;
using System.Collections;
using System.Configuration;
using System.Diagnostics;
using System.IO;
@@ -145,7 +146,7 @@ namespace MTC_Sim
Power = 1000;
AccTime = 1440 * 365;
OPERATOR_ID.Text = "M9999";
OPERATOR_ID.Text = "OP9999";
STATUS_STRB_DW0.Text = utils.binaryForm(0);
STATUS_STRB_DW1.Text = utils.binaryForm(0);
@@ -249,7 +250,7 @@ namespace MTC_Sim
// inizio a riportare che sto eseguendo..
MainProgrBar.PerformStep();
// eseguo eventuali simulazioni x dati/flags
// eseguo eventuali simulazioni x dati/flags SE RICHIESTO
simulateData();
// check esecuzione FastTask
@@ -287,7 +288,7 @@ namespace MTC_Sim
private void checkSlowTask()
{
slowCount--;
if(slowCount<=0)
if (slowCount <= 0)
{
slowCount = utils.CRI("slowCount");
//lg.Info("Reset slowCount");
@@ -342,7 +343,7 @@ namespace MTC_Sim
agObj.mMessage.ForceChanged();
agObj.mAdapter.SendChanged();
}
// apro eseguibile dump
private void dump_Click(object sender, EventArgs e)
{
@@ -356,7 +357,7 @@ namespace MTC_Sim
Process.Start(string.Format(@"{0}\dump\dump.exe", path));
}
}
#region classi x simulazione valori vari
/// <summary>
@@ -373,10 +374,25 @@ namespace MTC_Sim
{
PROG_ROW_NUM.Text = rnd.Next(1, 10000).ToString();
}
// ora controllo se ci siano eventi M/S/T x alzare flag...
if (agObj.codaM.Count > 0) agObj.STROBE_PLC = agObj.STROBE_PLC | Strobe.M_CODE;
if (agObj.codaS.Count > 0) agObj.STROBE_PLC = agObj.STROBE_PLC | Strobe.S_CODE;
if (agObj.codaT.Count > 0) agObj.STROBE_PLC = agObj.STROBE_PLC | Strobe.T_CODE;
// cambio posizioni 6% casi: aggiungo codici M
if (rnd.Next(0, 100) > 95)
{
agObj.appendCodeMST("M", rnd.Next(1, 30).ToString());
}
// cambio posizioni 3% casi: aggiungo codici S
if (rnd.Next(0, 100) > 97)
{
agObj.appendCodeMST("S", rnd.Next(100, 10000).ToString());
}
// cambio posizioni 3% casi: aggiungo codici T
if (rnd.Next(0, 100) > 97)
{
agObj.appendCodeMST("T", rnd.Next(1, 100).ToString());
}
// aggiungo 1 pz al totale nel 0.3% dei casi (-->TC circa 333 x tick)...
if (rnd.Next(0, 1000) > 997)
@@ -468,6 +484,59 @@ namespace MTC_Sim
agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusBitMap.AL03;
}
// nel 2% dei casi imposto un RUN MODE diverso da RUN
if (rnd.Next(0, 100) > 98)
{
int codSel = rnd.Next(1, 3);
switch (codSel)
{
case 1:
manual.Checked = true;
break;
case 2:
mdi.Checked = true;
break;
default:
edit.Checked = true;
break;
}
}
// nel 3% degli altri casi riporto RUN MODE a RUN
else
{
if (rnd.Next(0, 100) > 97)
{
automatic.Checked = true;
}
}
// nel 2% dei casi imposto un EXE MODE diverso da AUTO
if (rnd.Next(0, 100) > 98)
{
int codSel = rnd.Next(1, 3);
switch (codSel)
{
case 1:
ready.Checked = true;
break;
case 2:
stopped.Checked = true;
break;
default:
feedhold.Checked = true;
break;
}
}
// nel 3% degli altri casi riporto EXE MODE a AUTO
else
{
if (rnd.Next(0, 100) > 97)
{
running.Checked = true;
}
}
// controllo se ci sia il flag di lettura di un evento M/S/T nel qual caso lo abbasso...
@@ -506,7 +575,25 @@ namespace MTC_Sim
if (utils.IsSetAll(agObj.STROBE_PLC, Strobe.POS_ACT)) agObj.STROBE_PLC -= Strobe.POS_ACT;
}
#if false
// ora controllo se ci siano da alzare flag...
utils.setBitOnStFlag(agObj.Strobes, (agObj.codaM.Count > 0), 32);
utils.setBitOnStFlag(agObj.Strobes, (agObj.codaS.Count > 0), 33);
utils.setBitOnStFlag(agObj.Strobes, (agObj.codaT.Count > 0), 34);
utils.setBitOnStFlag(agObj.Strobes, (agObj.AlarmFlags[0] != 0), 0);
utils.setBitOnStFlag(agObj.Strobes, (agObj.AlarmFlags[1] != 0), 1);
utils.setBitOnStFlag(agObj.Strobes, (agObj.AlarmFlags[2] != 0), 2);
utils.setBitOnStFlag(agObj.Strobes, (agObj.AlarmFlags[3] != 0), 3);
utils.setBitOnStFlag(agObj.Strobes, (agObj.AlarmFlags[4] != 0), 4);
utils.setBitOnStFlag(agObj.Strobes, (agObj.AlarmFlags[5] != 0), 5);
utils.setBitOnStFlag(agObj.Strobes, (agObj.AlarmFlags[6] != 0), 6);
utils.setBitOnStFlag(agObj.Strobes, (agObj.AlarmFlags[7] != 0), 7);
#endif
refreshVisualStrobes();
refreshCodeMST();
}
}
@@ -540,7 +627,7 @@ namespace MTC_Sim
{
if (addCodM.Text.Trim() != "")
{
agObj.appendCodeMST("M",addCodM.Text.Trim());
agObj.appendCodeMST("M", addCodM.Text.Trim());
addCodM.Text = "";
}
refreshCodeMST();
@@ -731,7 +818,7 @@ namespace MTC_Sim
answ.Status = stop.Enabled;
answ.Power = Power;
answ.AccTime = AccTime;
answ.EmrStop = estop.Checked;
answ.EmrStop = estop.Checked;
answ.FuncMode = ((KeyValuePair<string, string>)functionalMode.SelectedItem).Key;
@@ -751,7 +838,7 @@ namespace MTC_Sim
else if (feedhold.Checked) agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusBitMap.EM_FEEDHOLD;
else if (stopped.Checked) agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusBitMap.EM_STOP;
else if (ready.Checked) agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusBitMap.EM_READY;
if(answ.FuncMode!= "1") agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusBitMap.HM;
if (answ.FuncMode != "1") agObj.STATUS_FLAG = agObj.STATUS_FLAG | StatusBitMap.HM;
// ritorno oggetto!
return answ;
@@ -910,6 +997,10 @@ namespace MTC_Sim
float.TryParse(cells[5].Value.ToString(), out posAct.k);
answ.PathPosAct = posAct;
// aggiungo altri oggetti...
answ.CodG_Act = "G01 G10 G34 G60";
answ.SubMode = string.Format("# Asse selezionato {0} #", cbAxNum.SelectedIndex);
// ritorno oggetto!
return answ;
}
@@ -946,10 +1037,10 @@ namespace MTC_Sim
int.TryParse(uoNumCU.Text, out answ.UnOpNumCU);
answ.UnOpStatus = uoStatus.Text;
int.TryParse(uoVitaRes.Text, out answ.UnOpVitaRes);
answ.UnOpSpeed=uoSpeed.Value;
answ.UnOpLoad=uoLoad.Value;
answ.UnOpSpeed = uoSpeed.Value;
answ.UnOpLoad = uoLoad.Value;
int.TryParse(uoAccTime.Text, out answ.UnOpAccTime);
// ritorno oggetto!
return answ;
}
@@ -1061,74 +1152,36 @@ namespace MTC_Sim
#endregion
#region gestione allarmi
/// <summary>
/// Vettore errori system
/// </summary>
public List<int> systemAlarm
{
get
{
List<int> answ = new List<int>();
// controllo se ho valori errori checked...
if (SysErr_01.Checked) answ.Add(1);
if (SysErr_02.Checked) answ.Add(2);
if (SysErr_03.Checked) answ.Add(3);
return answ;
}
}
/// <summary>
/// Vettore errori PLC
/// </summary>
public List<int> plcAlarm
{
get
{
List<int> answ = new List<int>();
// controllo se ho valori errori checked...
if (PlcErr_01.Checked) answ.Add(1);
if (PlcErr_02.Checked) answ.Add(2);
if (PlcErr_03.Checked) answ.Add(3);
return answ;
}
}
/// <summary>
/// Vettore errori CNC
/// </summary>
public List<int> cncAlarm
{
get
{
List<int> answ = new List<int>();
// controllo se ho valori errori checked...
if (CncErr_01.Checked) answ.Add(1);
if (CncErr_02.Checked) answ.Add(2);
if (CncErr_03.Checked) answ.Add(3);
return answ;
}
}
public List<DataRefItem<int, string>> genericAlarm
{
get
{
List<DataRefItem<int, string>> answ = new List<DataRefItem<int, string>>();
if (ErrRT_01.Checked) answ.Add(new DataRefItem<int, string>(1, "TEMP"));
if (ErrRT_02.Checked) answ.Add(new DataRefItem<int, string>(1, "FILL"));
return answ;
}
}
#endregion
private void CMS_MachineSim_FormClosing(object sender, FormClosingEventArgs e)
{
agObj.tryDisconnect();
}
private void SysErr_01_CheckedChanged(object sender, EventArgs e)
{
// aggiorno il vettore allarmi (da 128 byte) sulla base della selezione dei checkbox (per i primi 9...) - ultimi 3 selezionano 8 allarmi ciascuno...
BitArray bitArray = new BitArray(1024);
bitArray[7] = SysErr_01.Checked;
bitArray[6] = SysErr_02.Checked;
bitArray[5] = SysErr_03.Checked;
bitArray[4] = PlcErr_01.Checked;
bitArray[3] = PlcErr_02.Checked;
bitArray[2] = PlcErr_03.Checked;
bitArray[1] = CncErr_01.Checked;
bitArray[0] = CncErr_02.Checked;
bitArray[15] = CncErr_03.Checked;
// ne assegno 8 alla volta...
for (int i = 0; i < 8; i++)
{
bitArray[16 + i] = ErrRT_01.Checked;
bitArray[24 + i] = ErrRT_02.Checked;
bitArray[32 + i] = ErrRT_03.Checked;
}
byte[] newAlarm = utils.ToByteArray(bitArray);
Buffer.BlockCopy(newAlarm, 0, agObj.AlarmFlags, 0, 32);
}
}
}
+1 -1
View File
@@ -127,7 +127,7 @@
<Content Include="AdapterConf\CMS_FANUC.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="AdapterConf\Demo.xml">
<Content Include="AdapterConf\DEMO.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="AlarmList.txt">
-1
View File
@@ -360,7 +360,6 @@ namespace MTC_Sim
// aggiunto 2016.05.10
listaDR.Add(new DataRefItem<string, string>(string.Format("Path_{0:00}_CodG_Act", i + 1), "CLASS"));
listaDR.Add(new DataRefItem<string, string>(string.Format("Path_{0:00}_SubMode", i + 1), "FLAG#R10528.0:R10531.7"));
listaDR.Add(new DataRefItem<string, string>(string.Format("Path_{0:00}_UserAction", i + 1), "STROBE#R10520.4:R10520.6"));
Path[i] = new element(string.Format("Path_{0:00}", i + 1), string.Format("Path num {0}", i + 1), fonteDati.Random, listaDR);
}
+35 -4
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
@@ -116,17 +117,19 @@ namespace MTC_Sim
return answ;
}
/// <summary>
/// imposta un bita al valore richiesto duplicando il valore IN come OUT
/// imposta un bit al valore richiesto duplicando il valore IN come OUT
/// </summary>
/// <param name="original">valore originale da aggiornare</param>
/// <param name="bitVal">valore richiesto x il bit (0/1)</param>
/// <param name="bitBool">valore richiesto x il bit (0/1)</param>
/// <param name="bitIndex">indice bit, 0 based (es: 0..31 per 32bit)</param>
/// <returns></returns>
public static byte[] setBitOnStFlag(byte[] original, int bitVal, int bitIndex)
public static byte[] setBitOnStFlag(byte[] original, bool bitBool, int bitIndex)
{
int bitVal = 0;
if (bitBool) bitVal = 1;
// risposta è identica ad originale...
byte[] answ = original;
// verifico se il bit è 0/1
// verifico se il bit è 0/1b
if (bitVal <= 1 && bitVal >= 0)
{
// verifico se si possa aggiornare il bit richiesto (<= al totale dei bit...)
@@ -155,6 +158,34 @@ namespace MTC_Sim
}
return answ;
}
/// <summary>
/// Converte un bitarray a byte[]
/// </summary>
/// <param name="bits"></param>
/// <returns></returns>
public static byte[] ToByteArray(BitArray bits)
{
int numBytes = bits.Count / 8;
if (bits.Count % 8 != 0) numBytes++;
byte[] bytes = new byte[numBytes];
int byteIndex = 0, bitIndex = 0;
for (int i = 0; i < bits.Count; i++)
{
if (bits[i])
bytes[byteIndex] |= (byte)(1 << (7 - bitIndex));
bitIndex++;
if (bitIndex == 8)
{
bitIndex = 0;
byteIndex++;
}
}
return bytes;
}
}
/// <summary>
/// Oggetto timing x archiviazione dati perfomances