|
|
|
using log4net;
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Service.Execute.Model;
|
|
|
|
|
|
|
|
namespace Service.Execute.Api;
|
|
|
|
|
|
|
|
public class RfidApi
|
|
|
|
{
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(RfidApi));
|
|
|
|
//TODO::Rfid 服务地址
|
|
|
|
private static readonly string BASE_URL = "http://localhost:7243";
|
|
|
|
|
|
|
|
private static readonly HttpClient _httpClient = new HttpClient()
|
|
|
|
{
|
|
|
|
Timeout = TimeSpan.FromSeconds(60)
|
|
|
|
};
|
|
|
|
|
|
|
|
public static async Task<bool> BeginRead()
|
|
|
|
{
|
|
|
|
Log.Info("BeginRead");
|
|
|
|
/*string url = BASE_URL + "/Api/BeginRead";
|
|
|
|
try
|
|
|
|
{
|
|
|
|
string s = await _httpClient.GetStringAsync(url);
|
|
|
|
Log.Info($"BeginRead resp = {s}");
|
|
|
|
return bool.Parse(s);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Console.WriteLine(e);
|
|
|
|
return false;
|
|
|
|
}*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async Task<bool> StopRead()
|
|
|
|
{
|
|
|
|
Log.Info("StopRead");
|
|
|
|
string url = BASE_URL + "/Api/StopRead";
|
|
|
|
/*try
|
|
|
|
{
|
|
|
|
string s = await _httpClient.GetStringAsync(url);
|
|
|
|
Log.Info($"StopRead resp = {s}");
|
|
|
|
return bool.Parse(s);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Console.WriteLine(e);
|
|
|
|
return false;
|
|
|
|
}*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async Task<RfidReadModel?> ReadRifd()
|
|
|
|
{
|
|
|
|
Log.Info("ReadRifd");
|
|
|
|
/*string url = BASE_URL + "/Api/ReadRfidData";
|
|
|
|
try
|
|
|
|
{
|
|
|
|
string s = await _httpClient.GetStringAsync(url);
|
|
|
|
Log.Info($"ReadRifd resp={s}");
|
|
|
|
if (s != String.Empty)
|
|
|
|
{
|
|
|
|
RfidReadModel? model = JsonConvert.DeserializeObject<RfidReadModel>(s);
|
|
|
|
if (model != null)
|
|
|
|
{
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
Console.WriteLine(e);
|
|
|
|
return null;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
return new RfidReadModel()
|
|
|
|
{
|
|
|
|
VelVin = "LC1HMYBF6R0004575",
|
|
|
|
VelNo = "LC1HMYBF6R0004575",
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|