From 00cf40a1f3c9a1a37a9ea28ad0e1adf19d15af08 Mon Sep 17 00:00:00 2001 From: lxw Date: Tue, 4 Jun 2024 13:12:31 +0800 Subject: [PATCH] =?UTF-8?q?Rfid=E4=BF=AE=E6=94=B9=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E5=92=8C=E6=96=AD=E5=BC=80=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Execute/Api/RfidApi.cs | 46 +++++++++++++++++++++++ Service/Execute/Step/StationReadyState.cs | 3 +- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Service/Execute/Api/RfidApi.cs b/Service/Execute/Api/RfidApi.cs index 5867831..4da8141 100644 --- a/Service/Execute/Api/RfidApi.cs +++ b/Service/Execute/Api/RfidApi.cs @@ -48,10 +48,56 @@ public class RfidApi Log.Error($"RfidApi StopRead err e={e}"); return false; } + + + } + + public static async Task DisConnect() + { + Log.Info("DisConnect"); + string url = BASE_URL + "/Api/Close"; + try + { + string s = await _httpClient.GetStringAsync(url); + Log.Info($"DisConnect resp={s}"); + return bool.Parse(s); + } + catch (Exception e) + { + Log.Error($"RfidApi DisConnect err e={e}"); + return false; + } + } + + public static async Task Connect() + { + var disConnect = await DisConnect(); + + Log.Info("Connect"); + string url = BASE_URL + "/Api/Open"; + try + { + string s = await _httpClient.GetStringAsync(url); + Log.Info($"Connect resp={s}"); + return bool.Parse(s); + } + catch (Exception e) + { + Log.Error($"RfidApi Connect err e={e}"); + return false; + } } public static async Task ReadRifd() { + //断连 + var connect = await Connect(); + if (!connect) + { + Log.Info("Rfid connect fail"); + return null; + } + Log.Info("ReadRifd"); string url = BASE_URL + "/Api/ReadRfidData"; try diff --git a/Service/Execute/Step/StationReadyState.cs b/Service/Execute/Step/StationReadyState.cs index b1d3191..4684259 100644 --- a/Service/Execute/Step/StationReadyState.cs +++ b/Service/Execute/Step/StationReadyState.cs @@ -39,6 +39,7 @@ public class StationReadyState : IState { return null; } + //plc是否是远程模式 var plcIsAuto = PlcIsAuto(machine); if (InvokeStatus.Done != plcIsAuto) @@ -229,7 +230,7 @@ public class StationReadyState : IState machine); RfidApi.StopRead(); _log.Info("stop read rfid"); - + RfidApi.DisConnect(); machine.RfidReadFlag = true; } }, () =>