diff --git a/SlnMesnac.Extensions/RfidFactorySetup.cs b/SlnMesnac.Extensions/RfidFactorySetup.cs index 9631a85..01fcb01 100644 --- a/SlnMesnac.Extensions/RfidFactorySetup.cs +++ b/SlnMesnac.Extensions/RfidFactorySetup.cs @@ -50,6 +50,8 @@ namespace SlnMesnac.Extensions { RfidAbsractFactory _rfid = x.GetService(); bool connectResult = _rfid.Connect(item.equipIp, item.equipPort); + _rfid.ip = item.equipIp; + _rfid.port = item.equipPort; if (connectResult) { Log.Information($"RFID:{item.equipIp}:{item.equipPort};连接成功,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); @@ -59,12 +61,20 @@ namespace SlnMesnac.Extensions { absractFactories.Remove(_rfid); } - + _rfid.IsConnected = true; absractFactories.Add(_rfid); } else { Log.Information($"RFID:{item.equipIp}:{item.equipPort};连接失败,时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + _rfid.ConfigKey = item.equipKey; + + if (absractFactories.Contains(_rfid)) + { + absractFactories.Remove(_rfid); + } + _rfid.IsConnected = false; + absractFactories.Add(_rfid); } } } diff --git a/SlnMesnac.Rfid/Factory/RflyFactory.cs b/SlnMesnac.Rfid/Factory/RflyFactory.cs index 046ecad..f9064fb 100644 --- a/SlnMesnac.Rfid/Factory/RflyFactory.cs +++ b/SlnMesnac.Rfid/Factory/RflyFactory.cs @@ -40,7 +40,7 @@ namespace SlnMesnac.Rfid.Factory public class RflyFactory:RfidAbsractFactory { private ILogger _logger; - private readonly TcpClient _tcpClient = new TcpClient(); + public readonly TcpClient _tcpClient = new TcpClient(); private readonly StringChange _stringChange; public RflyFactory(ILogger logger,StringChange stringChange) @@ -49,6 +49,10 @@ namespace SlnMesnac.Rfid.Factory _stringChange = stringChange; } + + + + /// /// 建立连接 /// @@ -66,7 +70,8 @@ namespace SlnMesnac.Rfid.Factory } catch (Exception e) { - throw new InvalidOperationException($"设备连接异常:{e.Message}"); + _logger.LogError($"RFID设备{ip}连接异常:{e.Message}"); + return false; } } @@ -534,6 +539,18 @@ namespace SlnMesnac.Rfid.Factory return epcLength; } + public override void RefreshStatus() + { + if (_tcpClient != null) + { + this.IsConnected = _tcpClient.Online; + } + else + { + this.IsConnected = false; + } + } + #endregion } } \ No newline at end of file diff --git a/SlnMesnac.Rfid/RfidAbsractFactory.cs b/SlnMesnac.Rfid/RfidAbsractFactory.cs index 59a3a8d..7e4a174 100644 --- a/SlnMesnac.Rfid/RfidAbsractFactory.cs +++ b/SlnMesnac.Rfid/RfidAbsractFactory.cs @@ -32,8 +32,24 @@ namespace SlnMesnac.Rfid /// public abstract class RfidAbsractFactory { + public string ip; + public int port; + + public bool IsConnected { get; set; } + + public string ConfigKey { get; set; } + + /// + /// 获取连接状态 + /// + /// + /// + /// + public abstract void RefreshStatus(); + + /// /// 建立连接 /// diff --git a/SlnMesnac.WPF/SlnMesnac.WPF.csproj b/SlnMesnac.WPF/SlnMesnac.WPF.csproj index ffca841..4ec2f07 100644 --- a/SlnMesnac.WPF/SlnMesnac.WPF.csproj +++ b/SlnMesnac.WPF/SlnMesnac.WPF.csproj @@ -1,7 +1,7 @@  - WinExe + Exe net6.0-windows enable true diff --git a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs index 362fa60..1a3d20d 100644 --- a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs @@ -39,7 +39,7 @@ namespace SlnMesnac.WPF.ViewModel private readonly BaseConfigInfoPage configInfoPage = new BaseConfigInfoPage(); private readonly RecipeManagePage recipeManagePage = new RecipeManagePage(); private readonly AgvAndTaskMonitorPage agvAndTaskMonitorPage = new AgvAndTaskMonitorPage(); - private System.Timers.Timer timer = new System.Timers.Timer(1000 * 5); + private System.Timers.Timer timer = new System.Timers.Timer(1000 * 60); PlcAbsractFactory? plc = null; private BaseBusiness? baseBusiness = null; #region 参数定义 @@ -273,15 +273,16 @@ namespace SlnMesnac.WPF.ViewModel #region RFID状态 var rfidEquip = baseBusiness.GetRfidByKey("secondFloorOut"); - if (rfidEquip != null) + if (rfidEquip != null && rfidEquip.IsConnected) { + rfidEquip.RefreshStatus(); Out2FRfidStatus = 1; } - else + else { - Out2FRfidStatus = 2; - - + Out2FRfidStatus = 2; + bool result = rfidEquip.Connect(rfidEquip.ip, rfidEquip.port); + rfidEquip.IsConnected = result; } #endregion diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json index df0b546..e6fbf1c 100644 --- a/SlnMesnac.WPF/appsettings.json +++ b/SlnMesnac.WPF/appsettings.json @@ -66,6 +66,7 @@ // 小包出口位RFID "configId": 2, "equipIp": "192.168.2.28", + // "equipIp": "127.0.0.1", "equipPort": 20108, "equipKey": "secondFloorOut", "isFlage": true