Added MariaDB and fanuc tool managing

This commit is contained in:
Lucio Maranta
2018-02-02 07:10:57 +00:00
parent 34448506e5
commit b9c7c2d1a0
7 changed files with 203 additions and 22 deletions
+19 -5
View File
@@ -1,6 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup>
</configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<connectionStrings>
<add name="mySQLDatabaseConnection" providerName="MySql.Data.MySqlClient" connectionString="Server=localhost;Database=test_database;Uid=root;Pwd=root;" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.11.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>
</entityFramework>
<system.data>
</system.data></configuration>
@@ -75,8 +75,24 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="MySql.Data, Version=6.9.11.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.6.9.11\lib\net45\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="MySql.Data.Entity.EF6, Version=6.9.11.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.Entity.6.9.11\lib\net45\MySql.Data.Entity.EF6.dll</HintPath>
</Reference>
<Reference Include="MySql.Web, Version=6.9.11.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Web.6.9.11\lib\net45\MySql.Web.dll</HintPath>
</Reference>
<Reference Include="Siemens.Sinumerik.Operate.Services, Version=4.7.4.0, Culture=neutral, PublicKeyToken=bdd90fa02fd1c4ee" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
@@ -99,6 +115,8 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ToolDatabase\ToolDatabaseContext.cs" />
<Compile Include="ToolDatabase\ToolModels.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
@@ -112,6 +130,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
+68 -15
View File
@@ -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<AlarmModel> Msg = new List<AlarmModel>();
List<AlarmModel> ncAlarms = new List<AlarmModel>();
List<String> Lines = new List<string>();
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<int> list = new List<int>() { 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<String> 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"))
@@ -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<ToolModel> Tools { get; set; }
public DbSet<ShankModel> Shanks { get; set; }
public DbSet<FamilyModel> Family { get; set; }
public DbSet<ManinaModello> Manine { get; set; }
public ToolDatabaseContext() : base("mySQLDatabaseConnection")
{
}
}
}
@@ -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; }
}
}
}
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.2.0" targetFramework="net462" />
<package id="MySql.Data" version="6.9.11" targetFramework="net462" />
<package id="MySql.Data.Entity" version="6.9.11" targetFramework="net462" />
<package id="MySql.Web" version="6.9.11" targetFramework="net462" />
</packages>
+2 -2
View File
@@ -411,12 +411,12 @@ namespace CMS_CORE.Siemens
//Get the Nc Active Alarms
public override CmsError NC_RActiveAlarms(ref List<AlarmModel> Alarms)
public override CmsError NC_RActiveAlarms(ref List<AlarmModel> 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();