wenxiangchao
2026-11-02 fe2aa4880d5c9fd88088ad0ed81ebaca05629f5f
Plugin.CurrentSensorControl/SingleSensor.xaml.cs
@@ -12,8 +12,8 @@
    [ObservableObject]
    public partial class SingleSensor : UserControl
    {
        private static Dictionary<string, ModbusRtuOverTcp> clients = new Dictionary<string, ModbusRtuOverTcp>();
        private static Dictionary<ModbusRtuOverTcp, bool> status = new Dictionary<ModbusRtuOverTcp, bool>();
        private static Dictionary<string, ModbusTcpNet> clients = new Dictionary<string, ModbusTcpNet>();
        private static Dictionary<ModbusTcpNet, bool> status = new Dictionary<ModbusTcpNet, bool>();
        [ObservableProperty]
        private string sensorName;
@@ -47,7 +47,7 @@
        [ObservableProperty]
        private int channel;
        private ModbusRtuOverTcp client;
        private ModbusTcpNet client;
        public SingleSensor()
@@ -63,10 +63,10 @@
            Port = port;
            Address = address;
            Channel = channel;
            string key = $"{Ip}:{Port}:{Address}";
            string key = $"{Ip}:{Port}";
            if (!clients.ContainsKey(key))
            {
                client = new ModbusRtuOverTcp(Ip, Port, (byte)Address);
                client = new ModbusTcpNet(Ip, Port);
                clients[key] = client;
            }
            else
@@ -134,16 +134,16 @@
            var sb = status[client];
            if (IsConnected)
            {
                OperateResult<double[]> res;
                OperateResult<ushort> res;
                lock (client)
                {
                    res = client.ReadDouble(channel.ToString(), 1);
                    res = client.ReadUInt16(channel.ToString());
                }
                Dispatcher.Invoke(() =>
                {
                    if (res.IsSuccess)
                    {
                        Current = res.Content[0].ToString();
                        Current = (res.Content / 1000d).ToString();
                        ErrMsg = string.Empty;
                    }
                    else