| | |
| | | [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; |
| | |
| | | [ObservableProperty] |
| | | private int channel; |
| | | |
| | | private ModbusRtuOverTcp client; |
| | | private ModbusTcpNet client; |
| | | |
| | | |
| | | public SingleSensor() |
| | |
| | | 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 |
| | |
| | | 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 |