Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
easyboot opened this issue Dec 8, 2023 · 1 comment
Open

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

easyboot opened this issue Dec 8, 2023 · 1 comment

Comments

@easyboot
Copy link

easyboot commented Dec 8, 2023

95dbab06baf2e666b26f72de9d30c69

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

@easyboot
Copy link
Author

easyboot commented Dec 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant