Rfid修改 增加连接和断开连接

zw
lxw 6 months ago
parent 4a5ab90bb5
commit 00cf40a1f3

@ -48,10 +48,56 @@ public class RfidApi
Log.Error($"RfidApi StopRead err e={e}"); Log.Error($"RfidApi StopRead err e={e}");
return false; return false;
} }
}
public static async Task<bool> 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<bool> 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<RfidReadModel?> ReadRifd() public static async Task<RfidReadModel?> ReadRifd()
{ {
//断连
var connect = await Connect();
if (!connect)
{
Log.Info("Rfid connect fail");
return null;
}
Log.Info("ReadRifd"); Log.Info("ReadRifd");
string url = BASE_URL + "/Api/ReadRfidData"; string url = BASE_URL + "/Api/ReadRfidData";
try try

@ -39,6 +39,7 @@ public class StationReadyState : IState
{ {
return null; return null;
} }
//plc是否是远程模式 //plc是否是远程模式
var plcIsAuto = PlcIsAuto(machine); var plcIsAuto = PlcIsAuto(machine);
if (InvokeStatus.Done != plcIsAuto) if (InvokeStatus.Done != plcIsAuto)
@ -229,7 +230,7 @@ public class StationReadyState : IState
machine); machine);
RfidApi.StopRead(); RfidApi.StopRead();
_log.Info("stop read rfid"); _log.Info("stop read rfid");
RfidApi.DisConnect();
machine.RfidReadFlag = true; machine.RfidReadFlag = true;
} }
}, () => }, () =>

Loading…
Cancel
Save