调试
This commit is contained in:
@@ -26,9 +26,6 @@ namespace 头罩视野
|
||||
{
|
||||
InitializeComponent();
|
||||
ModbusHelper.Connect("192.168.1.10", 502); // 连接一次,全局生效
|
||||
//InitializeModbusTcp();
|
||||
//MainFrame.Content = new Views.ChangeLanguage();
|
||||
|
||||
}
|
||||
//private void GoHome(object s, RoutedEventArgs e) => MainFrame.Content = new Views.ChangeLanguage();
|
||||
private void GoTest(object s, RoutedEventArgs e) => MainFrame.Content = new Views.PageTest();
|
||||
@@ -39,36 +36,6 @@ namespace 头罩视野
|
||||
|
||||
//NavigationService.Navigate(new Views.RecordDate()); 页面相互跳转
|
||||
|
||||
//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 ShowError(string msg) => MessageBox.Show(msg, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
@@ -254,7 +254,7 @@ namespace 头罩视野.Views
|
||||
try
|
||||
{
|
||||
ushort[] registers = await Task.Run(async () =>
|
||||
await _modbusMaster.ReadHoldingRegistersAsync(1, (ushort)address, (ushort)length)
|
||||
await _modbusMaster?.ReadHoldingRegistersAsync(1, (ushort)address, (ushort)length)
|
||||
);
|
||||
|
||||
if (registers != null && registers.Length >= 2)
|
||||
@@ -279,7 +279,7 @@ namespace 头罩视野.Views
|
||||
try
|
||||
{
|
||||
ushort[] registers = await Task.Run(async () =>
|
||||
await _modbusMaster.ReadHoldingRegistersAsync(1, (ushort)address, (ushort)length)
|
||||
await _modbusMaster?.ReadHoldingRegistersAsync(1, (ushort)address, (ushort)length)
|
||||
);
|
||||
|
||||
if (registers != null && registers.Length >= 2)
|
||||
@@ -358,8 +358,6 @@ namespace 头罩视野.Views
|
||||
_timer.Start();
|
||||
ma = new Function(_modbusMaster);
|
||||
c = new DataChange();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user