| | |
| | | using FreeSql; |
| | | using OfficeOpenXml.Drawing.Chart; |
| | | using Quartz; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Comm; |
| | | using WIDESEA_Comm.ItemDB; |
| | | using WIDESEA_Comm.LogInfo; |
| | | using WIDESEA_Core.EFDbContext; |
| | | using WIDESEA_Core.Extensions; |
| | | using WIDESEA_Entity.DomainModels; |
| | | using WIDESEA_WCS.IRepositories; |
| | | using WIDESEA_WCS.IServices; |
| | | using WIDESEA_WCS.Jobs; |
| | | using WIDESEA_WCS.Repositories; |
| | | using WIDESEA_WCS.Services; |
| | | using WIDESEA_WCS.WCSClient; |
| | |
| | | /// ä¸äºåå
è°åº¦ |
| | | /// </summary> |
| | | [DisallowConcurrentExecution] |
| | | public class One_two_unitJob : IJob |
| | | public class One_two_unitJob : JobBase, IJob |
| | | { |
| | | public Task Execute(IJobExecutionContext context) |
| | | { |
| | | try |
| | | { |
| | | var client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient; |
| | | if (client == null) |
| | | { |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | //èªå¨éè¿ |
| | | if (!client.IsConnected) |
| | | { |
| | | client.Connect(); |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | DoAction(client); |
| | | } |
| | | catch { } |
| | | return Task.CompletedTask; |
| | | } |
| | | static List<GDXDB> gDXDBs = new List<GDXDB>(); |
| | | private void DoAction(PLCClient client) |
| | | { |
| | | try |
| | | { |
| | | #region è¯»åæ¹æ³ãæ¥å¿ãæ§è¡æ¶é´ |
| | | //client.Write("DB400.DBX0", "123456"); |
| | | //client.WriteByOrder("R_wheel_SN", "123456", "4.1"); |
| | | //client.WriteByOrder("R_wheel_SN", "666666", "4.2"); |
| | | |
| | | //var res = client.Read<string>("DB400.DBX0", 20); |
| | | //var res1 = client.ReadByOrder<string>("R_wheel_SN", "4.1"); |
| | | //var res2 = client.ReadByOrder<string>("R_wheel_SN", "4.2"); |
| | | |
| | | //æ¥å¿åå
¥ |
| | | //WriteDBLog.Info("ä¸äºåå
è°åº¦", "4.1:" + res1 + ";4.2:" + res2, "PCS"); |
| | | |
| | | //æ§è¡å®ææ¶é´ |
| | | //Console.WriteLine(DateTime.Now); |
| | | #endregion |
| | | |
| | | #region æ·»å PLCå°åä¿¡æ¯ |
| | | //VOLContext Context = new VOLContext(); |
| | | //Idt_plcinfodetailRepository dt_PlcinfodetailService = new dt_plcinfodetailRepository(Context); |
| | | //List<dt_plcinfodetail> plcinfodetails = new List<dt_plcinfodetail>(); |
| | | //for (int i = 106; i <= 110; i++) |
| | | //{ |
| | | // dt_plcinfodetail dt_Plcinfodetail = new dt_plcinfodetail() |
| | | // { |
| | | // plcdetail_id = Guid.NewGuid(), |
| | | // plcdetail_iotype = "One_two_unit", |
| | | // plcdetail_db = "DB400", |
| | | // plcdetail_value = "DBX" + ((i - 1) * 30), |
| | | // plcdetail_valtype = "string", |
| | | // plcdetail_len = 20, |
| | | // plcdetail_name = "R_wheel_SN", |
| | | // plcdetail_number = "7." + (i - 80), |
| | | // plcdetail_remark = "读å车轮SNå·" |
| | | // }; |
| | | // plcinfodetails.Add(dt_Plcinfodetail); |
| | | // dt_plcinfodetail dt_Plcinfodetail1 = new dt_plcinfodetail() |
| | | // { |
| | | // plcdetail_id = Guid.NewGuid(), |
| | | // plcdetail_iotype = "One_two_unit", |
| | | // plcdetail_db = "DB400", |
| | | // plcdetail_value = "DBX" + ((i - 1) * 30 + 20), |
| | | // plcdetail_valtype = "int", |
| | | // plcdetail_name = "R_wheel_type", |
| | | // plcdetail_number = "7." + (i - 80), |
| | | // plcdetail_remark = "读å车轮类å" |
| | | // }; |
| | | // plcinfodetails.Add(dt_Plcinfodetail1); |
| | | // dt_plcinfodetail dt_Plcinfodetail2 = new dt_plcinfodetail() |
| | | // { |
| | | // plcdetail_id = Guid.NewGuid(), |
| | | // plcdetail_iotype = "One_two_unit", |
| | | // plcdetail_db = "DB400", |
| | | // plcdetail_value = "DBX" + ((i - 1) * 30 + 22), |
| | | // plcdetail_valtype = "byte", |
| | | // plcdetail_name = "R_part_status", |
| | | // plcdetail_number = "7." + (i - 80), |
| | | // plcdetail_remark = "读å车轮é¶ä»¶ç¶æ" |
| | | // }; |
| | | // plcinfodetails.Add(dt_Plcinfodetail2); |
| | | // dt_plcinfodetail dt_Plcinfodetail3 = new dt_plcinfodetail() |
| | | // { |
| | | // plcdetail_id = Guid.NewGuid(), |
| | | // plcdetail_iotype = "One_two_unit", |
| | | // plcdetail_db = "DB400", |
| | | // plcdetail_value = "DBX" + ((i - 1) * 30 + 23), |
| | | // plcdetail_valtype = "byte", |
| | | // plcdetail_name = "R_part_process", |
| | | // plcdetail_number = "7." + (i - 80), |
| | | // plcdetail_remark = "读å车轮é¶ä»¶å·¥èº" |
| | | // }; |
| | | // plcinfodetails.Add(dt_Plcinfodetail3); |
| | | // dt_plcinfodetail dt_Plcinfodetail4 = new dt_plcinfodetail() |
| | | // { |
| | | // plcdetail_id = Guid.NewGuid(), |
| | | // plcdetail_iotype = "One_two_unit", |
| | | // plcdetail_db = "DB400", |
| | | // plcdetail_value = "DBX" + ((i - 1) * 30 + 24), |
| | | // plcdetail_valtype = "byte", |
| | | // plcdetail_name = "R_machine_nr", |
| | | // plcdetail_number = "7." + (i - 80), |
| | | // plcdetail_remark = "读åè¾émachine_nr" |
| | | // }; |
| | | // plcinfodetails.Add(dt_Plcinfodetail4); |
| | | // dt_plcinfodetail dt_Plcinfodetail5 = new dt_plcinfodetail() |
| | | // { |
| | | // plcdetail_id = Guid.NewGuid(), |
| | | // plcdetail_iotype = "One_two_unit", |
| | | // plcdetail_db = "DB400", |
| | | // plcdetail_value = "DBX" + ((i - 1) * 30 + 25), |
| | | // plcdetail_valtype = "byte", |
| | | // plcdetail_name = "R_direction", |
| | | // plcdetail_number = "7." + (i - 80), |
| | | // plcdetail_remark = "读åè¾édirection" |
| | | // }; |
| | | // plcinfodetails.Add(dt_Plcinfodetail5); |
| | | //} |
| | | //dt_PlcinfodetailService.AddRange(plcinfodetails, true); |
| | | #endregion |
| | | |
| | | VOLContext Context = new VOLContext(); |
| | | Idt_plcinfoheadRepository repository = new dt_plcinfoheadRepository(Context); |
| | | Idt_plcinfodetailRepository plcRepository = new dt_plcinfodetailRepository(Context); |
| | | |
| | | PropertyInfo[] propertyInfos = typeof(GDXDB).GetProperties();//è·åææå±æ§ |
| | | var plc = repository.FindFirst(x => x.plcinfo_name == client.PLCName); |
| | | var numbers = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep).GroupBy(x => x.plcdetail_number).ToList(); |
| | | foreach (var number in numbers) |
| | | { |
| | | GDXDB dBItem = gDXDBs.Where(x => x.R_Name == number.Key).FirstOrDefault(); |
| | | if (dBItem == null) |
| | | { |
| | | dBItem = new(); |
| | | dBItem.OnReadSignal += HandleReadSignal; |
| | | gDXDBs.Add(dBItem); |
| | | //object obj = dBItem.R_part_status; |
| | | //dBItem.R_part_status = client.Read<byte>(number.Key); |
| | | } |
| | | List<dt_plcinfodetail> details = plcRepository.Find(x => x.plcdetail_iotype == plc.plcinfo_iotyep && x.plcdetail_number == number.Key).ToList(); |
| | | for (int i = 0; i < propertyInfos.Length; i++) |
| | | { |
| | | if (i == 0) |
| | | { |
| | | dBItem.R_Name = number.Key; |
| | | } |
| | | else |
| | | { |
| | | object readData = DBExtension.Read(details.Where(x => x.plcdetail_name == propertyInfos[i].Name).FirstOrDefault(), client); |
| | | if (readData != null) { } |
| | | object obj = propertyInfos[i].GetValue(dBItem); |
| | | if (obj != readData) |
| | | propertyInfos[i].SetValue(dBItem, readData); |
| | | } |
| | | } |
| | | } |
| | | AddDB(); |
| | | //ExecuteJob(context, DoAction); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine(ex.Message); |
| | | |
| | | } |
| | | return Task.CompletedTask; |
| | | } |
| | | |
| | | public void HandleReadSignal(GDXDB DBItem) |
| | | private void DoAction(IJobExecutionContext context) |
| | | { |
| | | VOLContext Context = new VOLContext(); |
| | | Idt_ActualProductionRepository repository = new dt_ActualProductionRepository(Context); |
| | | var info = repository.FindFirst(x => x.SN == DBItem.R_wheel_SN);//æ¥è¯¢è½¦è½®ç详ç»ä¿¡æ¯ |
| | | if (info != null) |
| | | var client = context.JobDetail.JobDataMap.Get("JobParams") as PLCClient; |
| | | //èªå¨éè¿ |
| | | if (!client.IsConnected) |
| | | { |
| | | //åè¯æ¡æ¶ |
| | | |
| | | client.Connect(); |
| | | return; |
| | | } |
| | | StackerReadDBItem.StackerReadDBItems = new List<StackerReadDBItem>(); |
| | | PropertyInfo[] propertyInfos = typeof(StackerReadDBItem).GetProperties(); |
| | | var groups = client.itemGroups.OrderBy(x => x.Methods).ThenBy(x => x.name).GroupBy(x => x.Methods).ToList(); |
| | | foreach (var key in groups) |
| | | { |
| | | StackerReadDBItem StackerDBItem = new StackerReadDBItem(); |
| | | foreach (var propertyInfo in propertyInfos) |
| | | { |
| | | if (propertyInfo.Name == "StackerNo") |
| | | { |
| | | StackerDBItem.StackerNo = key.Key; |
| | | } |
| | | else |
| | | { |
| | | DBItemGroup group = key.FirstOrDefault(x => x.name == propertyInfo.Name); |
| | | if (group != null) |
| | | { |
| | | var readData = DBExtension.Read(group, client); |
| | | switch (propertyInfo.Name) |
| | | { |
| | | case "R_wheel_SN": |
| | | StackerDBItem.R_wheel_SN = readData.ToString(); |
| | | break; |
| | | case "R_wheel_type": |
| | | StackerDBItem.R_wheel_type = Convert.ToInt16(readData); |
| | | break; |
| | | case "R_part_status": |
| | | StackerDBItem.R_part_status = Convert.ToByte(readData); |
| | | break; |
| | | case "R_part_process": |
| | | StackerDBItem.R_part_process = Convert.ToByte(readData); |
| | | break; |
| | | case "R_machine_nr": |
| | | StackerDBItem.R_machine_nr = Convert.ToBoolean(readData); |
| | | break; |
| | | case "R_direction": |
| | | StackerDBItem.R_direction = Convert.ToByte(readData); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | StackerReadDBItem.StackerReadDBItems.Add(StackerDBItem); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ·»å DBå°åä¿¡æ¯ |
| | | /// </summary> |
| | | public void AddDB() |
| | | { |
| | | VOLContext context = new VOLContext(); |
| | | Idt_plcinfodetailRepository repository = new dt_plcinfodetailRepository(context); |
| | | List<dt_plcinfodetail> plcinfodetail = new List<dt_plcinfodetail>(); |
| | | for (int i = 1; i <= 1; i++) |
| | | { |
| | | dt_plcinfodetail dt_Plcinfodetail1 = new dt_plcinfodetail() |
| | | { |
| | | plcdetail_id = Guid.NewGuid(), |
| | | plcdetail_iotype = "VK5", |
| | | plcdetail_db = "DB630", |
| | | plcdetail_value = ((i - 1 + 28 + 10 + 10) * 24).ToString(), |
| | | plcdetail_valtype = "string", |
| | | plcdetail_len = 20, |
| | | plcdetail_name = "R_wheel_SN", |
| | | plcdetail_opratortype = "wheel", |
| | | plcdetail_remark = "读å车轮SNå·", |
| | | plcdetail_number = "æºæ¢°æ3", |
| | | }; |
| | | plcinfodetail.Add(dt_Plcinfodetail1); |
| | | dt_plcinfodetail dt_Plcinfodetail2 = new dt_plcinfodetail() |
| | | { |
| | | plcdetail_id = Guid.NewGuid(), |
| | | plcdetail_iotype = "VK5", |
| | | plcdetail_db = "DB630", |
| | | plcdetail_value = (20 + (i - 1 + 28 + 10 + 10) * 24).ToString(), |
| | | plcdetail_valtype = "int16", |
| | | plcdetail_name = "R_wheel_type", |
| | | plcdetail_opratortype = "wheel", |
| | | plcdetail_remark = "读å车轮类å", |
| | | plcdetail_number = "æºæ¢°æ3", |
| | | }; |
| | | plcinfodetail.Add(dt_Plcinfodetail2); |
| | | dt_plcinfodetail dt_Plcinfodetail3 = new dt_plcinfodetail() |
| | | { |
| | | plcdetail_id = Guid.NewGuid(), |
| | | plcdetail_iotype = "VK5", |
| | | plcdetail_db = "DB630", |
| | | plcdetail_value = (22 + (i - 1 + 28 + 10 + 10) * 24).ToString(), |
| | | plcdetail_valtype = "byte", |
| | | plcdetail_name = "R_part_status", |
| | | plcdetail_opratortype = "wheel", |
| | | plcdetail_remark = "读åè½¦è½®ç¶æ", |
| | | plcdetail_number = "æºæ¢°æ3", |
| | | }; |
| | | plcinfodetail.Add(dt_Plcinfodetail3); |
| | | dt_plcinfodetail dt_Plcinfodetail4 = new dt_plcinfodetail() |
| | | { |
| | | plcdetail_id = Guid.NewGuid(), |
| | | plcdetail_iotype = "VK5", |
| | | plcdetail_db = "DB630", |
| | | plcdetail_value = (23 + (i - 1 + 28 + 10 + 10) * 24).ToString(), |
| | | plcdetail_valtype = "byte", |
| | | plcdetail_name = "R_part_process", |
| | | plcdetail_opratortype = "wheel", |
| | | plcdetail_remark = "读å车轮工èº", |
| | | plcdetail_number = "æºæ¢°æ3", |
| | | }; |
| | | plcinfodetail.Add(dt_Plcinfodetail4); |
| | | } |
| | | repository.AddRange(plcinfodetail, true); |
| | | } |
| | | } |
| | | } |