| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- using Common;
- using Common.vo.pb;
- using MeterModelLibrary;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace MeterPlugInLibrary
- {
- public delegate void EventDataCollection(object o, DataCollectionArgs e);
- public class DataCollectionArgs
- {
- public string carno { get; set; }//车号
- public string carnoAlert { get; set; } //双车号识别类型 0:都识别且一致 1:只有一个识别 2:都识别但不一致 3:都不识别
- public int weight { get; set; }//重量
- public int weightStatus { get; set; }//0稳定,1不稳定,2空磅
- public int parkStatus { get; set; }//红外对射 0未挡住,1:车头压线 2:车尾压线 3:两头压线; 记录在重量稳定后生成
- public int licType { get; set; }//0 抓拍 1 RFID
- public DateTime datetime { get; set; } //当前时间的距离1970.1.1.08:00时间的秒数
- public string vdioCarNos { get; set; }
- public string RfidNos { get; set; }
- public string videoCarNo1 { get; set; }
- public string videoCarNo2 { get; set; }
- }
- public class DataCollectionControl
- {
- public event EventDataCollection EventDataCollectionArgs;//定义事件
- private Thread CollectionThread;//采集线程
- private string strPntNo = "";//计量点编号
- private string strPntName = "";//计量点编号
- /// <summary>
- /// 开启数据采集线程
- /// </summary>
- public void Start(string strPntID, string strPntName)
- {
- PbCache.collect = new CollectModel();
- this.strPntNo = strPntID;
- this.strPntName = strPntName;
- CollectionThread = new Thread(new ThreadStart(WgtThread));
- CollectionThread.Start();
- }
- public void Stop()
- {
- if (CollectionThread != null)
- {
- CollectionThread.Abort();
- CollectionThread = null;
- }
- }
- /// <summary>
- /// 重量采集线程
- /// </summary>
- private void WgtThread()
- {
- //===========eason 2020 注释================
- int icount = 0, iOldWgt = 0, iWdCount = 0; //iWdCount稳定次数,这里判断为5次稳定即可
- MemoryTableDataSocket MemoClass = new MemoryTableDataSocket(PbCache.collect_no);//内存表
- //CarNoModfiy carNoModifyClass = new CarNoModfiy();//车号修正
- while (true)
- {
- try
- {
- icount++;
- Thread.Sleep(500);
- DataCollectionArgs arg = new DataCollectionArgs();
- //WriteThreadLog("数据采集线执行跟踪!");//2021年3月16日 杨秀东添加
- JArray jArray = MemoClass.TrackTable(PbCache.collect_no);
- if (jArray != null) //正常采集,若为null则重量采集线程中断了
- {
- //arg.carno = jArray[2].ToString();
- arg.weight = Convert.ToInt32(jArray[3].ToString());
- arg.weightStatus = Convert.ToInt32(jArray[4].ToString());
- arg.parkStatus = Convert.ToInt32(jArray[5].ToString());
- arg.datetime = Convert.ToDateTime(jArray[6].ToString().Replace("T", " ").Replace("Z", ""));
- arg.licType = Convert.ToInt32(jArray[7].ToString());
- //if (jArray[2].ToString() != "" || jArray[8].ToString() != "" || jArray[14].ToString() != "")
- //{
- WriteThreadLog("jArray:"+jArray.ToString());
- //}
- // 20221011 By BourneCao
- // 增加双摄像头支持
- // 1. 获取双摄像头车号
- string carNo1 = jArray[8].ToString();
- string carNo2 = jArray[14].ToString();
- if (carNo1.Contains("挂")) carNo1 = "";
- if (carNo2.Contains("挂")) carNo2 = "";
- arg.videoCarNo1 = carNo1;
- arg.videoCarNo2 = carNo2;
- if (arg.licType == 0) //摄像头的数据
- {
- //arg.carno = jArray[2].ToString();
- // 2. 判断逻辑:
- // a.A车号识别,B车号不识别;B车号识别,A车号不识别,正常计量,标记只有1个车号识别
- if (carNo1 != "" && carNo2 == "")
- {
- arg.carno = carNo1;
- arg.carnoAlert = "1";
- }
- else if (carNo2 != "" && carNo1 == "")
- {
- arg.carno = carNo2;
- arg.carnoAlert = "1";
- }
- // b.A车号识别,B车号识别,且识别一致,正常计量
- else if (carNo1 != "" && carNo2 != "" && carNo1 == carNo2)
- {
- arg.carno = carNo1;
- arg.carnoAlert = "0";
- }
- // c.A车号识别,B车号识别,且识别不一致,停止计量,标记只有车号不一致识别
- // c.A车号识别,B车号识别,且识别不一致,以枪机为准。张存斌、李亚军批准 By BourneCao 20221214
- else if (carNo1 != "" && carNo2 != "" && carNo1 != carNo2)
- {
- arg.carno = carNo2;
- arg.carnoAlert = "1";
- }
- // d.都不识别
- else
- {
- arg.carno = "";
- arg.carnoAlert = "3";
- }
-
- }
- else
- {
- arg.carno = jArray[8].ToString();
- }
- arg.vdioCarNos = arg.carno; //jArray[8].ToString();
- arg.RfidNos = jArray[9].ToString();
- #region 判稳代码
- /*
- if (PbCache.range != null)
- {
- if (PbCache.range.stableDiff != null)
- {
- if (Math.Abs(arg.weight - iOldWgt) > PbCache.range.stableDiff.Value)
- {
- iOldWgt = arg.weight;
- iWdCount = 0;
- }
- else
- {
- arg.weight = iOldWgt;
- iWdCount++;
- }
- }
- }
- if (arg.weightStatus == 2)
- {
- arg.weightStatus = 0; //重量稳定
- iWdCount = 0;
- }
- //0.1秒采集一次,一共采集5次,若稳定则认为重量稳定
- if (iWdCount >= 10)
- {
- arg.weightStatus = 0; //重量稳定
- iWdCount = 10;
- }
- //*/
- #endregion
- }
- //每隔0.5秒调用一次写入到界面数据
- //if (icount > 4)
- {
- icount = 0;
- // 将数据提交移出数据采集线程
- // 避免HTTP数据提交影响到数据采集的刷新
- // By BourneCao 20220811
- EventDataCollectionArgs(this, arg);
- }
- }
- catch (Exception exp)
- {
- WriteThreadLog("数据采集线程异常!" + exp.Message);
- }
- }
- }
- public void WriteLog(string str)
- {
- try
- {
- string m_szRunPath;
- m_szRunPath = System.Environment.CurrentDirectory;
- if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
- {
- System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
- }
- string strDate = System.DateTime.Now.ToString("yyyyMMdd");
- string strPathFile = m_szRunPath + "\\log\\" + strDate;
- if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
- {
- Directory.CreateDirectory(strPathFile);
- }
- System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\数据采集_" + strDate + ".log", true);
- tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- tw.WriteLine(str);
- tw.WriteLine("\r\n");
- tw.Close();
- }
- catch (Exception exp)
- {
- }
- }
- /// <summary>
- /// 写线程日志
- /// </summary>
- /// <param name="str"></param>
- public void WriteThreadLog(string str)
- {
- try
- {
- string m_szRunPath;
- m_szRunPath = System.Environment.CurrentDirectory;
- if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
- {
- System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
- }
- string strDate = System.DateTime.Now.ToString("yyyyMMdd");
- string strPathFile = m_szRunPath + "\\log\\" + strDate;
- if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
- {
- Directory.CreateDirectory(strPathFile);
- }
- System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\数据采集线程_" + strDate + ".log", true);
- tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- tw.WriteLine(str);
- tw.WriteLine("\r\n");
- tw.Close();
- }
- catch (Exception exp)
- {
- }
- }
- public void WriteLogUpCardNo(string str)
- {
- try
- {
- string m_szRunPath;
- m_szRunPath = System.Environment.CurrentDirectory;
- if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
- {
- System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
- }
- string strDate = System.DateTime.Now.ToString("yyyyMMdd");
- string strPathFile = m_szRunPath + "\\log\\" + strDate;
- if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
- {
- Directory.CreateDirectory(strPathFile);
- }
- System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\修正车号_" + strDate + ".log", true);
- tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- tw.WriteLine(str);
- tw.WriteLine("\r\n");
- tw.Close();
- }
- catch (Exception exp)
- {
- }
- }
- public void WriteLogStatus(string str)
- {
- try
- {
- string m_szRunPath;
- m_szRunPath = System.Environment.CurrentDirectory;
- if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
- {
- System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
- }
- string strDate = System.DateTime.Now.ToString("yyyyMMdd");
- string strPathFile = m_szRunPath + "\\log\\" + strDate;
- if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
- {
- Directory.CreateDirectory(strPathFile);
- }
- System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\重量稳定判断_" + strDate + ".log", true);
- tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- tw.WriteLine(str);
- tw.WriteLine("\r\n");
- tw.Close();
- }
- catch (Exception exp)
- {
- }
- }
- }
- }
|