diff --git a/头罩视野slove/头罩视野/Views/VisiData.xaml.cs b/头罩视野slove/头罩视野/Views/VisiData.xaml.cs index 399833a..fb42015 100644 --- a/头罩视野slove/头罩视野/Views/VisiData.xaml.cs +++ b/头罩视野slove/头罩视野/Views/VisiData.xaml.cs @@ -26,7 +26,7 @@ namespace 头罩视野.Views public partial class VisiData : Page { - private TcpClient _tcpClient => ModbusResourceManager.Instance.TcpClient; + private IModbusMaster _modbusMaster => ModbusResourceManager.Instance.ModbusMaster; DispatcherTimer _timer; DataChange c = new DataChange(); @@ -34,7 +34,7 @@ namespace 头罩视野.Views public VisiData() { InitializeComponent(); - InitializeModbusTcp(); + _timer = InitDispatcherTimer(); } //复位btn @@ -253,35 +253,7 @@ namespace 头罩视野.Views private void GoTest(object s, RoutedEventArgs e) => NavigationService.Content = new Views.PageTest(); private void GoRecord(object s, RoutedEventArgs e) => NavigationService.Content = new Views.RecordDate(); private void GoView(object s, RoutedEventArgs e) => NavigationService.Content = new Views.RecordPage(); - private void InitializeModbusTcp() - { - try - { - - string plcIp = "192.168.1.10"; - bool initSuccess = ModbusResourceManager.Instance.Init(plcIp, 502); - if (!initSuccess) - { - MessageBox.Show("连接Modbus服务器失败!", "错误"); - //this.Close(); - return; - } - - // 检查连接状态 - if (_tcpClient == null || !_tcpClient.Connected) - { - MessageBox.Show("Modbus连接异常!", "错误"); - - return; - } - - - } - catch (Exception ex) - { - ShowError($"Modbus初始化失败: {ex.Message}"); - } - } + private void Page_Loaded(object sender, RoutedEventArgs e) { _timer.Start();