IoTClient icon indicating copy to clipboard operation
IoTClient copied to clipboard

如何读取三菱PLC的字符串

Open easyboot opened this issue 1 year ago • 1 comments

95dbab06baf2e666b26f72de9d30c69

你的代码中这个方法没有实现,那么我如何可以读取到字符串呢 public Result ReadString(string address) { throw new NotImplementedException(); }

easyboot avatar Dec 08 '23 07:12 easyboot

通过下面的代码即可实现,很简单
public string ReadString(string deviceName,ushort Length) { Result<byte[]> result1 = new(); if (client.Connected) { result1 = client.Read(deviceName, Length); } //byte[] result2 = new byte[Length]; //result2 result1.Value = result1.Value.TakeWhile((v, index) => result1.Value.Skip(index).Any(w => w != 0x00)).ToArray(); string str = Encoding.Default.GetString(result1.Value); return str; }

easyboot avatar Dec 08 '23 15:12 easyboot