Titration2Execute.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. using System.Diagnostics;
  2. using shjxCamera;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.Runtime.Intrinsics.Arm;
  6. namespace SHJX.Service.Control.Execute.TitrationController
  7. {
  8. public class Titration2Execute
  9. {
  10. private static readonly ILogger logger = LogFactory.BuildLogger(typeof(Titration2Execute));
  11. public static bool Running = true;
  12. private static int titrationCount = 0;
  13. private static int slowSpeedCount = 0;
  14. private static int signalTimeLen = 10;
  15. private static int arriveRangeCount = 0; //突跃次数
  16. private static List<ColorData2Point> currSignals = new(); // 信号队列
  17. private static List<ColorData2Point> currSignalsCompare = new(); // 信号队列
  18. private static ColorData2Graber _graber = Globals.Graber2;
  19. private static double balanceVal = 0;
  20. private static bool IsClean = true;
  21. private static readonly string titrationCamera = "D2_camera";
  22. /// <summary>
  23. /// 滴定
  24. /// </summary>
  25. /// <param name="rangeValue">阈值</param>
  26. /// <param name="amount">体积</param>
  27. public static void Start(Titration2Arg arg, ref double amount)
  28. {
  29. Messager<object>.Send("TitrationStart2");
  30. if (Globals.Camera2 is null)
  31. {
  32. logger.LogDebug("2222222未找到摄像头,无法进行滴定操作");
  33. return;
  34. }
  35. int threshold_gray = 5; // 色点过滤阈值
  36. int threshold_hue = (int)arg.RangeValue; // 色相偏移阈值
  37. int threshold_stable_check = arg.ArriveCheckCount; // 稳定检测时长
  38. // string taskTag = $"{arg.BatchName}/{arg.TaskName}";
  39. //Directory.CreateDirectory($"Data/{taskTag}");
  40. //var csvWriter = new StreamWriter($"Data/{taskTag}.csv");
  41. //csvWriter.Write("滴数,体积,红,绿,蓝,灰度,色调,饱和度,亮度\n");
  42. //csvWriter.Flush();
  43. // 滴定
  44. int titrationCount = 0;
  45. List<ColorPoint> samplePoints = []; // 采样点
  46. logger.LogCritical($"<22222222> 滴定开始(色相偏移阈值: {threshold_hue,2}, 稳定检测时长: {threshold_stable_check})");
  47. // 快速滴定(一般用于标定)
  48. if (arg.WhetherQuicklyTitration)
  49. {
  50. bool quicklyTitrationRes = LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).CheckWhetherArriveEndPoint().Execute(Convert.ToInt32(Math.Round(arg.QuicklyTitrationValue / arg.LiquidAmount * arg.LiquidConvertRatio)));
  51. if (quicklyTitrationRes)
  52. {
  53. amount += arg.QuicklyTitrationValue;
  54. logger.LogCritical("22222222快速滴定下发成功,等待15秒后继续滴定操作!");
  55. Thread.Sleep(5 * 1000);
  56. }
  57. }
  58. //if (!ConfigInstance.IsAutomaticInLiquid)//滴定1有自动吸液,滴定2无自动吸液
  59. // //{
  60. int distance = Convert.ToInt32(Math.Round(arg.PumpCapacity / arg.LiquidAmount * arg.LiquidConvertRatio));
  61. LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).CheckWhetherArriveEndPoint().Execute(LiquidSwitchPattern.In, distance);
  62. // //}
  63. // 滴定前等待
  64. logger.LogCritical($"<22222222> 滴定前等待({arg.BeforeWaitTime}s)");
  65. Thread.Sleep(arg.BeforeWaitTime * 1000);
  66. // 第0滴颜色采样(背景采样)
  67. ColorPoint cp = Globals.Camera2.SampleBackground(titrationCamera, threshold_gray, threshold_hue);
  68. if (cp.Hue < 10)
  69. {
  70. Messager<object>.Send("TitrationStop2");
  71. logger.LogCritical($"<22222222> 采集信号有误,退出滴定"); return; }
  72. logger.LogCritical($"<22222222> 第{titrationCount:D3}滴({amount:F3}), HSB({cp.Hue,3},{cp.Saturation:F3},{cp.Brightness:F3}), RGBL({cp.R,3},{cp.G,3},{cp.B,3},{cp.Gray,3})");
  73. //csvWriter.Write($"{titrationCount:D3},{amount:F3},{cp.R,3},{cp.G,3},{cp.B,3},{cp.Gray,3},{cp.Hue,3},{cp.Saturation:F3},{cp.Brightness:F3}\n");
  74. //csvWriter.Flush();
  75. samplePoints.Add(cp);
  76. Messager<Titration2ValueArgs>.Send("Titration2ValueChange", new Titration2ValueArgs(titrationCount, amount, cp.Hue));
  77. Messager<object>.Send("GraberColorValue2", cp.Hue);
  78. while (true)
  79. {
  80. // 达到最大滴定体积,结束滴定
  81. if (amount >= arg.MaxDropVolume)
  82. {
  83. logger.LogCritical($"<2222222> 滴定结束(最大滴定量)");
  84. break;
  85. }
  86. bool arriveEndPoint = LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).IsArriveEndPoint;
  87. if (arriveEndPoint)
  88. {
  89. distance = Convert.ToInt32(Math.Round(arg.PumpCapacity / arg.LiquidAmount * arg.LiquidConvertRatio));
  90. LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).Execute(LiquidSwitchPattern.In, distance);
  91. }
  92. LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).Execute(LiquidSwitchPattern.Out, arg.LiquidConvertRatio);
  93. titrationCount += 1;
  94. amount += arg.LiquidAmount;
  95. // 第N滴颜色采样
  96. Thread.Sleep(1000);
  97. cp = Globals.Camera2.Sample( $"22222222/{titrationCount:D3}S", threshold_gray, threshold_hue);
  98. //csvWriter.Write($"{titrationCount:D3},{amount:F3},{cp.R,3},{cp.G,3},{cp.B,3},{cp.Gray,3},{cp.Hue,3},{cp.Saturation:F3},{cp.Brightness:F3}\n");
  99. //csvWriter.Flush();
  100. samplePoints.Add(cp);
  101. logger.LogCritical($"<22222222> 第{titrationCount:D3}滴({amount:F3}), HSB({cp.Hue,3},{cp.Saturation:F3},{cp.Brightness:F3}), RGBL({cp.R,3},{cp.G,3},{cp.B,3},{cp.Gray,3})");
  102. //Application.Current.Dispatcher.BeginInvoke(delegate ()
  103. //{
  104. // ChartHelper.SaveGraph(samplePoints, taskTag);
  105. //});
  106. Messager<Titration2ValueArgs>.Send("Titration2ValueChange", new Titration2ValueArgs(titrationCount, amount, cp.Hue));
  107. Messager<object>.Send("GraberColorValue2", cp.Hue);
  108. if (ColorPoint.HueDiff(samplePoints.First(), samplePoints.Last()) < threshold_hue)
  109. {
  110. continue;
  111. }
  112. // 稳定判断: 达到阈值设定,进入稳定(褪色)检测
  113. logger.LogCritical($"<22222222> 稳定检测(开始)");
  114. bool stable = false;
  115. int chkCnt = 0;
  116. int retCnt = 0;
  117. Stopwatch sw = new();
  118. sw.Start();
  119. while (true)
  120. {
  121. // 到达稳定检测截止时限,完成检测
  122. if (sw.ElapsedMilliseconds / 1000 >= threshold_stable_check)
  123. {
  124. logger.LogCritical($"22222222 稳定检测(完成)");
  125. sw.Stop();
  126. stable = true;
  127. break;
  128. }
  129. // 第N滴第i次稳定检测颜色采样
  130. chkCnt++;
  131. Thread.Sleep(1000);
  132. cp = Globals.Camera2.Sample( $"22222222/{titrationCount:D3}T-{chkCnt:D2}", threshold_gray, threshold_hue);
  133. //csvWriter.Write($"{titrationCount:D3},{amount:F3},{cp.R,3},{cp.G,3},{cp.B,3},{cp.Gray,3},{cp.Hue,3},{cp.Saturation:F3},{cp.Brightness:F3}\n");
  134. //csvWriter.Flush();
  135. samplePoints.Add(cp);
  136. logger.LogCritical($"22222222 稳定检测({chkCnt:D2}), HSB({cp.Hue,3},{cp.Saturation:F3},{cp.Brightness:F3}), RGBL({cp.R,3},{cp.G,3},{cp.B,3},{cp.Gray,3})");
  137. Messager<Titration2ValueArgs>.Send("Titration2ValueChange", new Titration2ValueArgs(titrationCount, amount, cp.Hue));
  138. Messager<object>.Send("GraberColorValue2", cp.Hue);
  139. if (ColorPoint.HueDiff(samplePoints.First(), samplePoints.Last()) < threshold_hue)
  140. {
  141. if (retCnt == 0)
  142. {
  143. retCnt++;
  144. continue;
  145. }
  146. logger.LogCritical($"22222222 稳定检测(中止)");
  147. break;
  148. }
  149. else
  150. retCnt = 0;
  151. }
  152. // 稳定检测通过,滴定完成
  153. if (stable)
  154. {
  155. logger.LogCritical($"22222222滴定结束(共{titrationCount:D3}滴, {amount:F3}ml)");
  156. break;
  157. }
  158. }
  159. //csvWriter.Close();
  160. // 保存图表
  161. //string chartTitle = $"{taskTag} ({amount:F3}ml)";
  162. //Application.Current.Dispatcher.BeginInvoke(delegate ()
  163. //{
  164. // ChartHelper.SaveGraph(samplePoints, $"{taskTag}", chartTitle);
  165. //});
  166. Messager<object>.Send("TitrationStop2");
  167. logger.LogCritical($"******************************22222222滴定结束******************************");
  168. //// 保存图表
  169. //string chartTitle = $"{taskTag} ({amount:F3}ml)";
  170. //Application.Current.Dispatcher.BeginInvoke(delegate ()
  171. //{
  172. // ChartHelper.SaveGraph(samplePoints, $"{taskTag}", chartTitle);
  173. //});
  174. //Globals.EA?.GetEvent<TitrationStatusEvent>().Publish(new TitrationStatus()
  175. //{
  176. // TitrationUnit = titrationUnit,
  177. // TaskTag = taskTag,
  178. // TitrationCount = titrationCount,
  179. // TitrationVolume = (float)amount,
  180. // SamplePoints = samplePoints,
  181. // IsRunning = false
  182. //});
  183. }
  184. //try
  185. //{
  186. // Messager<object>.Send("TitrationStart2");
  187. // if (Globals.Camera2 is null)
  188. // {
  189. // logger.LogDebug("22222222未找到摄像头,无法进行滴定操作");
  190. // return;
  191. // }
  192. // Running = true;
  193. // titrationCount = 0;
  194. // slowSpeedCount = 0;
  195. // signalTimeLen = 10;
  196. // arriveRangeCount = 0; //突跃次数
  197. // currSignals = new(); // 信号队列
  198. // currSignalsCompare = new(); // 信号队列
  199. // // _graber = Globals.Graber2;
  200. // balanceVal = -1 * arg.RangeValue;
  201. // if (!Globals.Camera2.IsOpened)
  202. // {
  203. // Globals.Camera2.OpenCamera();
  204. // }
  205. // logger.LogCritical($"******************************22222222滴定开始******************************");
  206. // if (arg.WhetherQuicklyTitration) //快速滴定判断
  207. // {
  208. // bool quicklyTitrationRes = LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).CheckWhetherArriveEndPoint().Execute(Convert.ToInt32(Math.Round(arg.QuicklyTitrationValue / arg.LiquidAmount * arg.LiquidConvertRatio)));
  209. // if (quicklyTitrationRes)
  210. // {
  211. // amount += arg.QuicklyTitrationValue;
  212. // logger.LogCritical("22222222快速滴定下发成功,等待15秒后继续滴定操作!");
  213. // Thread.Sleep(5 * 1000);
  214. // }
  215. // }
  216. // Thread.Sleep(arg.BeforeWaitTime * 1000);
  217. // //if (!ConfigInstance.IsAutomaticInLiquid)//滴定1有自动吸液,滴定2无自动吸液
  218. // //{
  219. // int distance = Convert.ToInt32(Math.Round(arg.PumpCapacity / arg.LiquidAmount * arg.LiquidConvertRatio));
  220. // LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).CheckWhetherArriveEndPoint().Execute(LiquidSwitchPattern.In, distance);
  221. // //}
  222. // _graber.PresetLightParammanual(arg.explosion, 10);
  223. // _graber.PresetLightParam(-9);
  224. // Thread.Sleep(2000);
  225. // for (int i = 0; i < 7; i++) // 采集7段信号作为背景
  226. // {
  227. // currSignals.Add(_graber.GrabSignal(500));
  228. // currSignalsCompare.Add(currSignals[i]);
  229. // }
  230. // int times = 3;
  231. // while (JudgeManualTitration(currSignals))
  232. // {
  233. // if (times == 0)
  234. // {
  235. // logger.LogCritical($"*******************22222222检测到异常样本!请尝试手工滴定*******************");
  236. // return;
  237. // }
  238. // _graber.PresetLightParammanual(arg.explosion, 10);
  239. // _graber.PresetLightParam(-9);
  240. // Thread.Sleep(2000);
  241. // for (int i = 0; i < 7; i++) // 采集7段信号作为背景
  242. // {
  243. // currSignals[i] = _graber.GrabSignal(500);
  244. // currSignalsCompare[i] = currSignals[i];
  245. // }
  246. // times--;
  247. // }
  248. // if (IsClean)
  249. // {
  250. // logger.LogCritical($"*******************22222222干净样本滴定算法*******************");
  251. // CleanSampleTitration(arg, ref amount);
  252. // }
  253. // else
  254. // {
  255. // logger.LogCritical($"*******************22222222复杂样本滴定算法*******************");
  256. // ComplexSampleTitration(arg, ref amount);
  257. // }
  258. //}
  259. //catch (Exception ex)
  260. //{
  261. // logger.LogError($"22222222滴定异常{DateTime.Now},ErrorInfo:{ex}");
  262. //}
  263. //finally
  264. //{
  265. // Messager<object>.Send("TitrationStop2");
  266. // logger.LogCritical($"******************************22222222滴定结束******************************");
  267. //}
  268. // private static bool JudgeManualTitration(List<ColorData2Point> currSignals)
  269. // {
  270. // double max = currSignals[0].GetRSV();
  271. // double min = currSignals[0].GetRSV();
  272. // for (int i = 1; i < currSignals.Count; i++)
  273. // {
  274. // if (currSignals[i].GetRSV() > max)
  275. // max = currSignals[i].GetRSV();
  276. // if (currSignals[i].GetRSV() < min)
  277. // min = currSignals[i].GetRSV();
  278. // }
  279. // if (max - min > 2.5 || max - min == 0 || min < 110 || max > 120)
  280. // return true;
  281. // else
  282. // return false;
  283. // }
  284. // private static void CleanSampleTitration(Titration2Arg arg, ref double amount)
  285. // {
  286. // ColorData2Point subRcurrSignals = new ColorData2Point();
  287. // while (true)
  288. // {
  289. // if (currSignals.Count >= 7) // 信号判断
  290. // {
  291. // double subR = 0.0;
  292. // int currpt = currSignals.Count - 6;
  293. // subRcurrSignals = _graber.GrabSignal(signalTimeLen);
  294. // currSignalsCompare.Add(subRcurrSignals);
  295. // subR = (subRcurrSignals.GetRSV() - ((currSignals[currpt - 1].GetRSV() + currSignals[currpt].GetRSV()) / 2)) * 100 / subRcurrSignals.GetRSV();
  296. // if (subR > 0)
  297. // {
  298. // currSignals.Add(subRcurrSignals);
  299. // }
  300. // logger.LogCritical($"22222222当前第{titrationCount:D3}滴,体积:{amount:F3},阈值:{subR:F2}");
  301. // Messager<Titration2ValueArgs>.Send("Titration2ValueChange", new Titration2ValueArgs(titrationCount, amount, subR));
  302. // if (subR <= balanceVal)
  303. // {
  304. // arriveRangeCount++;
  305. // Stopwatch swten = new();
  306. // swten.Start();
  307. // int retreatCount = 1; //后退次数
  308. // int flag = 0;
  309. // while (true) //继续采集信号,监测是否褪色
  310. // {
  311. // currpt = currSignals.Count - 6;
  312. // subRcurrSignals = _graber.GrabSignal(signalTimeLen);
  313. // currSignalsCompare.Add(subRcurrSignals);
  314. // subR = (subRcurrSignals.GetRSV() - ((currSignals[currpt - 1].GetRSV() + currSignals[currpt].GetRSV()) / 2)) * 100 / subRcurrSignals.GetRSV();
  315. // if (subR > 0)
  316. // {
  317. // currSignals.Add(subRcurrSignals);
  318. // }
  319. // logger.LogCritical($"22222222已达设定阈值,观察是否褪色,阈值为:{subR}");
  320. // if (subR <= balanceVal)
  321. // {
  322. // flag = 0;
  323. // retreatCount++;
  324. // if (swten.ElapsedMilliseconds / 1000 > arg.ArriveCheckCount)
  325. // {
  326. // break;
  327. // }
  328. // Running = false;
  329. // Thread.Sleep(1000);
  330. // continue; //颜色比较红,继续观察是否到30秒
  331. // }
  332. // else if (++flag > 1)
  333. // {
  334. // Running = true;
  335. // if (retreatCount > 2)
  336. // {
  337. // slowSpeedCount = 5; //如果回退超过三次判定,则给定慢速10次
  338. // logger.LogCritical($"22222222回退超过三次,给定慢速5次");
  339. // }
  340. // break;//当检测到的信号值 大于阈值时,则滴定未结束,需要继续滴定
  341. // }
  342. // else
  343. // {
  344. // retreatCount++;
  345. // Running = false;
  346. // Thread.Sleep(1000);
  347. // continue; //颜色比较红,继续观察是否到30秒
  348. // }
  349. // }
  350. // swten.Stop();
  351. // }
  352. // else
  353. // {
  354. // arriveRangeCount = arriveRangeCount > 0 ? arriveRangeCount - 1 : 0;
  355. // slowSpeedCount = slowSpeedCount > 0 ? slowSpeedCount - 1 : slowSpeedCount;
  356. // }
  357. // if (amount >= arg.MaxDropVolume) break;
  358. // if (!Running) break;
  359. // bool arriveEndPoint = LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).IsArriveEndPoint;
  360. // if (arriveEndPoint)
  361. // {
  362. // int distance = Convert.ToInt32(Math.Round(arg.PumpCapacity / arg.LiquidAmount * arg.LiquidConvertRatio));
  363. // LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).Execute(LiquidSwitchPattern.In, distance);
  364. // }
  365. // bool res = LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).Execute(LiquidSwitchPattern.Out, arg.LiquidConvertRatio);
  366. // if (!res)
  367. // {
  368. // logger.LogError("22222222写入失败,等待两秒后再次写入");
  369. // Thread.Sleep(2000);
  370. // continue;
  371. // }
  372. // titrationCount += 1;
  373. // amount += arg.LiquidAmount;
  374. // Thread.Sleep((arriveRangeCount < 1 && slowSpeedCount < 1) ? arg.IntervalTime : 2000);
  375. // }
  376. // }
  377. // //CalibrationTitrationColor(arg, ref amount, titrationCount, balanceVal);
  378. // for (int i = 0; i < currSignals.Count; i++)
  379. // {
  380. // logger.LogCritical($"22222222currSignals r={currSignals[i].GetRSV()},g={currSignals[i].GetGSV()},num={i}");
  381. // }
  382. // for (int i = 0; i < currSignalsCompare.Count; i++)
  383. // {
  384. // logger.LogCritical($"22222222currSignalsCompare r={currSignalsCompare[i].GetRSV()},g={currSignalsCompare[i].GetGSV()},num={i}");
  385. // }
  386. // }
  387. // private static void ComplexSampleTitration(Titration2Arg arg, ref double amount)
  388. // {
  389. // ColorData2Point subRcurrSignals = new ColorData2Point();
  390. // while (true)
  391. // {
  392. // if (currSignals.Count >= 7) // 信号判断
  393. // {
  394. // double subR = 0.0;
  395. // int currpt = currSignals.Count - 6;
  396. // subRcurrSignals = _graber.GrabSignal(signalTimeLen);
  397. // //currSignalsCompare.Add(subRcurrSignals);
  398. // subR = (subRcurrSignals.GetRSV() - ((currSignals[currpt - 1].GetRSV() + currSignals[currpt].GetRSV()) / 2)) * 100 / subRcurrSignals.GetRSV();
  399. // //if (subR > 0)
  400. // //{
  401. // currSignals.Add(subRcurrSignals);
  402. // //}
  403. // logger.LogCritical($"22222222当前第{titrationCount:D3}滴,体积:{amount:F3},阈值:{subR:F2}");
  404. // Messager<Titration2ValueArgs>.Send("Titration2ValueChange", new Titration2ValueArgs(titrationCount, amount, subR));
  405. // if (subR <= balanceVal)
  406. // {
  407. // arriveRangeCount++;
  408. // Stopwatch swten = new();
  409. // swten.Start();
  410. // int retreatCount = 1; //后退次数
  411. // int flag = 0;
  412. // while (true) //继续采集信号,监测是否褪色
  413. // {
  414. // currpt = currSignals.Count - 6;
  415. // subRcurrSignals = _graber.GrabSignal(signalTimeLen);
  416. // //currSignalsCompare.Add(subRcurrSignals);
  417. // subR = (subRcurrSignals.GetRSV() - ((currSignals[currpt - 1].GetRSV() + currSignals[currpt].GetRSV()) / 2)) * 100 / subRcurrSignals.GetRSV();
  418. // //if (subR > 0)
  419. // //{
  420. // currSignals.Add(subRcurrSignals);
  421. // //}
  422. // logger.LogCritical($"22222222已达设定阈值,观察是否褪色,阈值为:{subR}");
  423. // if (subR <= balanceVal*0.7)
  424. // {
  425. // flag = 0;
  426. // retreatCount++;
  427. // if (swten.ElapsedMilliseconds / 1000 > arg.ArriveCheckCount)
  428. // {
  429. // break;
  430. // }
  431. // Running = false;
  432. // Thread.Sleep(1000);
  433. // continue; //颜色比较红,继续观察是否到30秒
  434. // }
  435. // else if (++flag > 1)
  436. // {
  437. // Running = true;
  438. // if (retreatCount > 2)
  439. // {
  440. // slowSpeedCount = 5; //如果回退超过三次判定,则给定慢速10次
  441. // logger.LogCritical($"22222222回退超过三次,给定慢速5次");
  442. // }
  443. // break;//当检测到的信号值 大于阈值时,则滴定未结束,需要继续滴定
  444. // }
  445. // else
  446. // {
  447. // retreatCount++;
  448. // Running = false;
  449. // Thread.Sleep(1000);
  450. // continue; //颜色比较红,继续观察是否到30秒
  451. // }
  452. // }
  453. // swten.Stop();
  454. // }
  455. // else
  456. // {
  457. // arriveRangeCount = arriveRangeCount > 0 ? arriveRangeCount - 1 : 0;
  458. // slowSpeedCount = slowSpeedCount > 0 ? slowSpeedCount - 1 : slowSpeedCount;
  459. // }
  460. // if (amount >= arg.MaxDropVolume) break;
  461. // if (!Running) break;
  462. // bool arriveEndPoint = LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).IsArriveEndPoint;
  463. // if (arriveEndPoint)
  464. // {
  465. // int distance = Convert.ToInt32(Math.Round(arg.PumpCapacity / arg.LiquidAmount * arg.LiquidConvertRatio));
  466. // LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).Execute(LiquidSwitchPattern.In, distance);
  467. // }
  468. // bool res = LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).Execute(LiquidSwitchPattern.Out, arg.LiquidConvertRatio);
  469. // if (!res)
  470. // {
  471. // logger.LogError("22222222写入失败,等待两秒后再次写入");
  472. // Thread.Sleep(2000);
  473. // continue;
  474. // }
  475. // titrationCount += 1;
  476. // amount += arg.LiquidAmount;
  477. // Thread.Sleep((arriveRangeCount < 1 && slowSpeedCount < 1) ? arg.IntervalTime : 2000);
  478. // }
  479. // }
  480. // //CalibrationTitrationColor(arg, ref amount, titrationCount, balanceVal);
  481. // for (int i = 0; i < currSignals.Count; i++)
  482. // {
  483. // logger.LogCritical($"22222222currSignals r={currSignals[i].GetRSV()},g={currSignals[i].GetGSV()},num={i}");
  484. // }
  485. // }
  486. // private static void CalibrationTitrationColor(Titration2Arg arg, ref double amount, int titrationCount, double balanceVal)
  487. // {
  488. // int count = 0;
  489. // if (amount >= 4 && amount < 6)
  490. // { count = 1; }
  491. // else if (amount >= 6 && amount < 8)
  492. // { count = 2; }
  493. // else if (amount >= 8 && amount < 9)
  494. // { count = 3; }
  495. // else if (amount >= 9)
  496. // { count = 4; }
  497. // for (int i = 0; i < count; i++)
  498. // {
  499. // bool arriveEndPoint = LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).IsArriveEndPoint;
  500. // if (arriveEndPoint)
  501. // {
  502. // int distance = Convert.ToInt32(Math.Round(arg.PumpCapacity / arg.LiquidAmount * arg.LiquidConvertRatio));
  503. // LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).Execute(LiquidSwitchPattern.In, distance);
  504. // }
  505. // bool res = LiquidPipeSwitchTitration2.StartNew.SetLiquidName(EquipmentNames.Titration2PotassiumPermanganate).Execute(LiquidSwitchPattern.Out, arg.LiquidConvertRatio);
  506. // if (!res)
  507. // {
  508. // logger.LogError("22222222写入失败,等待两秒后再次写入");
  509. // Thread.Sleep(2000);
  510. // }
  511. // titrationCount += 1;
  512. // amount += arg.LiquidAmount;
  513. // Messager<Titration2ValueArgs>.Send("Titration2ValueChange", new Titration2ValueArgs(titrationCount, amount, balanceVal));
  514. // logger.LogCritical($"22222222-------加入校准{i+1}滴");
  515. // Thread.Sleep(300);
  516. // }
  517. // }
  518. // #endregion
  519. //}
  520. }
  521. }