DataCollectionArgs.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using Core.StlMes.Client.LgResMgt.Mcms.entity;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. namespace Core.StlMes.Client.LgResMgt.Mcms
  10. {
  11. public delegate void EventDataCollection(object o, DataCollectionArgs e);
  12. public class DataCollectionArgs
  13. {
  14. public string carno { get; set; }//车号
  15. public int weight { get; set; }//重量
  16. public int weightStatus { get; set; }//0稳定,1不稳定,2空磅
  17. public int parkStatus { get; set; }//红外对射 0未挡住,1:车头压线 2:车尾压线 3:两头压线; 记录在重量稳定后生成
  18. public int licType { get; set; }//0 抓拍 1 RFID
  19. public DateTime datetime { get; set; } //当前时间的距离1970.1.1.08:00时间的秒数
  20. public string vdioCarNos { get; set; }
  21. public string RfidNos { get; set; }
  22. }
  23. public class DataCollectionControl
  24. {
  25. public event EventDataCollection EventDataCollectionArgs;//定义事件
  26. private Thread CollectionThread;//采集线程
  27. private string strPntNo = "";//计量点编号
  28. private string strPntName = "";//计量点编号
  29. /// <summary>
  30. /// 开启数据采集线程
  31. /// </summary>
  32. public void Start(string strPntID, string strPntName)
  33. {
  34. PbCache.collect = new CmmMonitorWeightEntity();
  35. this.strPntNo = strPntID;
  36. this.strPntName = strPntName;
  37. CollectionThread = new Thread(new ThreadStart(WgtThread));
  38. CollectionThread.Start();
  39. }
  40. public void Stop()
  41. {
  42. if (CollectionThread != null)
  43. {
  44. CollectionThread.Abort();
  45. CollectionThread = null;
  46. }
  47. }
  48. /// <summary>
  49. /// 重量采集线程
  50. /// </summary>
  51. private void WgtThread()
  52. {
  53. //===========eason 2020 注释================
  54. //int icount = 0, iOldWgt = 0, iWdCount = 0; //iWdCount稳定次数,这里判断为5次稳定即可
  55. // MemoryTableDataSocket MemoClass = new MemoryTableDataSocket(PbCache.collect_no);//内存表
  56. //CarNoModfiy carNoModifyClass = new CarNoModfiy();//车号修正
  57. while (true)
  58. {
  59. // try
  60. // {
  61. // Thread.Sleep(500);
  62. // DataCollectionArgs arg = new DataCollectionArgs();
  63. // //*************************Eason add 2021-08-12*****************
  64. // if (AppConfigCache.productType == "0")
  65. // {
  66. // arg.weight = 0;
  67. // arg.weightStatus = 0;
  68. // arg.parkStatus = 0;
  69. // arg.datetime = DateTime.Now;
  70. // arg.licType = 0;
  71. // }
  72. // else
  73. // {
  74. // //**************************end************************************
  75. // WriteThreadLog("数据采集线执行跟踪!");//2021年3月16日 杨秀东添加
  76. // JArray jArray = MemoClass.TrackTable(PbCache.collect_no);
  77. // if (jArray != null) //正常采集,若为null则重量采集线程中断了
  78. // {
  79. // //arg.carno = jArray[2].ToString();
  80. // arg.weight = Convert.ToInt32(jArray[3].ToString());
  81. // arg.weightStatus = Convert.ToInt32(jArray[4].ToString());
  82. // arg.parkStatus = Convert.ToInt32(jArray[5].ToString());
  83. // arg.datetime = Convert.ToDateTime(jArray[6].ToString().Replace("T", " ").Replace("Z", ""));
  84. // arg.licType = Convert.ToInt32(jArray[7].ToString());
  85. // if (arg.licType == 0) //摄像头的数据
  86. // {
  87. // arg.carno = jArray[2].ToString();
  88. // }
  89. // else
  90. // {
  91. // arg.carno = jArray[8].ToString();
  92. // }
  93. // arg.vdioCarNos = arg.carno; //jArray[8].ToString();
  94. // arg.RfidNos = jArray[9].ToString();
  95. // }
  96. // }
  97. // EventDataCollectionArgs(this, arg);
  98. // }
  99. // catch (Exception exp)
  100. // {
  101. // WriteThreadLog("数据采集线程异常!" + exp.Message);
  102. // }
  103. }
  104. }
  105. public void WriteLog(string str)
  106. {
  107. try
  108. {
  109. string m_szRunPath;
  110. m_szRunPath = System.Environment.CurrentDirectory;
  111. if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
  112. {
  113. System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
  114. }
  115. string strDate = System.DateTime.Now.ToString("yyyyMMdd");
  116. string strPathFile = m_szRunPath + "\\log\\" + strDate;
  117. if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
  118. {
  119. Directory.CreateDirectory(strPathFile);
  120. }
  121. System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\数据采集_" + strDate + ".log", true);
  122. tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  123. tw.WriteLine(str);
  124. tw.WriteLine("\r\n");
  125. tw.Close();
  126. }
  127. catch (Exception exp)
  128. {
  129. }
  130. }
  131. /// <summary>
  132. /// 写线程日志
  133. /// </summary>
  134. /// <param name="str"></param>
  135. public void WriteThreadLog(string str)
  136. {
  137. try
  138. {
  139. string m_szRunPath;
  140. m_szRunPath = System.Environment.CurrentDirectory;
  141. if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
  142. {
  143. System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
  144. }
  145. string strDate = System.DateTime.Now.ToString("yyyyMMdd");
  146. string strPathFile = m_szRunPath + "\\log\\" + strDate;
  147. if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
  148. {
  149. Directory.CreateDirectory(strPathFile);
  150. }
  151. System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\数据采集线程_" + strDate + ".log", true);
  152. tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  153. tw.WriteLine(str);
  154. tw.WriteLine("\r\n");
  155. tw.Close();
  156. }
  157. catch (Exception exp)
  158. {
  159. }
  160. }
  161. public void WriteLogUpCardNo(string str)
  162. {
  163. try
  164. {
  165. string m_szRunPath;
  166. m_szRunPath = System.Environment.CurrentDirectory;
  167. if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
  168. {
  169. System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
  170. }
  171. string strDate = System.DateTime.Now.ToString("yyyyMMdd");
  172. string strPathFile = m_szRunPath + "\\log\\" + strDate;
  173. if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
  174. {
  175. Directory.CreateDirectory(strPathFile);
  176. }
  177. System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\修正车号_" + strDate + ".log", true);
  178. tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  179. tw.WriteLine(str);
  180. tw.WriteLine("\r\n");
  181. tw.Close();
  182. }
  183. catch (Exception exp)
  184. {
  185. }
  186. }
  187. public void WriteLogStatus(string str)
  188. {
  189. try
  190. {
  191. string m_szRunPath;
  192. m_szRunPath = System.Environment.CurrentDirectory;
  193. if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
  194. {
  195. System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
  196. }
  197. string strDate = System.DateTime.Now.ToString("yyyyMMdd");
  198. string strPathFile = m_szRunPath + "\\log\\" + strDate;
  199. if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
  200. {
  201. Directory.CreateDirectory(strPathFile);
  202. }
  203. System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\重量稳定判断_" + strDate + ".log", true);
  204. tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  205. tw.WriteLine(str);
  206. tw.WriteLine("\r\n");
  207. tw.Close();
  208. }
  209. catch (Exception exp)
  210. {
  211. }
  212. }
  213. }
  214. }