Hey Anja, I don't know by heart S7 protocol. I will try to answer based on other things I've seen. Maybe follow up replies will bring more light to us. :)
Depending on protocol, some keep and propagate type information, some do not. If all you have within request/response is bit or byte size then it is really matter of interpretation of returned data. If you request 4 bytes of data and PLC answers with 4 bytes and no error then you can expect any type which fits into this limit. That's why in many cases an additional information is needed. Either put manually by technician or through list of (pre)defined tags announced by manufacturer who embeds given PLC. The request fields we define in our "client" code ship an expected data type on our end which then is used to map it to transport sizes understod by PLC. Yet actual value on PLC might be different than we define. Then you most likely will get decoding errors or values out of reasonable range. Actual reason for skipping type/length information is to minimize transfer overhead. Typical type-length-value (TLV) encoding adds one or two bytes thus some systems omit it and communicate only value. The type and length information is then delivered by other way. Best, Łukasz On 29.04.2021 14:32, Anja Hager wrote: > Hi everyone, > > > > I'm currently writing my master thesis on the topic of Architecture Mining > for S7 machines through analysis of pcap files. > > > > Therefore I'm already able to retrieve all the fields for request and > response messages (S7ParameterReadVarRequest tells me the read request was > for DB444:0.0:REAL and the corresponding S7ParameterReadVarResponse contains > the answer as data item S7VarPayloadDataItem). > > Now I'm stuck at the point where I've got a byte array as returned by > item.getData() . How is it possible to convert this byte[] to the concrete > value of that DB, if the type is known (item.getTransportSize() returns a > DataTransportSize e.g. REAL, NULL etc.) > > I want: data of response as byte[] "41 dd bf 4e" of type REAL --> concrete > value: e.g. 123,456 > > > > I've had a look at the mechanism when actively reading a S7 DB e.g. via > HelloPlc4x example . Within S7ProtocolLogic.java a private function > (PlcValue parsePlcValue(S7Field field, ByteBuf data)) is used : return > DataItemIO.staticParse(readBuffer, field.getDataType().getDataProtocolId(), > stringLength) > > Unfortunately in my case I don't have all the parameters. My data types > REAL, NULL, .. are types enum DataTransportSize not enum TransportSize, so > there is no protocolId. > > Is there any way to make use of this function or do you have any other idea > how to convert the bytes ? > > I would really appreciate any help in this. Thanks! > > > > Best, > > Anja Hager > > > >
