-
Notifications
You must be signed in to change notification settings - Fork 22
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
Reading datatype string #28
Comments
You need to specify the length as well: Not setting Also, the string support has some magic:
So please ensure Last but not least, the exception you're getting is upon parsing the response from the PLC, so apparently there's something triggering an error PLC-side while I think the request would be perfectly valid (but only reading the string header), that's something I'll have to look into. I'll also see if I can add some sanity checks to avoid Length not being set, perhaps changing the mutability of the |
Some of this has been addressed in 935168b. There's no released version with that change yet, but then again this only adds some additional sanity checks on length passed to |
I can read the datatype string with the following line:
DataBlockDataItem<byte[]> dataItemString = new DataBlockDataItem<byte[]> { DbNumber = 2, StartByte = 40, Length = 200 };
And converting it to a string with the next line:
Encoding.Default.GetString(dataItemString.Value)
Although I must say I expected to be able to read it like this:
DataBlockDataItem<string> dataItemStringString = new DataBlockDataItem<string> { DbNumber = 2, StartByte = 40 };
Which throws the following exception:
System.AggregateException HResult=0x80131500 Message=One or more errors occurred. (Read of dataItem Sally7.DataBlockDataItem1[System.String] returned DataTypeNotSupported) Source=Sally7 StackTrace: at Sally7.S7ConnectionHelpers.ParseReadResponse(ReadOnlySpan1 buffer, ReadOnlySpan1 dataItems) at Sally7.S7Connection.<ReadAsync>d__31.MoveNext() at Sandbox.Program.<Read>d__1.MoveNext() in D:\Projects\Sandbox\Sandbox\Program.cs:line 43
Inner Exception 1: Exception: Read of dataItem Sally7.DataBlockDataItem1[System.String] returned DataTypeNotSupported
This aside, reading the bytes and converting this to a string works.
My real problem starts when trying to read the string:
dataItemString.Value = Encoding.Default.GetBytes("Test");
Which writes the converted bytes to the DB:
X#(54 65 73 74 72 64 69 6E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00)
I can read them again using the working read method for the string, but I want the string to be decoded in the DB.
Writing through the string datatype for the DataBlockDataItem results in an empty string in the DB ('').
DataBlockDataItem<string> dataItemStringString = new DataBlockDataItem<string> { DbNumber = 2, StartByte = 40 }; dataItemStringString.Value = "Test";
How can I write the datatype string?
The text was updated successfully, but these errors were encountered: