using Cksoft.Data; using Cksoft.Data.Repository; using Cksoft.Unity; using DllEapDal; using DllEapEntity; using RabbitMQ.Client; using System; using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Linq; using Microsoft.Extensions.Logging; using Mes.Model; using System.Threading.Tasks; namespace DllScan { public class ScanCore { private ILogger loger = null; public ScanCore(ILogger loger) { this.loger = loger; } private Thread SocketRecThread = null;//socket接受数据线程 private ScanSocket CurrHsms = null; public MacOrder CurrMac = null;//机台数据 public List CurrItemDt { set; get; } = null;//固定项表 //public string CurrLogQueueName=""; //private IModel CurrQueueChannel = null; private string CurrFileDir = "";//日志文件主路径 //扫描链表,将扫描的数据存放在此,供调程任务消费 private List ScanList = new List(); public bool IsRun = false;//检查线程是否在运行 public bool SocketIsRun = false;//socket接受线程是否在运行 //private string CurrRecQueueName = "";//接收队列名称 hsmsreceive+机台编号 //private string CurrSendQueueName = "";//发送队列名称 hsmssend+机台编号 public delegate void SetText(string str); public event SetText eventSetText = null; private string CurrLogFile = ""; //装载或卸载事件交换机 private string LOrDExchange = ""; //private string CurrStatusShowQueueName = "";//状态显示队列 //private Thread CheckSocketThread = null;//检查socket是否正常的线程 //运行中发生错误信息 public delegate void SetErrorText(int id, string errorinfo); public event SetErrorText eventSetErrorText = null; private Thread CheckThread = null;//检查线程 //private bool ReadDbStatus = false;//是否正确读取配置文件 //private bool QueueStatus = false;//消息队列是否注册成功 //private long LastRecTick = 0;//记录最后接受机台数据时间戳 private bool RecordSend = false;//标记开始记录发送包 public ScanCore(MacOrder mac, ILogger loger) { CurrMac = mac; this.loger = loger; //CurrLogQueueName = AppConfigurtaionServices.Configuration["mqname:scanlogmqname"]; } public int SetCurrID(int id, ref string errorinfo) { return 1; } public int ShutDown(ref string errorinfo) { try { IsRun = false; SocketIsRun = false; //关闭连接 ShutDownSocket(ref errorinfo); return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } //记录程序内部错误日志 private void WriteErrorInfoLog(string errorinfo) { StringBuilder sqlstr = new StringBuilder(100); try { //if (CurrLogFile != "") //{ // DllUnity.Unity.WriteLog(CurrLogFile, errorinfo); //} //eventSetErrorText?.Invoke(CurrMac.ID, errorinfo); string temperrorinfo = ""; ScanBlock node = new ScanBlock("", CurrMac.MacFCode, DateTime.Now); int result = WriteLogToQueue(errorinfo, ref temperrorinfo); if (result <= 0) { sqlstr.AppendFormat("\r\n"); sqlstr.AppendFormat("写日志到MQ发生错误:{0}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); sqlstr.AppendFormat("原始错误信息:{0}\r\n", errorinfo); sqlstr.AppendFormat("错误信息:{0}\r\n", temperrorinfo); //写入本地错误日志 WriteLog.WriteLogFor(CurrLogFile, sqlstr.ToString()); } } catch (Exception ex) { eventSetErrorText?.Invoke(CurrMac.MacID, ex.Message.ToString()); sqlstr.AppendFormat("\r\n"); sqlstr.AppendFormat("写日志到MQ发生错误:{0}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); sqlstr.AppendFormat("错误信息:{0}\r\n", ex.Message.ToString()); WriteLog.WriteLogFor(CurrLogFile, sqlstr.ToString()); } } //将日志写到消息队列中 //总的启动 //private IModel RegeditChannel(ref string errorinfo) //{ // try // { // var factory = new ConnectionFactory(); // factory.HostName = AppConfigurtaionServices.Configuration["rabbitmq:IPAddress"]; // factory.UserName = AppConfigurtaionServices.Configuration["rabbitmq:UserName"]; // factory.Password = AppConfigurtaionServices.Configuration["rabbitmq:Password"]; // var connection = factory.CreateConnection(); // var channel = connection.CreateModel(); // return channel; // } // catch (Exception ex) // { // errorinfo = ex.Message.ToString(); // return null; // } //} public int Start(ref string errorinfo) { //string errorinfo = ""; CurrLogFile = CreateLogFile(CurrMac.MacID, CurrMac.MacFCode, ref errorinfo); if (errorinfo != "") { return -1; } StringBuilder sqlstr = new StringBuilder(100); //消息队列必须正常连接,如果无法连接则不能启动程序 //CurrQueueChannel = RegeditChannel(ref errorinfo); //if (CurrQueueChannel == null) //{ // sqlstr.Clear(); // sqlstr.AppendFormat("{0}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); // sqlstr.AppendFormat("初始化队列发生错误\r\n"); // sqlstr.AppendFormat("{0}", errorinfo); // WriteErrorInfoLog(sqlstr.ToString()); // return -1; //} int result = StartCheckThread(ref errorinfo); if (result <= 0) { IsRun = false; //处理接受失败,写入数据库 sqlstr.Clear(); sqlstr.AppendFormat("{0}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); sqlstr.AppendFormat("开始检查线程发生错误\r\n"); sqlstr.AppendFormat("{0}", errorinfo); WriteErrorInfoLog(sqlstr.ToString()); return -1; } return 1; } //启动总的检查线程,此线程应该一直运行,直到程序退出 public int StartCheckThread(ref string errorinfo) { try { IsRun = true; //成功后,启动接受线程 CheckThread = new Thread(CheckThreadFun); CheckThread.Start(); return 1; } catch (Exception ex) { IsRun = false; errorinfo = ex.Message.ToString(); return -1; } } public int StopCheckThread(ref string errorinfo) { try { IsRun = false; SocketIsRun = false; ShutDownSocket(ref errorinfo); if (CheckThread == null) return 1; //CheckThread.Interrupt();//中断线程 //CheckThread.IsBackground = true;//让后台处理 CheckThread = null; return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } private void CheckThreadFun() { try { StringBuilder sqlstr = new StringBuilder(100); int sleeptime = int.Parse(CurrItemDt[0].FCode); string errorinfo = ""; string closesocketerror = ""; while (IsRun) { errorinfo = ""; closesocketerror = ""; int result = CheckThreadFunFor(ref errorinfo); if (result <= 0) { //发生了错误,需要清理 SocketIsRun = false; ShutDownSocket(ref closesocketerror); Thread.Sleep(1000 * 5);//休眠5秒钟 sqlstr.Clear(); sqlstr.AppendFormat("{0}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); sqlstr.AppendFormat("检查线程发生错误\r\n"); sqlstr.AppendFormat("{0}", errorinfo); if (closesocketerror != "") { sqlstr.AppendFormat("关闭SOCKET错误:{0}", closesocketerror); } eventSetErrorText?.Invoke(CurrMac.ID, errorinfo); WriteErrorInfoLog(sqlstr.ToString()); if (result == -11)//说明是验证指令出现错误,需要休眠 { Thread.Sleep(1000 * 60); } //Thread.Sleep(sleeptime); } else { //说明是重新连接后的,需要刷新界面状态 if (result != 100) { eventSetErrorText?.Invoke(CurrMac.ID, "正常接受数据"); } //发送测试包 result = SendLinkTest(ref errorinfo); if (result <= 0) { sqlstr.Clear(); sqlstr.AppendFormat("{0}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); sqlstr.AppendFormat("发送连接测试错误:\r\n"); sqlstr.AppendFormat("{0}", errorinfo); eventSetErrorText?.Invoke(CurrMac.MacID, errorinfo); WriteErrorInfoLog(sqlstr.ToString()); ShutDownSocket(ref errorinfo); } } Thread.Sleep(sleeptime); } } catch (Exception ex) { IsRun = false; WriteErrorInfoLog("检查线程出错:" + ex.Message.ToString()); } } //初始化连接线程函数 private int CheckThreadFunFor(ref string errorinfo) { try { int result = 0; //判断socket是否正常通行 if (CurrHsms == null) { //修改状态为开始连接机台 RecordSend = false; CurrHsms = new ScanSocket(); bool init = CurrHsms.InitSocket(CurrMac.ScanIp, CurrMac.FPort, ref errorinfo); if (!init) { errorinfo = "初始化连接发生错误:" + errorinfo; return -1; } if (!IsRun) { errorinfo = "检查线程已终止。"; return -1; } //设置SOCKET超时时间,防止接受不到数据 CurrHsms.SetReceiveTimeout(1000 * 15); CurrHsms.SetSendTimeout(1000 * 15); result = StartSocketRecThread(ref errorinfo); if (result < 0) { errorinfo = "启动接受线程发生错误:" + errorinfo; return -1; } RecordSend = true; //设置SOCKET超时时间,一直接受 CurrHsms.SetReceiveTimeout(0); CurrHsms.SetSendTimeout(1000 * 30);//设置发送超时为30秒 return 1; } else { //检查是否存在超时未回复的包,如果存在则关闭socket连接 result = CheckList(10, ref errorinfo); if (result <= 0) { errorinfo = "启动接受线程检查数据包错误发生错误:" + errorinfo; return -1; } return 100; } } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } //发送测试连接包 private int SendLinkTest(ref string errorinfo) { try { return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } //检查已发送的数据,是否在规定的时间内得到回复 private int CheckList(int timeout, ref string errorinfo) { try { //long start = DateTime.Now.Ticks; //long end = start + timeout * 10000000; //for (int i = 0; i < CurrSendList.Count; i++) //{ // start = CurrSendList[i].SendTime; // end = start + timeout * 10000000; // if (DateTime.Now.Ticks > end) // { // errorinfo = "存在超时未收到响应包。" + CurrSendList[i].CurrOrder.FCode; // return -1; // } //} return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } public int StartSocketRecThread(ref string errorinfo) { try { //if (SocketRecThread != null) //{ // SocketRecThread.Abort(); //} SocketIsRun = true; //成功后,启动接受线程 SocketRecThread = new Thread(SocketRecThreadFun); SocketRecThread.Start(); return 1; } catch (Exception ex) { SocketIsRun = false; errorinfo = ex.Message.ToString(); return -1; } } //关闭连接 private bool ShutDownSocket(ref string errorinfo) { try { SocketIsRun = false; CurrHsms.ShutDownSocket(ref errorinfo); CurrHsms = null; ////上报断开连接 //McaSecVMst msgdt = GetMsgDt(CurrMac.MacFCode, DateTime.Now, 0, 0, -1, -1, "", ref errorinfo); //if (msgdt == null) // return false; //OrderBlock tempentity = new OrderBlock(msgdt); //int result = WriteBusinessToQueue(CurrMesQueueName, tempentity, ref errorinfo); //if (result <= 0) // return false; ////断开后,需要报告给状态管理系统,标志机台状态已经断开 //result = WriteBusinessToQueue(CurrMacStatusQueueName, tempentity, ref errorinfo); //if (result <= 0) // return false; string temperrorinfo = ""; ScanBlock node = new ScanBlock("", CurrMac.MacFCode, DateTime.Now); int result = WriteLogToQueue("关闭连接", ref temperrorinfo); if (result <= 0) { StringBuilder sqlstr = new StringBuilder(100); sqlstr.AppendFormat("\r\n"); sqlstr.AppendFormat("写日志到MQ发生错误:{0}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); sqlstr.AppendFormat("原始错误信息:{0}\r\n", errorinfo); sqlstr.AppendFormat("错误信息:{0}\r\n", temperrorinfo); //写入本地错误日志 WriteLog.WriteLogFor(CurrLogFile, sqlstr.ToString()); } return true; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return false; } } private string CreateLogFile(int mcaid, string code, ref string errorinfo) { try { string sFilePath = System.IO.Directory.GetCurrentDirectory() + "\\log" + DateTime.Now.ToString("yyyyMMdd"); string sFileName = mcaid.ToString() + "_" + code + "_" + DateTime.Now.ToString("HHmmss") + ".log"; sFileName = sFilePath + "\\" + sFileName; //文件的绝对路径 if (!Directory.Exists(sFilePath))//验证路径是否存在 { Directory.CreateDirectory(sFilePath); //不存在则创建 } return sFileName; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return ""; } } private void SocketRecThreadFun() { StringBuilder sqlstr = new StringBuilder(100); try { int result = 0; string errorinfo = ""; while (IsRun && SocketIsRun) { errorinfo = ""; result = TheadFunNew(ref errorinfo); //if(errorinfo!="") //{ // //说明发生了错误,先写日志,然后停止该线程 //} //if (result == -11) //{ // //socket错误 //} if (result <= 0) { //sqlstr.Clear(); //sqlstr.AppendFormat("{0}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //sqlstr.AppendFormat("接受数据线程发生错误\r\n"); //sqlstr.AppendFormat("{0}", errorinfo); //WriteErrorInfoLog(errorinfo); ShutDownSocket(ref errorinfo); ScanBlock node = new ScanBlock("", CurrMac.MacFCode, DateTime.Now); node.Remark = errorinfo; string temperrorinfo = ""; result = WriteLogToQueue($"TheadFunNew 出错{errorinfo}", ref temperrorinfo); if (result <= 0) { sqlstr.AppendFormat("\r\n"); sqlstr.AppendFormat("写日志到MQ发生错误:{0}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); sqlstr.AppendFormat("原始错误信息:{0}\r\n", errorinfo); sqlstr.AppendFormat("错误信息:{0}\r\n", temperrorinfo); //写入本地错误日志 //WriteLog.WriteLogFor(CurrLogFile, sqlstr.ToString()); WriteErrorInfoLog(sqlstr.ToString()); } break; } // isrun = false; } } catch (Exception ex) { sqlstr.Clear(); sqlstr.AppendFormat("{0}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); sqlstr.AppendFormat("接受数据线程发生错误\r\n"); sqlstr.AppendFormat("{0}", ex.Message.ToString()); WriteErrorInfoLog(sqlstr.ToString()); //启动线程出错 } //处理接受线程停止错误 } //线程处理函数 private int TheadFunNew(ref string errorinfo) { try { ScanBlock node = ReceiveBlock(ref errorinfo); if (node == null) return -1; WriteLogToQueue($"接受到扫描信息= {node.ScanStr} ......", ref errorinfo); //查找扫描链表,看看是否有一样的信息存在,如果存在则不处理此扫描信息 lock (ScanList) { List templist = ScanList.Where(t => t.ScanStr == node.ScanStr).ToList(); if(templist.Count>0) { WriteLogToQueue($"链表中存在相同的节点= {node.ScanStr} 无需处理......", ref errorinfo); return 1; } else { //开启新的任务处理此扫描 //Task.Factory.StartNew(new Func(ProcessBlockForTask),node); //Task.Factory.StartNew(new Action(ProcessBlockForTask), node); //将节点添加到链表 ScanList.Add(node); //启动调程任务 Task.Run(() => ProcessBlockForTask(node)); } } //LastRecTick = DateTime.Now.Ticks;//更新时间戳 //将从机台收到的数据打包发送给消息队列 //WriteLogToQueue($"接受到程序名称= {node.ScanStr} 开始处理......", ref errorinfo); //int result = ProcessBlock(node, ref errorinfo); //if (result <= 0) //{ // errorinfo = "调程发生错误,错误信息为:" + errorinfo; // string temperrorinfo = ""; // node.Remark = errorinfo; // WriteLogToQueue($"机台={node.MacCode}调程出现错误,错误信息为:{errorinfo}", ref temperrorinfo); // errorinfo = ""; // return 100; //} //string temperrorinfo1 = ""; //node.Remark = $"download success"; //WriteLogToQueue($"机台={node.MacCode}调程完成。", ref temperrorinfo1); return 1; } catch (Exception ex) { errorinfo = ex.ToString(); return -1; } } private void ProcessBlockForTask(ScanBlock sendentity) { string errorinfo = ""; IDatabase db = null; try { //调程 int result = 0; db = DbFactory.Base("eap"); string scanstr = sendentity.ScanStr.Replace('\r', ' ').Trim(); loger.LogError($"开始处理扫描调程,{scanstr}"); string client = AppConfigurtaionServices.Configuration["Client"]; //下载程序前先清空auto目录下所有程序 Dad3350ProgramDal dad3350 = new Dad3350ProgramDal(db); if (client == "Onsemi") { result = dad3350.ClearProgramAutoDir(CurrMac.MacFCode, ref errorinfo); } else { result = dad3350.ClearProgram(CurrMac.MacFCode, ref errorinfo); } if (CurrMac.MacModelFCode.Trim().ToLower() == "dad3350"&&client=="qingdao") { loger.LogError($"开始处理dad3350调程,以文件的方式,{scanstr}"); FilesProgramDal filedal = new FilesProgramDal(db); result = filedal.DownloadProgram(CurrMac.MacFCode, scanstr, ref errorinfo); if (result <= 0) { loger.LogError($"文件方式调程失败,{scanstr}:{errorinfo}"); } loger.LogError($"文件方式调程成功。{scanstr}"); } else { ProgramDal dal = new ProgramDal(db, loger); result = dal.DownloadProgram(CurrMac.MacFCode, scanstr, ref errorinfo); if (result <= 0) { loger.LogError($"调程失败,{scanstr}:{errorinfo}"); } loger.LogError($"调程成功。{scanstr}"); } //删除队列中的数据 lock(ScanList) { ScanList.RemoveAll(t => t.ScanStr == sendentity.ScanStr); //List templist = ScanList.Where(t => t.ScanStr == sendentity.ScanStr).ToList(); //if(templist.Count>0) //{ // foreach (var item in templist) // ScanList.Remove(item); //} } } catch (Exception ex) { db.Rollback(); errorinfo = ex.Message.ToString(); } finally { if (db != null) db.Close(); } } private int ProcessBlock(ScanBlock sendentity, ref string errorinfo) { IDatabase db = null; try { loger.LogError($"机台【{sendentity.MacCode}】开始执行调程任务:{sendentity.ScanStr}"); //调程 db = DbFactory.Base("eap"); //db.BeginTrans(); string scanstr = sendentity.ScanStr.Replace('\r', ' ').Trim(); if (CurrMac.MacModelFCode.Trim().ToLower() == "dad3350") { loger.LogError($"开始处理dad3350调程,以文件的方式,{scanstr}"); FilesProgramDal filedal = new FilesProgramDal(db); int result = filedal.DownloadProgram(CurrMac.MacFCode, scanstr, ref errorinfo); if (result <= 0) { loger.LogError($"文件方式调程失败,{scanstr}:{errorinfo}"); } loger.LogError($"文件方式调程成功。{scanstr}"); return result; } ProgramDal dal = new ProgramDal(db,loger); return dal.DownloadProgram(CurrMac.MacFCode, scanstr, ref errorinfo); //int result = 0; //string condition = $" and a.id={CurrMac.MacID}"; //List macs = db.FindListForCondition(condition, ref errorinfo).ToList(); //if(macs==null||macs.Count<=0) //{ // errorinfo = "未找到机台信息。"; // return -1; //} //switch (CurrMac.MacModelFCode.ToLower()) //{ // case "dad3350": // case "dfd6341": // Dad3350ProgramDal dal = new Dad3350ProgramDal(db); // result = dal.DownloadProgram(macs[0], scanstr, ref errorinfo); // break; // case "bg": // BgProgramDal bgdal = new BgProgramDal(db); // result = bgdal.DownloadProgram(macs[0], scanstr, ref errorinfo); // break; // case "ad838": // AsmProgramDal asmdal = new AsmProgramDal(db); // result = asmdal.DownloadProgram(macs[0], scanstr, ref errorinfo); // break; //} //if (result < 0) //{ // db.Rollback(); // MacOrderSendDal senddal = new MacOrderSendDal(db); // string temperrorinfo = ""; // senddal.SendS10F3(CurrMac.MacFCode, $"Download recipe[{scanstr}] faile", ref temperrorinfo); // return -1; //} //db.Commit(); //return 1; } catch (Exception ex) { db.Rollback(); errorinfo = ex.Message.ToString(); return -1; } finally { if (db != null) db.Close(); } } private string GetLogFile(string code, ref string errorinfo) { try { //每天1个日志 CurrFileDir= AppConfigurtaionServices.Configuration["ScanLogDir"]; string sFilePath = CurrFileDir + "\\log" + DateTime.Now.ToString("yyyyMMdd"); string sFileName = code + ".log"; sFileName = sFilePath + "\\" + sFileName; //文件的绝对路径 if (!Directory.Exists(sFilePath))//验证路径是否存在 { Directory.CreateDirectory(sFilePath); //不存在则创建 } return sFileName; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return ""; } } //将日志写到消息队列中 //private int WriteLogToQueue(ScanBlock orgblock, ref string errorinfo) //{ // try // { // //byte[] queuedata = EntityHelper.SerializeBytes(orgblock); // //if (queuedata == null) // // return -1; // //CurrQueueChannel.QueueDeclare(CurrLogQueueName, false, false, false, null);//创建一个名称为hello的消息队列 // //CurrQueueChannel.BasicPublish("", CurrLogQueueName, null, queuedata); //开始传递 // //本地写日志 // string filename = GetLogFile(CurrMac.MacFCode, ref errorinfo); // if (filename == "") // return -1; // string logstr = $"发生时间:{orgblock.OccurTime.Value.ToString("yyyy-MM-dd HH:mm:ss.fff")} 机台编号:{CurrMac.MacFCode} "; // FileStream fs; // StreamWriter sw; // if (File.Exists(filename)) // { // //验证文件是否存在,有则追加,无则创建 // fs = new FileStream(filename, FileMode.Append, FileAccess.Write); // } // else // { // fs = new FileStream(filename, FileMode.Create, FileAccess.Write); // } // sw = new StreamWriter(fs); // sw.WriteLine(logstr); // sw.WriteLine($"扫描信息:{orgblock.ScanStr}"); // sw.WriteLine($"备注:{orgblock.Remark}"); // sw.Close(); // fs.Close(); // return 1; // } // catch (Exception ex) // { // errorinfo = ex.Message.ToString(); // return -1; // } //} private int WriteLogToQueue(string log, ref string errorinfo) { try { loger.LogError($"机台编号={CurrMac.MacFCode},{log}"); ////byte[] queuedata = EntityHelper.SerializeBytes(orgblock); ////if (queuedata == null) //// return -1; ////CurrQueueChannel.QueueDeclare(CurrLogQueueName, false, false, false, null);//创建一个名称为hello的消息队列 ////CurrQueueChannel.BasicPublish("", CurrLogQueueName, null, queuedata); //开始传递 ////本地写日志 //string filename = GetLogFile(CurrMac.MacFCode, ref errorinfo); //if (filename == "") // return -1; //string logstr = $"发生时间:{DateTime.Now} 机台编号:{CurrMac.MacFCode} "; //FileStream fs; //StreamWriter sw; //if (File.Exists(filename)) //{ // //验证文件是否存在,有则追加,无则创建 // fs = new FileStream(filename, FileMode.Append, FileAccess.Write); //} //else //{ // fs = new FileStream(filename, FileMode.Create, FileAccess.Write); //} //sw = new StreamWriter(fs); //sw.WriteLine(logstr); //sw.WriteLine($"{log}"); //sw.Close(); //fs.Close(); return 1; } catch (Exception ex) { errorinfo = ex.Message.ToString(); return -1; } } //接受数据并处理 private ScanBlock ReceiveBlock(ref string errorinfo) { try { ScanBlock blocknode = CurrHsms.ReceiveForBlock(ref errorinfo); if (blocknode == null) { errorinfo = $"接受数据发生异常:{errorinfo}"; return null; } blocknode.MacCode = CurrMac.MacFCode; //写入日志 int result = WriteLogToQueue($"机台={CurrMac.MacFCode}接受到扫码指令:{blocknode.ScanStr}", ref errorinfo); if (result <= 0) { return null; } return blocknode; } catch (Exception ex) { errorinfo = "ReceiveBlock 出现异常:" + ex.ToString(); return null; } } //初始化发送数据链表 private int InitCurrSendList(ref string errorinfo) { //lock (CurrSendList) //{ // try // { // //清空链表 // CurrSendList.Clear(); // return 1; // } // catch (Exception ex) // { // errorinfo = ex.Message.ToString(); // return -1; // } //} return 1; } } }