zhaopeiym / IoTClient

This is an IoT device communication protocol implementation client, which will include common industrial communication protocols such as mainstream PLC communication reading, ModBus protocol, and Bacnet protocol. This component is open source and free for life, using the most relaxed MIT open source agreement, you can modify and commercial use at will (commercial use please evaluate and test). 这是一个物联网设备通讯协议实现客户端,将会包括主流PLC通信读取、ModBus协议、Bacnet协议等常用工业通讯协议。本组件终身开源免费,采用最宽松的MIT开源协议,您可以随意修改和商业使用(商业使用请做好评估和测试)。
MIT License
1.27k stars 408 forks source link

如何读取三菱PLC的字符串 #39

Open easyboot opened 9 months ago

easyboot commented 9 months ago

95dbab06baf2e666b26f72de9d30c69

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

easyboot commented 9 months ago

通过下面的代码即可实现,很简单
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; }