HotDeliveryDataCollectionControl.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using Common;
  2. using Common.vo.pb;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Threading;
  8. namespace MeterPlugInLibrary
  9. {
  10. public delegate void EventHotDeliveryDataCollection(object o, List<CollectModel> e);
  11. public class HotDeliveryDataCollectionControl
  12. {
  13. public event EventHotDeliveryDataCollection EventHotDeliveryDataCollectionArgs;//定义事件
  14. private Thread CollectionThread;//采集线程
  15. private string[] strPntNo = null;//计量点编号CAR40,CAR41,CAR42,CAR43,CAR44,CAR45
  16. /// <summary>
  17. /// 开启数据采集线程
  18. /// </summary>
  19. public void Start(params string[] strPntID)
  20. {
  21. this.strPntNo = strPntID;
  22. CollectionThread = new Thread(new ThreadStart(WgtThread));
  23. CollectionThread.Start();
  24. }
  25. public void Stop()
  26. {
  27. if (CollectionThread != null)
  28. {
  29. CollectionThread.Abort();
  30. CollectionThread = null;
  31. }
  32. }
  33. /// <summary>
  34. /// 重量采集线程
  35. /// </summary>
  36. private void WgtThread()
  37. {
  38. MemoryTableDataSocket MemoClass = new MemoryTableDataSocket("", AppConfigCache.icoredbTcp);//内存表
  39. //MemoryTableDataSocket MemoClass = new MemoryTableDataSocket("", "tarantool://guest@172.22.42.3:2101");//内存表
  40. while (true)
  41. {
  42. try
  43. {
  44. Thread.Sleep(500);
  45. List<CollectModel> larg = new List<CollectModel>();
  46. List<JArray> lj = MemoClass.TrackTableList(strPntNo);//热送磅采集
  47. //WriteThreadLog("数据采集线执行跟踪!");//2021年3月16日 杨秀东添加
  48. if (lj != null) //正常采集,若为null则重量采集线程中断了
  49. {
  50. foreach (JArray jArray in lj)
  51. {
  52. CollectModel arg = new CollectModel();
  53. arg.pointid = jArray[0].ToString(); //计量点的编号:CAR41
  54. arg.weight = Convert.ToInt32(jArray[3].ToString());
  55. arg.weightStatus = Convert.ToInt32(jArray[4].ToString());
  56. arg.parkStatus = Convert.ToInt32(jArray[5].ToString());
  57. arg.datetime = Convert.ToDateTime(jArray[6].ToString().Replace("T", " ").Replace("Z", ""));
  58. arg.licType = Convert.ToInt32(jArray[7].ToString());
  59. if (arg.licType == 0) //抓拍摄像头的数据
  60. {
  61. arg.carno = jArray[2].ToString();
  62. }
  63. else
  64. {
  65. arg.carno = jArray[8].ToString();
  66. }
  67. larg.Add(arg);
  68. }
  69. }
  70. EventHotDeliveryDataCollectionArgs(this, larg); //赋值给主页面调用
  71. }
  72. catch (Exception exp)
  73. {
  74. WriteThreadLog("数据采集线程异常!" + exp.Message);
  75. }
  76. }
  77. }
  78. public void WriteLog(string str)
  79. {
  80. try
  81. {
  82. string m_szRunPath;
  83. m_szRunPath = System.Environment.CurrentDirectory;
  84. if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
  85. {
  86. System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
  87. }
  88. string strDate = System.DateTime.Now.ToString("yyyyMMdd");
  89. string strPathFile = m_szRunPath + "\\log\\" + strDate;
  90. if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
  91. {
  92. Directory.CreateDirectory(strPathFile);
  93. }
  94. System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\数据采集_" + strDate + ".log", true);
  95. tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  96. tw.WriteLine(str);
  97. tw.WriteLine("\r\n");
  98. tw.Close();
  99. }
  100. catch (Exception exp)
  101. {
  102. }
  103. }
  104. /// <summary>
  105. /// 写线程日志
  106. /// </summary>
  107. /// <param name="str"></param>
  108. public void WriteThreadLog(string str)
  109. {
  110. try
  111. {
  112. string m_szRunPath;
  113. m_szRunPath = System.Environment.CurrentDirectory;
  114. if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
  115. {
  116. System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
  117. }
  118. string strDate = System.DateTime.Now.ToString("yyyyMMdd");
  119. string strPathFile = m_szRunPath + "\\log\\" + strDate;
  120. if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
  121. {
  122. Directory.CreateDirectory(strPathFile);
  123. }
  124. System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\数据采集线程_" + strDate + ".log", true);
  125. tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  126. tw.WriteLine(str);
  127. tw.WriteLine("\r\n");
  128. tw.Close();
  129. }
  130. catch (Exception exp)
  131. {
  132. }
  133. }
  134. public void WriteLogUpCardNo(string str)
  135. {
  136. try
  137. {
  138. string m_szRunPath;
  139. m_szRunPath = System.Environment.CurrentDirectory;
  140. if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
  141. {
  142. System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
  143. }
  144. string strDate = System.DateTime.Now.ToString("yyyyMMdd");
  145. string strPathFile = m_szRunPath + "\\log\\" + strDate;
  146. if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
  147. {
  148. Directory.CreateDirectory(strPathFile);
  149. }
  150. System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\修正车号_" + strDate + ".log", true);
  151. tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  152. tw.WriteLine(str);
  153. tw.WriteLine("\r\n");
  154. tw.Close();
  155. }
  156. catch (Exception exp)
  157. {
  158. }
  159. }
  160. public void WriteLogStatus(string str)
  161. {
  162. try
  163. {
  164. string m_szRunPath;
  165. m_szRunPath = System.Environment.CurrentDirectory;
  166. if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
  167. {
  168. System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
  169. }
  170. string strDate = System.DateTime.Now.ToString("yyyyMMdd");
  171. string strPathFile = m_szRunPath + "\\log\\" + strDate;
  172. if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
  173. {
  174. Directory.CreateDirectory(strPathFile);
  175. }
  176. System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\重量稳定判断_" + strDate + ".log", true);
  177. tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  178. tw.WriteLine(str);
  179. tw.WriteLine("\r\n");
  180. tw.Close();
  181. }
  182. catch (Exception exp)
  183. {
  184. }
  185. }
  186. }
  187. }