123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Diagnostics.Eventing.Reader;
- using System.IO;
- using System.Linq;
- using System.Security.Policy;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using Aitex.Core.Backend;
- using Aitex.Core.MES.JC;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.RT.Log;
- using Aitex.Core.RT.SCCore;
- using Aitex.Core.Util;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using TwinCAT.Ads.Internal;
- namespace Aitex.Core.MES.YZQZ
- {
- public class YZQZFabAuto : FabAutoComm
- {
- private static bool jobStart = false;
- private static PeriodicJob _thread;
- private static string m_LotId;
- private static string m_ReceipeName;
-
- private static string m_machineNumber;
- private static string m_machineType;
- private static string m_wanPanPath;
- private static string m_operation;
- private static string m_operatorId;
- private static List<JobRecord> records;
-
- /// <summary>
- /// 根据扫码信息获取Recipe
- /// </summary>
- /// <returns>Lot--operation </returns>
- public override ResponseResult GetRecipeByMultipleLot(List<string> list ,string machineNumber,string machineType,string webApi)
- {
- List<RequestRecipe> requstParams = new List<RequestRecipe>();
- foreach (var lot in list)
- {
- RequestRecipe rrp= new RequestRecipe();
- rrp.LotId = lot;
- rrp.MachineNumber = machineNumber;
- rrp.MachineType = machineType;
- requstParams.Add(rrp);
- }
- string url = webApi + "/api/mes/GetRecipeByMultipleLot?strQuery={0}";
- string jsonParms = JsonConvert.SerializeObject(requstParams);
- LOG.Info("GetRecipeByMultipleLot|"+string.Format(url, jsonParms));
- string responseResult = HttpClient.HttpGet(string.Format(url, jsonParms));
- LOG.Info("GetRecipeByMultipleLot|"+responseResult);
- if (!string.IsNullOrEmpty(responseResult))
- {
- try
- {
-
- ResponseResult response = JsonConvert.DeserializeObject<ResponseResult>(responseResult);
- //if (response.Status ==200)
- //{
- // resResult = new KeyValuePair<ResultStatus, List<ResponseRecipe>>((ResultStatus)response.Status, response.Data);
- // cacheResponseReceip.Clear();
- // cacheResponseReceip.AddRange(response.Data);
- // m_operation = response.Data[0].Operation;
- // // Operation = response.Data[0].Operation;
- //}
- //else
- //{
- // resResult = new KeyValuePair<ResultStatus, List<ResponseRecipe>>((ResultStatus)response.Status, null);
- //}
- return response;
- }
- catch (Exception)
- {
- return null;
-
- }
-
- }
- return null;
- }
- public override bool SaveMachineErrorRecord(List<RequestMachineErrorRecord> requestRecords) {
- try
- {
- var postdata = JsonConvert.SerializeObject(requestRecords);
- string webapi = SC.GetSCString(SCName.System_YZQZWebapi).Value + "/api/mes/SaveMachineErrorRecord";
-
- string status;
- string result = HttpClient.PostResponse(webapi, postdata,out status);
- LOG.Info("MES|ErrorResponse|" + result);
- return true;
- }
- catch (Exception ex)
- {
- LOG.Info("MES|ErrorResponse|"+ex.Message);
- return false;
- }
-
- }
- public override bool SaveMachineStatusRecord(int State)
- {
- List<RequestMachineStatusRecord> requestRecords=new List<RequestMachineStatusRecord>();
- RequestMachineStatusRecord record= new RequestMachineStatusRecord();
- PState Pstate = (PState)State;
-
- string stateStr,color;
- switch (Pstate)
- {
-
- case PState.Idle:
- stateStr = "空闲";
- color = "黄色";
- break;
- case PState.Error:
- stateStr = "报警";
- color = "红色";
- break;
- default:
- stateStr = "运行";
- color = "绿色";
- break;
- }
-
- record.Status = stateStr;
- record.MachineNumber = SC.GetSCString(SCName.System_YZQZMachineNumber).Value;
- record.ColorName = color;
- record.MachineType = SC.GetSCString(SCName.System_YZQZMachineType).Value;
- record.UploadTime = DateTime.Now.ToString();
- requestRecords.Add(record);
- try
- {
- var postdata = JsonConvert.SerializeObject(requestRecords);
- string webapi = SC.GetSCString(SCName.System_YZQZWebapi).Value + "/api/mes/SaveMachineStatusRecord";
- LOG.Info("SaveMachineStatusRecord|" + Pstate.ToString());
- string status;
- string result = HttpClient.PostResponse(webapi, postdata, out status);
- return true;
- }
- catch (Exception ex)
- {
- LOG.Info("MES|ErrorResponse|" + ex.Message);
- return false;
- }
-
- }
- public override bool StartJobRecord(string lotId = "", string receipeName = "", string operation = "", string operatorId = "")
- {
- LOG.Info("StartJobRecord|" + "start|"+lotId+"|"+ receipeName);
- if (jobStart) return false;
- else jobStart = true;
- m_LotId = lotId;
- m_ReceipeName = receipeName;
- m_operation=operation;
- m_operatorId=operatorId;
- if (records == null)
- {
- records = new List<JobRecord>();
- }
- else records.Clear();
- work(true, false);
- _thread = new PeriodicJob(30000, this.OnTimer, "DBJob", true);
- _thread.Start();
- return true;
- }
- private bool OnTimer()
- {
- return work();
- }
- private bool work(bool start=false,bool end=false)
- {
- int i = 0;
- LOG.Info("work |"+i++);
- if (string.IsNullOrEmpty(m_machineNumber)) m_machineNumber = SC.GetSCString(SCName.System_YZQZMachineNumber).Value;
- if (string.IsNullOrEmpty(m_machineType)) m_machineType = SC.GetSCString(SCName.System_YZQZMachineType).Value;
- JobRecord oneRecord = new JobRecord();
- if(start)
- oneRecord.StartTime = DateTime.Now.ToString();
- if(end)
- oneRecord.EndtTime = DateTime.Now.ToString();
- oneRecord.CharmberPressure = IO.AI["AI_Chamber_real_pressure_fb_"].Value.ToString();
- oneRecord.OxygenConcentration = IO.AI["AI_MFC1_real_flow__fb"].Value.ToString();//???? how to make sure O2.
- oneRecord.Power = IO.AI["AI_RF_forward_power_fb"].Value.ToString();
- oneRecord.LotId =m_LotId;
- oneRecord.MachineNumber = m_machineNumber;
- oneRecord.MachineType = m_machineType;
- oneRecord.ReceipeName = m_ReceipeName;
- oneRecord.Operation = m_operation;
- oneRecord.OperatorId = m_operatorId;
- records.Add(oneRecord);
- return true;
- }
- public override void EndJobRecord()
- {
- LOG.Info("EndJobRecord|");
- if (!jobStart) return;
- if(jobStart)jobStart = false;
- work(false,true);
- if (_thread != null)
- _thread.Stop();
- saveToWanpan();
- }
- private static string dateTimeStr;
- private async void saveToWanpan()
- {
- await Task.Run(() =>
- {
- dateTimeStr = DateTime.Now.ToString("yyyyMMddHHmm");
- Export2CsvLocalFile();
- Export2CsvWanPanFile();
- records.Clear();
- });
- }
- private void Export2CsvLocalFile()
- {
- try
- {
-
- string path = string.Format(@"{0}", "Logs");
- DirectoryInfo curFolderInfo = new DirectoryInfo(path);
- string csvFileName = m_LotId.Replace("/","-").TrimEnd('-') +".csv";
-
- string filePath = Path.Combine(curFolderInfo.FullName, csvFileName);
- LOG.Info("Export2CsvLocalFile" + filePath);
- using (System.IO.StreamWriter fs = new System.IO.StreamWriter(filePath, false, Encoding.UTF8))
- {
- fs.Write("【批号】,【工序】,【作业员ID】,【机台号】,【机台类型】,【程序名称】,【开始时间】,【结束时间】,【氧气浓度】,【腔体压力】,【功率】");
- fs.WriteLine();
- foreach (var item in records)
- {
- fs.Write(item.LotId.TrimEnd('/'));
- fs.Write(",");
- fs.Write(item.Operation);
- fs.Write(",");
- fs.Write(item.OperatorId);
- fs.Write(",");
- fs.Write(item.MachineNumber);
- fs.Write(",");
- fs.Write(item.MachineType);
- fs.Write(",");
- fs.Write(item.ReceipeName);
- fs.Write(",");
- fs.Write(item.StartTime);
- fs.Write(",");
- fs.Write(item.EndtTime);
- fs.Write(",");
- fs.Write(item.OxygenConcentration);
- fs.Write(",");
- fs.Write(item.CharmberPressure);
- fs.Write(",");
- fs.Write(item.Power);
- fs.Write("\n");
- }
- fs.Close();
- }
- }
- catch (Exception ex)
- {
- LOG.Info(ex.Message);
- return;
- }
- }
- private void Export2CsvWanPanFile()
- {
- try
- {
- if (string.IsNullOrEmpty(m_wanPanPath))
- m_wanPanPath = SC.GetSCString(SCName.System_YZQZWanPan).Value;
- string csvFileName = m_LotId.Replace("/", "-").TrimEnd('-') + ".csv";
- string filePath = Path.Combine(m_wanPanPath, csvFileName);
- LOG.Info("Export2CsvWanPanFile" + filePath);
- using (System.IO.StreamWriter fs = new System.IO.StreamWriter(filePath, false, Encoding.UTF8))
- {
- fs.Write("【批号】,【工序】,【作业员ID】,【机台号】,【机台类型】,【程序名称】,【开始时间】,【结束时间】,【氧气浓度】,【腔体压力】,【功率】");
- fs.WriteLine();
- foreach (var item in records)
- {
- fs.Write(item.LotId.TrimEnd('/'));
- fs.Write(",");
- fs.Write(item.Operation);
- fs.Write(",");
- fs.Write(item.OperatorId);
- fs.Write(",");
- fs.Write(item.MachineNumber);
- fs.Write(",");
- fs.Write(item.MachineType);
- fs.Write(",");
- fs.Write(item.ReceipeName);
- fs.Write(",");
- fs.Write(item.StartTime);
- fs.Write(",");
- fs.Write(item.EndtTime);
- fs.Write(",");
- fs.Write(item.OxygenConcentration);
- fs.Write(",");
- fs.Write(item.CharmberPressure);
- fs.Write(",");
- fs.Write(item.Power);
- fs.Write("\n");
- }
- fs.Close();
- }
- }
- catch (Exception ex)
- {
- LOG.Info(ex.Message);
- return;
- }
- }
- }
- public enum PState
- {
- Init,
- Idle,
- Vent,
- Feed,
- Pumping,
- StopPumping,
- GasFlowing,
- StopGasFlowing,
- RfPowering,
- CyclePurge,
- LinePump,
- TankPump,
- ContainerPump,
- LoadProcessRecipe,
- ProcessHighVac,
- PreProcess,
- Processing,
- PostProcess,
- LeakCheck,
- Error,
- }
- }
|