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

Write String and WString not working #26

Open
3Philipp3 opened this issue Feb 18, 2024 · 4 comments
Open

Write String and WString not working #26

3Philipp3 opened this issue Feb 18, 2024 · 4 comments

Comments

@3Philipp3
Copy link

Hello!

First of all thank you for your outstanding work, this is a really great project. I ran some tests with a CPU 1510SP-1 and I encountered some problems with writing strings. Reading is ok, for all other datatypes that I've tried writing is also ok just strings and wstrings are
always giving me errors (S7CommPlusConnection - WriteValues: Write with errors. ReturnValue=2318368645692325907).

Thanks

@thomas-v2
Copy link
Owner

Are you using the tag classes for writing, PlcTagWString / PlcTagString? The constructor has an additional parameter, where you have to pass the string max.-length. By default it's 254, this is the length if you define a WString or a String without a specified length.
This is neccessary, because on writing a string, you need to write all bytes of the string, including the header bytes.

@3Philipp3
Copy link
Author

Hello,

no, I just used it like this:

public void WriteStringVar(String SymAdress, string val)
{
List writevalues = new List();
PValue writeValue = new ValueWString(val);
writevalues.Add(writeValue);
List writelist = new List();
var v = vars.Find(x => x.Name == SymAdress);
writelist.Add(new ItemAddress(v.AccessSequence));
List errors = new List();
errors.Clear();
int res = Client.WriteValues(writelist, writevalues, out errors);
}

But there is just the used Stringdata in the buffer (Stringlength + chars).

I changed it now to the PlcTagString method you suggested and this is working.

Thanks a lot!

@thomas-v2
Copy link
Owner

thomas-v2 commented Feb 19, 2024

The PlcTag classes are a layer above the ReadValues / WriteValues methods, as for some Plc datatypes you need informations of how to process the read data, and how to write the data in advance from the browsed informations. As you have seen for example in strings, they are transmitted as an array of byte (String) or ushort (WString).

@3Philipp3
Copy link
Author

Thank you for that information.
Really appreciate your work on this.

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

2 participants