256 lines
6.2 KiB
C#
256 lines
6.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MTC_Sim
|
|
{
|
|
public class utils
|
|
{
|
|
|
|
/// <summary>
|
|
/// legge conf in formato stringa
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
public static string CRS(string key)
|
|
{
|
|
string answ = "";
|
|
try
|
|
{
|
|
answ = ConfigurationManager.AppSettings[key].ToString();
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// legge conf in formato INT
|
|
/// </summary>
|
|
/// <param name="key"></param>
|
|
/// <returns></returns>
|
|
public static Int32 CRI(string key)
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(CRS(key));
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// verifica se un dato bit sia alzato (come flag di strobe)
|
|
/// </summary>
|
|
/// <param name="value">valore da testare</param>
|
|
/// <param name="flag">valore cercato, può essere un singolo valore o un insieme in modalità AND</param>
|
|
/// <returns></returns>
|
|
public static bool IsSetAll(Strobe value, Strobe flag)
|
|
{
|
|
return ((value & flag) == flag);
|
|
}
|
|
/// <summary>
|
|
/// verifica se un dato bit sia alzato (come flag di strobe)
|
|
/// </summary>
|
|
/// <param name="value">valore da testare</param>
|
|
/// <param name="flag">valore cercato, può essere un singolo valore o un insieme in modalità OR</param>
|
|
/// <returns></returns>
|
|
public static bool IsSetAny(Strobe value, Strobe flag)
|
|
{
|
|
return ((value & flag) != 0);
|
|
}
|
|
/// <summary>
|
|
/// formatta un numero in forma binaria 0/1
|
|
/// </summary>
|
|
/// <param name="valore"></param>
|
|
/// <returns></returns>
|
|
public static string binaryForm(int valore)
|
|
{
|
|
string answ = "";
|
|
try
|
|
{
|
|
answ = string.Format(new BinaryFormatter(), "{0:B}", valore);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
#if false
|
|
public DataSet DS_lists
|
|
{
|
|
get
|
|
{
|
|
DataTable tbl = new DataTable("HaltType");
|
|
tbl.Columns.Add("label");
|
|
tbl.Columns.Add("value");
|
|
tbl.Rows.Add("COD001", 001);
|
|
tbl.Rows.Add("COD002", 002);
|
|
tbl.Rows.Add("COD003", 003);
|
|
|
|
// Create a DataSet.
|
|
DataSet set = new DataSet("MTC-ADAPT");
|
|
set.Tables.Add(tbl);
|
|
set.Namespace = "adapt";
|
|
set.Prefix = "mtc";
|
|
|
|
return set;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
public enum tipoAdapter
|
|
{
|
|
/// <summary>
|
|
/// Adapter generico/demo
|
|
/// </summary>
|
|
Demo,
|
|
/// <summary>
|
|
/// adapter FANUC-CMS
|
|
/// </summary>
|
|
Fanuc,
|
|
/// <summary>
|
|
/// Adapter HMI-SCM
|
|
/// </summary>
|
|
HMI
|
|
}
|
|
|
|
public enum fonteDati
|
|
{
|
|
/// <summary>
|
|
/// dati recuperati da metodi/calssi con HMI
|
|
/// </summary>
|
|
HMI,
|
|
/// <summary>
|
|
/// dati recuperati da recupero memorie PLC/CNC
|
|
/// </summary>
|
|
MemLoad,
|
|
/// <summary>
|
|
/// in questo caso dato fittizio/senza dati (x init)
|
|
/// </summary>
|
|
NoData,
|
|
/// <summary>
|
|
/// Dati generati random
|
|
/// </summary>
|
|
Random
|
|
}
|
|
|
|
/// <summary>
|
|
/// informazioni di produzione
|
|
/// </summary>
|
|
public struct prodData
|
|
{
|
|
public string ProgramName;
|
|
public string ProgrRow;
|
|
public string PartId;
|
|
public string Operator;
|
|
|
|
public bool Status;
|
|
public int AccTime;
|
|
public int Power;
|
|
public bool EmrStop;
|
|
public string RunMode;
|
|
public string ExeMode;
|
|
public string FuncMode;
|
|
public string MessageCode;
|
|
public string MessageText;
|
|
|
|
public int pzTot;
|
|
public int pzOk;
|
|
public int pzKo;
|
|
|
|
public int PathFeedrate;
|
|
public int PathFeedrateOver;
|
|
public int PathSpeedrateOver;
|
|
|
|
public position PosAct;
|
|
|
|
public int xLoad;
|
|
public int yLoad;
|
|
public int zLoad;
|
|
public int cLoad;
|
|
|
|
public bool err_01;
|
|
public bool err_02;
|
|
public bool err_03;
|
|
public bool err_04;
|
|
public bool err_05;
|
|
public bool err_06;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Vettore completo posizione (X-Y-Z con versori i-j-k)
|
|
/// </summary>
|
|
public class position
|
|
{
|
|
public float x;
|
|
public float y;
|
|
public float z;
|
|
public float i;
|
|
public float j;
|
|
public float k;
|
|
public position()
|
|
{
|
|
x = 0;
|
|
y = 0;
|
|
z = 0;
|
|
i = 0;
|
|
j = 0;
|
|
k = 0;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Strobe: contiene il set di strobe di comunicazione
|
|
///
|
|
/// rif: http://stackoverflow.com/questions/17209054/parse-bits-in-a-byte-to-enum
|
|
/// </summary>
|
|
[Flags]
|
|
public enum Strobe : int
|
|
{
|
|
NONE = 0,
|
|
M_CODE = 1 << 0,
|
|
S_CODE = 1 << 1,
|
|
T_CODE = 1 << 2,
|
|
PZ_OK = 1 << 3,
|
|
PZ_KO = 1 << 4,
|
|
FEED_SPEED = 1 << 5,
|
|
POS_ACT = 1 << 6,
|
|
SP07 = 1 << 7,
|
|
SP08 = 1 << 8,
|
|
SP09 = 1 << 9,
|
|
SP10 = 1 << 10,
|
|
SP11 = 1 << 11,
|
|
SP12 = 1 << 12,
|
|
SP13 = 1 << 13,
|
|
SP14 = 1 << 14,
|
|
SP15 = 1 << 15,
|
|
SP16 = 1 << 16,
|
|
SP17 = 1 << 17,
|
|
SP18 = 1 << 18,
|
|
SP19 = 1 << 19,
|
|
SP20 = 1 << 20,
|
|
SP21 = 1 << 21,
|
|
SP22 = 1 << 22,
|
|
SP23 = 1 << 23,
|
|
SP24 = 1 << 24,
|
|
SP25 = 1 << 25,
|
|
SP26 = 1 << 26,
|
|
SP27 = 1 << 27,
|
|
SP28 = 1 << 28,
|
|
SP29 = 1 << 29,
|
|
SP30 = 1 << 30,
|
|
SP31 = 1 << 31,
|
|
SP32 = 1 << 32
|
|
}
|
|
|
|
}
|