123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866 |
-
- using DefaultEdit.Communication;
- using DefaultEdit.DataBase;
- using DefaultEdit.Log4xml;
- using DefaultEdit.Model;
- using Newtonsoft.Json.Linq;
- using NextTreatMesDemo.Models;
- using NextTreatMesDemo.Utils;
- using ObservableCollections;
- using Prism.Modularity;
- using Prism.Mvvm;
- using ScottPlot;
- using SqlSugar;
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Xml.Linq;
- namespace DefaultEdit.Core
- {
- public class Management : BindableBase
- {
- private CurentApplicationSettings _CurentApplicationSettings=new CurentApplicationSettings();
- private IServer _httpService = new MesServer();
- private S7PlcCommunicate s7PlcCommunicate;
- public event Action<string,bool> RuningToWorkEvent;
- public event Action ProduceDataToChangeEvent;
- private List<RfidInfo> _RfIDList=new List<RfidInfo>();
- public List<RfidInfo> RfIDList { get => _RfIDList; set => _RfIDList = value; }
- private ObservableCollection<RfidInfo> _RuningData=new ObservableCollection<RfidInfo>();
- public ObservableCollection<RfidInfo> RuningData { get => _RuningData; set => _RuningData = value; }
- private CurrConfig _currConfig = new CurrConfig();
- public CurrConfig CurrConfig { get => _currConfig; set { SetProperty(ref _currConfig, value); } }
- private tb_formulasdata _formulasdata = new tb_formulasdata();
- public tb_formulasdata Formulasdata { get => _formulasdata; set { SetProperty(ref _formulasdata, value); } }
- private DateTime _DateTimeNow;
- /// <summary>
- /// 当前时间
- /// </summary>
- public DateTime DateTimeNow
- {
- get { return _DateTimeNow; }
- set { SetProperty(ref _DateTimeNow, value); }
- }
- private ObservableCollection<string> _CurrStationRfid=new ObservableCollection<string>();
- public ObservableCollection<string> CurrStationRfid { get => _CurrStationRfid; set => _CurrStationRfid = value; }
- /// <summary>
- /// 用户Id(从MES接口内获取)
- /// </summary>
- private string _UserId = "";
- /// <summary>
- /// 用户名(从MES接口内获取)
- /// </summary>
- private string _UserName = "未登录";
- /// <summary>
- /// 用于记录后处理数据来打印小票
- /// </summary>
- public ObservableCollection<ProcessDataModel> processDataModels = new ObservableCollection<ProcessDataModel>();
- public double[] ProduceData = new double[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 };
- public IServer HttpService { get => _httpService; set { SetProperty(ref _httpService, value); } }
- public string UserId { get => _UserId; set { SetProperty(ref _UserId, value); } }
- public string UserName { get => _UserName; set { SetProperty(ref _UserName, value); } }
- public CurentApplicationSettings CurentApplicationSettings { get => _CurentApplicationSettings; set { SetProperty(ref _CurentApplicationSettings, value); } }
- public bool Ismeswork { get => ismeswork; set { SetProperty(ref ismeswork, value); } }
- private bool ismeswork = true;
- //运行线程
- private Thread WorkThread;
- private Stopwatch[] stopwatchs = new Stopwatch[3];
- public Management()
- {
- stopwatchs[ 0 ] = new Stopwatch();
- stopwatchs[ 1 ] = new Stopwatch();
- stopwatchs[ 2 ] = new Stopwatch();
- for ( int i = 0; i < 6; i++ )
- {
- CurrStationRfid.Add("");
- }
- RuningToWorkEvent += Management_RuningToWorkEvent; ;
- WorkThread = new Thread(DataBridging);
- WorkThread.Name = "Plc读取";
- WorkThread.IsBackground = true;
- WorkThread.Start();
- }
- public void ConnectPlc()
- {
- s7PlcCommunicate = new S7PlcCommunicate(CurentApplicationSettings.PlcIP);
- s7PlcCommunicate.OpenPlc();
- }
- private void Management_RuningToWorkEvent(string key, bool value)
- {
- switch ( key )
- {
- case "1工位离心开始":
- if ( value )
- {
- stopwatchs[ 0 ].Restart();
- if ( RfIDList.Count != 0 )
- {
- int index= RfIDList.FindIndex(x => x.StationId == 1);
- if ( index != -1 )
- {
- RfIDList[ index ].StationId = 2;
- CurrStationRfid[ 1 ] = RfIDList[ index ].Rfid;
- LogHelper.Info(RfIDList[ index ].Rfid + " 1工位离心开始");
- }
- else
- {
- LogHelper.Info(" 1工位离心开始");
- }
- index = RfIDList.FindIndex(x => x.StationId == 1);
- if ( index != -1 )
- {
- RfIDList[ index ].StationId = 2;
- CurrStationRfid[ 2 ] = RfIDList[ index ].Rfid;
- LogHelper.Info(RfIDList[ index ].Rfid + " 1工位离心开始");
- }
- else
- {
- LogHelper.Info(" 1工位离心开始");
- }
- }
- else
- {
- LogHelper.Info(" 1工位离心开始");
- }
- LogHelper.Debuginfo("1工位离心开始已置位");
- }
- else
- {
- LogHelper.Debuginfo("1工位离心开始已复位");
- }
- break;
- case "1工位离心完成":
- if ( value )
- {
- stopwatchs[ 0 ].Stop();
- if ( RfIDList.Count != 0 )
- {
- int index= RfIDList.FindIndex(x => x.StationId == 2);
- if ( index != -1 )
- {
- RfIDList[ index ].StationId = 3;
- LogHelper.Info(CurrStationRfid[ 1 ] + " 1工位离心完成");
- }
- else
- {
- LogHelper.Info(" 1工位离心完成");
- }
- index = RfIDList.FindIndex(x => x.StationId == 2);
- if ( index != -1 )
- {
- RfIDList[ index ].StationId = 3;
- LogHelper.Info(CurrStationRfid[ 2 ] + " 1工位离心完成");
- }
- else
- {
- LogHelper.Info(" 1工位离心完成");
- }
- CurrStationRfid[ 1 ] = "";
- CurrStationRfid[ 2 ] = "";
- }
- else
- {
- LogHelper.Info(" 1工位离心完成");
- }
- LogHelper.Debuginfo("1工位离心完成已置位");
- }
- else
- {
- LogHelper.Debuginfo("1工位离心完成已复位");
- }
- break;
- case "2工位离心开始":
- if ( value )
- {
- stopwatchs[ 1 ].Restart();
- if ( RfIDList.Count != 0 )
- {
- int index = RfIDList.FindIndex(x => x.StationId == 3);
- if ( index != -1 )
- {
- RfIDList[ index ].StationId = 4;
- CurrStationRfid[ 3 ] = RfIDList[ index ].Rfid;
- LogHelper.Info(RfIDList[ index ].Rfid + " 2工位离心开始");
- }
- else
- {
- LogHelper.Info(" 2工位离心开始");
- }
- index = RfIDList.FindIndex(x => x.StationId == 1);
- if ( index != -1 )
- {
- RfIDList[ index ].StationId = 4;
- CurrStationRfid[ 4 ] = RfIDList[ index ].Rfid;
- LogHelper.Info(RfIDList[ index ].Rfid + " 2工位离心开始");
- }
- else
- {
- LogHelper.Info(" 2工位离心开始");
- }
- }
- else
- {
- LogHelper.Info(" 2工位离心开始");
- }
- LogHelper.Debuginfo("2工位离心开始已置位");
- }
- else
- {
- LogHelper.Debuginfo("2工位离心开始已复位");
- }
- break;
- case "2工位离心完成":
- if ( value )
- {
- stopwatchs[ 1 ].Stop();
- if ( RfIDList.Count != 0 )
- {
- int index= RfIDList.FindIndex(x => x.StationId == 4);
- if ( index != -1 )
- {
- RfIDList[ index ].StationId = 5;
- LogHelper.Info(CurrStationRfid[ 3 ] + " 2工位离心完成");
- }
- else
- {
- LogHelper.Info(" 2工位离心完成");
- }
- index = RfIDList.FindIndex(x => x.StationId == 4);
- if ( index != -1 )
- {
- RfIDList[ index ].StationId = 5;
- LogHelper.Info(CurrStationRfid[ 4 ] + " 1工位离心完成");
- }
- else
- {
- LogHelper.Info(" 1工位离心完成");
- }
- CurrStationRfid[ 3 ] = "";
- CurrStationRfid[ 4 ] = "";
- }
- else
- {
- LogHelper.Info(" 2工位离心完成");
- }
- LogHelper.Debuginfo("2工位离心完成已置位");
- }
- else
- {
- LogHelper.Debuginfo("2工位离心完成已复位");
- }
- break;
- case "脱模开始":
- if ( value )
- {
- LogHelper.Info(CurrConfig.Rfid + " 脱模开始");
- PlateInPlace(CurrConfig.Rfid);
- LogHelper.Debuginfo("脱模开始已置位");
- }
- else
- {
- LogHelper.Debuginfo("脱模开始已复位");
- }
- break;
- case "脱模完成":
- if ( value )
- {
- LogHelper.Info(CurrConfig.Rfid + " 脱模完成");
- if ( processDataModels.Count != 0 )
- {
- PrintInfo(processDataModels[ 0 ], "手动");
- processDataModels.RemoveAt(0);
- }
- LogHelper.Debuginfo("脱模完成已置位");
- }
- else
- {
- LogHelper.Debuginfo("脱模完成已复位");
- }
- break;
- case "固化开始":
- if ( value )
- {
- stopwatchs[ 2 ].Restart();
- if ( RfIDList.Count != 0 )
- {
- int index= RfIDList.FindIndex(x => x.StationId ==5 );
- if ( index != -1 )
- {
- RfIDList[ index ].StationId = 6;
- CurrStationRfid[ 5 ] = RfIDList[ index ].Rfid;
- LogHelper.Info(RfIDList[ index ].Rfid + " 固化开始");
- }
- else
- {
- LogHelper.Info(" 固化开始");
- }
- index = RfIDList.FindIndex(x => x.StationId == 5);
- if ( index != -1 )
- {
- RfIDList[ index ].StationId = 6;
- CurrStationRfid[ 6 ] = RfIDList[ index ].Rfid;
- LogHelper.Info(RfIDList[ index ].Rfid + " 固化开始");
- }
- else
- {
- LogHelper.Info(" 固化开始");
- }
- }
- else
- {
- LogHelper.Info(" 固化开始");
- }
- LogHelper.Debuginfo("固化开始已置位");
- }
- else
- {
- LogHelper.Debuginfo("固化开始已复位");
- }
- break;
- case "固化完成":
- if ( value )
- {
- stopwatchs[ 2 ].Stop();
- if ( RfIDList.Count != 0 )
- {
- int index= RfIDList.FindIndex(x => x.StationId ==6 );
- if ( index != -1 )
- {
- RfIDList.RemoveAt(index);
- LogHelper.Info(RfIDList[ index ].Rfid + " 固化完成");
- }
- else
- {
- LogHelper.Info(" 固化完成");
- }
- index = RfIDList.FindIndex(x => x.StationId == 6);
- if ( index != -1 )
- {
- RfIDList.RemoveAt(index);
- LogHelper.Info(RfIDList[ index ].Rfid + " 固化完成");
- }
- else
- {
- LogHelper.Info(" 固化完成");
- }
- //CurrStationRfid[5] = RfIDList[index].Rfid;
- //CurrStationRfid[6] = RfIDList[index].Rfid;
- int hour= DateTime.Now.Hour;
- ProduceData[ hour ] = ProduceData[ hour ] + 2;
- for ( int i = hour + 1; i < ProduceData.Length; i++ )
- {
- ProduceData[ i ] = 0;
- }
- ProduceDataToChangeEvent?.Invoke();
- }
- else
- {
- LogHelper.Info(" 固化完成");
- }
- LogHelper.Debuginfo("固化完成已置位");
- }
- else
- {
- LogHelper.Debuginfo("固化完成已复位");
- }
- break;
- default:
- break;
- }
- }
- public void DataBridging()
- {
- ObservableDictionary<string,bool> BoolPairs=new ObservableDictionary<string, bool>();
- BoolPairs.Add("1工位离心开始", false);
- BoolPairs.Add("1工位离心完成", false);
- BoolPairs.Add("2工位离心开始", false);
- BoolPairs.Add("2工位离心完成", false);
- BoolPairs.Add("脱模开始", false);
- BoolPairs.Add("脱模完成", false);
- BoolPairs.Add("固化开始", false);
- BoolPairs.Add("固化完成", false);
- BoolPairs.CollectionChanged += BoolPairs_CollectionChanged;
- //BoolPairs["脱模开始"] =true ;
- //BoolPairs["脱模完成"] = true ;
- while ( true )
- {
- try
- {
- if ( s7PlcCommunicate != null && s7PlcCommunicate.IsConnected )
- {
- byte []buff= s7PlcCommunicate.ReadByte(25, 780, 84);
- int actuallength=buff[73];
- byte[] buffsT = new byte[ actuallength ];
- Array.Copy(buff, 74, buffsT, 0, actuallength);
- CurrConfig.Rfid = Encoding.ASCII.GetString(buffsT);
- BoolPairs[ "1工位离心开始" ] = s7PlcCommunicate.GetBitAt(buff, 0, 0);
- BoolPairs[ "1工位离心完成" ] = s7PlcCommunicate.GetBitAt(buff, 0, 1);
- BoolPairs[ "2工位离心开始" ] = s7PlcCommunicate.GetBitAt(buff, 1, 0);
- BoolPairs[ "2工位离心完成" ] = s7PlcCommunicate.GetBitAt(buff, 1, 1);
- BoolPairs[ "脱模开始" ] = s7PlcCommunicate.GetBitAt(buff, 2, 0);
- BoolPairs[ "脱模完成" ] = s7PlcCommunicate.GetBitAt(buff, 2, 1);
- BoolPairs[ "固化开始" ] = s7PlcCommunicate.GetBitAt(buff, 3, 0);
- BoolPairs[ "固化完成" ] = s7PlcCommunicate.GetBitAt(buff, 3, 1);
- //固化压力 792.0
- CurrConfig.Pressure1 = s7PlcCommunicate.GetRealAt(buff, 12);
- CurrConfig.PTime1 = s7PlcCommunicate.GetTimeSpanAt(buff, 16);
- CurrConfig.Speed = s7PlcCommunicate.GetShortAt(buff, 32);
- CurrConfig.Speed2 = s7PlcCommunicate.GetShortAt(buff, 34);
- CurrConfig.RealSpeed = s7PlcCommunicate.GetRealAt(buff, 36);
- CurrConfig.RealSpeed2 = s7PlcCommunicate.GetRealAt(buff, 40);
- CurrConfig.Time = s7PlcCommunicate.GetTimeSpanAt(buff, 44);
- CurrConfig.Time2 = s7PlcCommunicate.GetTimeSpanAt(buff, 48);
- //CurrConfig.Power1_1 = s7PlcCommunicate.GetShortAt(buff, 20);
- //CurrConfig.Power1_2 = s7PlcCommunicate.GetShortAt(buff, 22);
- //CurrConfig.Power1_3 = s7PlcCommunicate.GetShortAt(buff, 24);
- //CurrConfig.Power1_4 = s7PlcCommunicate.GetShortAt(buff, 26);
- CurrConfig.Realtime = ( float ) ( stopwatchs[ 0 ].ElapsedMilliseconds / 1000.0 );
- CurrConfig.Realtime2 = ( float ) ( stopwatchs[ 1 ].ElapsedMilliseconds / 1000.0 );
- CurrConfig.Realtime3 = ( float ) ( stopwatchs[ 2 ].ElapsedMilliseconds / 1000.0 );
- for ( int i = 0; i < stopwatchs.Length; i++ )
- {
- if ( stopwatchs[ i ].ElapsedMilliseconds / 1000.0 > 1000 )
- {
- stopwatchs[ i ].Stop();
- }
- }
- }
- List<tb_formulasdata> tb_Formulasdatas = SqlSugarHelper.Queryabletb_formulasdata();
- if ( tb_Formulasdatas.Count != 0 )
- Formulasdata = tb_Formulasdatas[ 0 ];
- }
- catch
- {
- }
- Thread.Sleep(50);
- }
- }
- private void BoolPairs_CollectionChanged(in NotifyCollectionChangedEventArgs<KeyValuePair<string, bool>> e)
- {
- if ( e.NewItem.Value != e.OldItem.Value )
- {
- RuningToWorkEvent?.Invoke(e.OldItem.Key, e.NewItem.Value);
- }
- }
- private void Serial_ConnectionChanged(SerialCommunication arg1, bool arg2)
- {
- if ( arg2 )
- LogHelper.Info(arg1.PortName + ":已连接");
- if ( !arg2 )
- LogHelper.Info(arg1.PortName + ":断开连接");
- }
- private void Serial_DataReceived(SerialCommunication arg1, string arg2)
- {
- LogHelper.Info("收到" + arg1.PortName + $"消息:{arg2}");
- }
- /// <summary>
- /// 网板读取获取数据并上传记录
- /// </summary>
- public async Task PlateInPlace(string value)
- {
- var IsOK = true;
- try
- {
- if ( !string.IsNullOrEmpty(value) )
- {
- try
- {
- if ( value.Length != 8 )
- {
- return;
- }
- else
- {
- var boardId = value;
- string boardguid = Guid.NewGuid().ToString();
- var modelsinfo = "";
- var materialtype = "";
- var printdeviceId = "";
- var brand = "";
- var printTagProduct = "";
- var iskid = false;
- var ishaiwai = false;
- var isLarge = "无";
- var count = 0;
- var tip = "";
- var isoutline = false;
- XnRestfulResult<List<Re_Items>> groupdata=new XnRestfulResult<List<Re_Items>>();
- if ( Ismeswork )
- {
- groupdata = _httpService.GetGroupItems(boardId, CurentApplicationSettings.DeviceId);
- if ( !groupdata.Success )
- {
- if ( groupdata.RawText.Contains("未点检") )
- {
- var s = MessageBox.Show("设备未点检,请点检后确认!", "提示", MessageBoxButton.OK);
- }
- LogHelper.MesInfo($"网板ID:{boardId}获取信息失败,Code:{( int ) groupdata.Code},原因:{groupdata.RawText}");
- isoutline = true;
- }
- else
- {
- if ( groupdata.Data.Count <= 0 )
- {
- LogHelper.MesInfo($"网板ID:{boardId}获取信息失败,Code:{( int ) groupdata.Code},原因:{groupdata.RawText}");
- isoutline = true;
- }
- }
- }
- else
- {
- isoutline = true;
- }
- if ( !isoutline )
- {
- ///上传后处理记录
- var result = UpdateRecord(boardId);
- if ( !string.IsNullOrEmpty(result) )
- {
- LogHelper.MesInfo($"上传记录失败,{result}!");
- var boxresult = MessageBox.Show($"{result}(是:放回;否:重试)", "提示", MessageBoxButton.YesNo);
- if ( boxresult == MessageBoxResult.Yes )
- {
- IsOK = false;
- return;
- }
- }
- ///读取网板内的牙模的信息(方便打印在小票上),如果读取失败就读取下一个牙模,读取成功就跳出循环
- for ( int i = 0; i < 10; i++ )
- {
- try
- {
- modelsinfo = "";
- count = groupdata.Data.Count;
- var Id = groupdata.Data[groupdata.Data.Count - i].itemId;
- var infos = _httpService.GetModels(Id, CurentApplicationSettings.DeviceId);
- if ( infos.Success )
- {
- modelsinfo = infos.Data.uvcuringReleaseBatch + " " + infos.Data.alignerSpec.material + "-" + infos.Data.alignerSpec.thickness;
- if ( infos.Data.order.is_expedited == "1" || infos.Data.remade || infos.Data.produceType == "R" )
- {
- modelsinfo = modelsinfo + "\r\n";
- if ( infos.Data.order.is_expedited == "1" )
- {
- modelsinfo = modelsinfo + " 加急";
- }
- if ( infos.Data.remade )
- {
- modelsinfo = modelsinfo + " 返工";
- }
- if ( infos.Data.produceType == "R" )
- {
- modelsinfo = modelsinfo + " 保持器";
- }
- }
- iskid = infos.Data.isKid;
- ishaiwai = infos.Data.order.country.Contains("中国") ? false : true;
- if ( infos.Data.processParameters != null )
- {
- var carrierf = infos.Data.processParameters.FirstOrDefault(x => x.key == "carrier");
- if ( carrierf != null )
- {
- isLarge = carrierf.value == "small" ? "小载具" : "大载具";
- }
- }
- var record = _httpService.GetProductionRecord(Id);
- if ( record.Success )
- {
- printdeviceId = record.Data.First().deviceId;
- if ( record.Data.First().description.FirstOrDefault(x => x.key == "printTaskId") != null )
- {
- var taskId = record.Data.First().description.FirstOrDefault(x => x.key == "printTaskId").value;
- var taskinfo = _httpService.GetPrintTask(taskId);
- if ( taskinfo.Success )
- {
- materialtype = taskinfo.Data.description.FirstOrDefault(x => x.key == "filmType") != null ? taskinfo.Data.description.FirstOrDefault(x => x.key == "filmType").value : "";
- printTagProduct = taskinfo.Data.description.FirstOrDefault(x => x.key == "printTagProduct") != null ? taskinfo.Data.description.FirstOrDefault(x => x.key == "printTagProduct").value : "";
- brand = taskinfo.Data.description.FirstOrDefault(x => x.key == "productOfProduce") != null ? taskinfo.Data.description.FirstOrDefault(x => x.key == "productOfProduce").value : "";
- break;
- }
- }
- }
- }
- }
- catch ( Exception e )
- {
- LogHelper.Error("读取网板内牙模信息异常:" + e.ToString());
- }
- }
- }
- else
- {
- LogHelper.MesInfo($"网板{value}获取数据异常,不上传记录");
- modelsinfo = "异常";
- materialtype = "异常";
- printTagProduct = "异常";
- printdeviceId = "异常";
- brand = "异常";
- }
- ///将生产信息记录下,用于在打印完成时打印小票
- App.Current.Dispatcher.Invoke(( System.Action ) delegate
- {
- //添加记录
- processDataModels.Add(new ProcessDataModel()
- {
- BoardId = boardId,
- ModelsInfo = modelsinfo,
- StartTime = DateTime.Now.ToString("HH:mm:ss"),
- State = ProcessState.入料中,
- BoardGuid = boardguid,
- stopwatch = new System.Diagnostics.Stopwatch(),
- MaterialType = materialtype,
- PrintTagProduct = printTagProduct,
- PrintDeviceId = printdeviceId,
- IsKid = iskid,
- Tip = tip,
- IsOverSea = ishaiwai,
- IsLarge = isLarge,
- Brand = brand,
- Count = count,
- });
- if ( processDataModels.Count > 10 )
- {
- processDataModels.RemoveAt(0);
- }
- RfidInfo rfidInfo= new RfidInfo() { Rfid = value, StationId = 1, ModelsInfo=modelsinfo, State="入料中", StartTime=DateTime.Now };
- if ( RfIDList.Find(x => x.Rfid == value) == null )
- {
- RfIDList.Add(rfidInfo);
- RuningData.Add(rfidInfo);
- }
- });
- }
- }
- catch ( Exception e )
- {
- LogHelper.Error("网板读取获取数据异常,原因:" + e.ToString());
- }
- }
- else
- {
- LogHelper.Info("未读取到网板编号");
- //WriteInfo($"未读取到网板编号");
- }
- }
- catch
- {
- }
- finally
- {
- }
- }
- /// <summary>
- /// 上传生产记录
- /// </summary>
- /// <param name="RfidId">从扫码枪获取的网板Id</param>
- /// <returns></returns>
- public string UpdateRecord(string RfidId)
- {
- try
- {
- Rt_ProductionRecordDto rt_ProductionRecord = new Rt_ProductionRecordDto()
- {
- userId = UserId,///用户Id
- creationTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz"),///生产时间
- deviceId = CurentApplicationSettings.DeviceId,///设备编号
- productionType = "UVcuringNextTreat",///生产工序,固定不变
- description = new List<DescriptionItem>()
- {
- ///从扫码枪获取的网板Id
- new DescriptionItem(){ key="containerId",value=RfidId},
- //后处理配方(根据设备不同参数也不同,具体需要上传什么参数要具体咨询下现场的工艺人员(程朋))
- new DescriptionItem(){ key="CentrifugalTime1",value="240"},
- new DescriptionItem(){ key="CentrifugalTime2",value="240"},
- new DescriptionItem(){ key="LightSolidifiedTime",value="240"},
- }
- };
- var recordData = _httpService.PostRecord(rt_ProductionRecord);
- if ( recordData.Success )
- {
- LogHelper.MesInfo($"网板ID:{RfidId}上传记录成功");
- return "";
- }
- else
- {
- LogHelper.MesInfo($"网板ID:{RfidId}上传记录失败,Code:{( int ) recordData.Code},原因:{recordData.RawText}");
- /////记录至数据库
- //Rt_AngelNetRecordDto recordDto = new Rt_AngelNetRecordDto()
- //{
- // DevcieId = DataPathcs.GetConnectionStringsConfig("DeviceID"),
- // EquipmentType = 4,
- // UserId = UserName,
- // descriptions = new List<Description>() {
- // new Description(){ Key="BoardId",KeyValue=RfidId },
- // new Description(){ Key="Code",KeyValue=recordData.Code.ToString() },
- // new Description(){ Key="RawText",KeyValue=recordData.RawText }
- // }
- //};
- //var recorddata = alignServer.InsertProductionRecord(recordDto);
- return $"{recordData.RawText}";
- }
- }
- catch ( Exception ex )
- {
- LogHelper.Error($"网板ID:{RfidId}上传记录异常,原因{ex.Message}");
- return ex.ToString();
- }
- }
- /// <summary>
- /// 小票打印
- /// </summary>
- /// <param name="printinfo"></param>
- /// <param name="Position"></param>
- public void PrintInfo(ProcessDataModel printinfo, string Position)
- {
- try
- {
- var pmTitle = new PrintModel
- {
- FontFamily = "宋体",
- FontSize = 15,
- IsBold = true,
- Text = new StringReader("\n" + "<<<<后处理收料信息>>>>") //首行需要空行,某些打印机首行不为空时会出现“首行乱码问题”
- };
- var count = 0;
- if ( printinfo.SolidifyStation != 0 )
- {
- count = printinfo.SolidifyStation % 2 == 1 ? 1 : 2;
- }
- var printContent = new StringBuilder();
- printContent.Append("<<<----------------------------->>>" + "\n");
- printContent.Append($"出料窗口:{CurentApplicationSettings.DeviceId}" + $",{Position}传送带,第{count}板" + "\n");
- printContent.Append($"网板编号:{printinfo.BoardId}" + "\n");
- printContent.Append("出票时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n");
- printContent.Append("<<<----------------------------->>>" + "\n");
- printContent.Append(" " + "\n");
- var batchs = new PrintModel
- {
- FontFamily = "宋体",
- FontSize = 12,
- IsBold = true,
- Text = new StringReader(printContent.ToString())
- };
- var sb = new StringBuilder();
- if ( !string.IsNullOrEmpty(printinfo.Tip) )
- {
- sb.Append($"记录上传异常:{printinfo.Tip}" + "\n");
- }
- sb.Append($"3D打印设备:{printinfo.PrintDeviceId}" + "\n");
- sb.Append($"批次:{printinfo.ModelsInfo}" + "\n");
- sb.Append($"膜片规格:{printinfo.MaterialType}" + "\n");
- sb.Append($"类型:{printinfo.PrintTagProduct}" + "\n");
- sb.Append($"品牌:{printinfo.Brand}" + "\n");
- sb.Append($"是否Kid:{( printinfo.IsKid == true ? "是" : "否" )}" + "\n");
- sb.Append($"是否海外:{( printinfo.IsOverSea == true ? "是" : "否" )}" + "\n");
- sb.Append($"大小载具:{printinfo.IsLarge}" + "\n");
- sb.Append($"数量:{printinfo.Count.ToString()}" + "\n");
- var pmContent2 = new PrintModel
- {
- FontFamily = "宋体",
- FontSize = 10,
- IsBold = false,
- Text = new StringReader(sb.ToString().Trim())
- };
- PrintModel[] pms = { pmTitle, batchs, pmContent2 };
- LogHelper.Info($"打印内容{printContent}" + "\n" + sb + "\n" + "<<<------------------------------->>>");
- TicketPrinterHelper.Print(pms, CurentApplicationSettings.PrinterName);
- }
- catch ( Exception ex )
- {
- LogHelper.Error("打印异常,原因:" + ex.ToString());
- }
- }
- }
- }
|