diff --git a/CMS_CORE_Application/App.config b/CMS_CORE_Application/App.config
index d39588d..3321d64 100644
--- a/CMS_CORE_Application/App.config
+++ b/CMS_CORE_Application/App.config
@@ -1,6 +1,20 @@
-
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CMS_CORE_Application/CMS_CORE_Application.csproj b/CMS_CORE_Application/CMS_CORE_Application.csproj
index 1743502..ba7acf3 100644
--- a/CMS_CORE_Application/CMS_CORE_Application.csproj
+++ b/CMS_CORE_Application/CMS_CORE_Application.csproj
@@ -75,8 +75,24 @@
true
+
+ ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll
+
+
+ ..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll
+
+
+ ..\packages\MySql.Data.6.9.11\lib\net45\MySql.Data.dll
+
+
+ ..\packages\MySql.Data.Entity.6.9.11\lib\net45\MySql.Data.Entity.EF6.dll
+
+
+ ..\packages\MySql.Web.6.9.11\lib\net45\MySql.Web.dll
+
+
@@ -99,6 +115,8 @@
+
+
Form1.cs
@@ -112,6 +130,7 @@
Resources.resx
True
+
SettingsSingleFileGenerator
Settings.Designer.cs
diff --git a/CMS_CORE_Application/Form1.cs b/CMS_CORE_Application/Form1.cs
index 3037cc0..76da6e2 100644
--- a/CMS_CORE_Application/Form1.cs
+++ b/CMS_CORE_Application/Form1.cs
@@ -3,12 +3,14 @@ using CMS_CORE.Demo;
using CMS_CORE.Fanuc;
using CMS_CORE.Osai;
using CMS_CORE.Siemens;
+using CMS_CORE_Application.ToolDatabase;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
+using static CMS_CORE_Application.ToolDatabase.ToolModels;
using static CMS_CORE_Library.DataStructures;
namespace CMS_CORE_Application
@@ -33,7 +35,8 @@ namespace CMS_CORE_Application
private void connectDemo_Click(object sender, EventArgs e)
{
- t = new Thread(new ThreadStart(test));
+ t = new Thread(new ThreadStart(ReadBasicData));
+ Thread toolThread = new Thread(new ThreadStart(ChangeTool));
if (NcCombo.SelectedItem == null)
return;
@@ -46,10 +49,12 @@ namespace CMS_CORE_Application
Connect.Enabled = false;
Disconnect.Enabled = true;
t.Start();
+ toolThread.Start();
}
+
}
- private void test()
+ private void ReadBasicData()
{
Nc.PROC_Mode mode = Nc.PROC_Mode.AUTO;
Nc.PROC_Status status = Nc.PROC_Status.ERROR;
@@ -65,18 +70,10 @@ namespace CMS_CORE_Application
List Msg = new List();
List ncAlarms = new List();
List Lines = new List();
-
PostPowerOnModel postPowerOn = new PostPowerOnModel();
- if (NCType == "Siemens")
- N = new Nc_Siemens(500);
- if (NCType == "Demo")
- N = new Nc_Demo(NCIp, NCPort);
- if (NCType == "Osai")
- N = new Nc_Osai(NCIp, NCPort, 500);
- if (NCType == "Fanuc")
- N = new Nc_Fanuc(NCIp, NCPort, 500);
-
+ N = SetNcByType();
+
CmsError cmsError = N.NC_Connect();
cmsError = N.NC_RModelName(ref ModelName);
N.NC_RProcessesNum(ref procnum);
@@ -175,23 +172,67 @@ namespace CMS_CORE_Application
TXTMsg.Text = String.Join(Environment.NewLine, Msg.Select(x => x.message));
TXTPPName.Text = PPName;
TXTNow.Text = NcTime.ToString();
- Error.Text = "";
+
+ if (error == false)
+ Error.Text = "";
TXTPPLines.Text = String.Join(Environment.NewLine, Lines);
Connect.Enabled = false;
Disconnect.Enabled = true;
});
-
}
+ error = false;
//sw.Stop();
if ((200 - (int)sw.ElapsedMilliseconds) < 0)
- Debug.WriteLine("Ritardo");
+ Debug.WriteLine("Ritardo " + sw.ElapsedMilliseconds);
Thread.Sleep(200);
}
}
+ public void ChangeTool()
+ {
+ N = SetNcByType();
+ ToolModel toola = RicercaPerManina(1);
+
+ CmsError cmsError = N.NC_Connect();
+ byte id = 0;
+ Stopwatch stopwatch = new Stopwatch();
+ while (true)
+ {
+ stopwatch.Restart();
+ // Read next tool area
+ N.MEM_RWByte(Nc.R, 0, Nc.MEMORY_Type.Fanuc_R, 8000, 1, ref id);
+ // if not empty
+ if (id != 0)
+ {
+ ToolModel tool = RicercaPerManina(id);
+ List list = new List() { id, tool.FamilyId, tool.ShankId};
+ N.MEM_RWIntegerList(Nc.W, 0, Nc.MEMORY_Type.Fanuc_R, 8001, 0, ref list);
+
+ id = 0;
+ N.MEM_RWByte(Nc.W, 0, Nc.MEMORY_Type.Fanuc_R, 8000, 1, ref id);
+ stopwatch.Stop();
+ Debug.WriteLine(stopwatch.ElapsedMilliseconds.ToString());
+ }
+
+ Thread.Sleep(200);
+ }
+ }
+ private ToolModel RicercaPerManina(int maninaId)
+ {
+ ToolDatabaseContext dbCtx = new ToolDatabaseContext();
+ int idManina = Convert.ToInt32(maninaId);
+ // Find Tool by manina id
+ ToolModel tools = dbCtx
+ .Shanks
+ .Where(x => x.ManinaId == idManina)
+ .Join(dbCtx.Tools, m => m.ShankId, u => u.ShankId, (m, u) => u)
+ .FirstOrDefault();
+ return tools;
+ }
+
private void SetError(List Lines, CmsError cmsError)
{
if (!this.IsDisposed && this.InvokeRequired)
@@ -207,7 +248,19 @@ namespace CMS_CORE_Application
});
}
}
+ private Nc SetNcByType()
+ {
+ if (NCType == "Siemens")
+ return new Nc_Siemens(500);
+ if (NCType == "Demo")
+ return new Nc_Demo(NCIp, NCPort);
+ if (NCType == "Osai")
+ return new Nc_Osai(NCIp, NCPort, 500);
+ if (NCType == "Fanuc")
+ return new Nc_Fanuc(NCIp, NCPort, 500);
+ return null;
+ }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (NcCombo.SelectedItem.ToString().Equals("Siemens"))
diff --git a/CMS_CORE_Application/ToolDatabase/ToolDatabaseContext.cs b/CMS_CORE_Application/ToolDatabase/ToolDatabaseContext.cs
new file mode 100644
index 0000000..f5abb30
--- /dev/null
+++ b/CMS_CORE_Application/ToolDatabase/ToolDatabaseContext.cs
@@ -0,0 +1,21 @@
+using MySql.Data.Entity;
+using System.Data.Entity;
+using static CMS_CORE_Application.ToolDatabase.ToolModels;
+
+namespace CMS_CORE_Application.ToolDatabase
+{
+ [DbConfigurationType(typeof(MySqlEFConfiguration))]
+
+ public class ToolDatabaseContext : DbContext
+ {
+ public DbSet Tools { get; set; }
+ public DbSet Shanks { get; set; }
+ public DbSet Family { get; set; }
+ public DbSet Manine { get; set; }
+
+ public ToolDatabaseContext() : base("mySQLDatabaseConnection")
+ {
+
+ }
+ }
+}
diff --git a/CMS_CORE_Application/ToolDatabase/ToolModels.cs b/CMS_CORE_Application/ToolDatabase/ToolModels.cs
new file mode 100644
index 0000000..d9796c6
--- /dev/null
+++ b/CMS_CORE_Application/ToolDatabase/ToolModels.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CMS_CORE_Application.ToolDatabase
+{
+ public class ToolModels
+ {
+ [Table("tool")]
+
+ public class ToolModel
+ {
+ [Key]
+ [Column("id")]
+ public int ToolId { get; set; }
+ [Column("broken")]
+ public bool Broken { get; set; }
+ [Column("shank")]
+ public int ShankId { get; set; }
+ [ForeignKey("ShankId")]
+ public ShankModel Shank { get; set; }
+ [Column("family")]
+ public int FamilyId { get; set; }
+ [ForeignKey("FamilyId")]
+ public FamilyModel Family { get; set; }
+ }
+
+ [Table("shank")]
+ public class ShankModel
+ {
+ [Key]
+ [Column("id")]
+ public int ShankId { get; set; }
+ [Column("manina")]
+ public int? ManinaId { get; set; }
+ [ForeignKey("ManinaId")]
+ public FamilyModel Manina { get; set; }
+ [Column("tablet_id")]
+ public int TabletId { get; set; }
+ }
+
+ [Table("family")]
+ public class FamilyModel
+ {
+ [Key]
+ [Column("id")]
+ public int FamilyId { get; set; }
+ [Column("gamma")]
+ public int Gamma { get; set; }
+ }
+
+ [Table("manina")]
+ public class ManinaModello
+ {
+ [Key]
+ [Column("id")]
+ public int IdManina { get; set; }
+ [Column("store")]
+ public int Store { get; set; }
+
+ }
+ }
+}
diff --git a/CMS_CORE_Application/packages.config b/CMS_CORE_Application/packages.config
new file mode 100644
index 0000000..e5c25f2
--- /dev/null
+++ b/CMS_CORE_Application/packages.config
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CMS_CORE_Library/Siemens/Nc_Siemens.cs b/CMS_CORE_Library/Siemens/Nc_Siemens.cs
index edfe5dc..b5e15cc 100644
--- a/CMS_CORE_Library/Siemens/Nc_Siemens.cs
+++ b/CMS_CORE_Library/Siemens/Nc_Siemens.cs
@@ -411,12 +411,12 @@ namespace CMS_CORE.Siemens
//Get the Nc Active Alarms
- public override CmsError NC_RActiveAlarms(ref List Alarms)
+ public override CmsError NC_RActiveAlarms(ref List alarms)
{
if (SiemensAlarms == null)
return null;
- Alarms = SiemensAlarms.
+ alarms = SiemensAlarms.
Where(x => (x.Id < IDMinPLCMessage || x.Id > IDMaxPLCMessage) && (x.Id < IDMinChannel || x.Id > IDMaxChannel))
.Select(x => new AlarmModel() { id = (uint)x.Id, message = x.Message, isWarning = false, process = 0 })
.ToList();