Hi
I am writing a serial protocol driver sends a command and receive a response from a TCP server.
Seems the driver can send and receive the packet to/from the TCP server. I can see the transactions from the element Stream Viewer.
Looks like I can receive the binary value (it is a fixed length binary value) from the TCP socket.
But I don't know how to present this binary value in a parameter (as a string or hex format, e.g. "0000000000050a0302804e") in the xml protocol driver.
I have parameter 7 to store the received binary value and It's always empty:
Following is the parameter 7 xml tags:
<Param id="7" trending="false">
<Name>RESPONSE</Name>
<Description>RESPONSE</Description>
<Information>
<Includes>
<Include>range</Include>
<Include>units</Include>
<Include>steps</Include>
<Include>time</Include>
</Includes>
</Information>
<Type>response</Type>
<Interprete>
<RawType>numeric text</RawType>
<Type>string</Type>
<LengthType>next param</LengthType>
</Interprete>
<Display>
<RTDisplay>true</RTDisplay>
<Positions>
<Position>
<Page>General</Page>
<Column>0</Column>
<Row>2</Row>
</Position>
</Positions>
</Display>
</Param>
I also try to use the QAction C# code to get the content of param 7 and the returned value seems empty as well.
respS = Convert.ToString(protocol.GetParameter(7));
protocol.Log(respS);
Please help, thanks.
The protocol.GetParameter() method call returns the value as string, but stops at the first zero byte (0x00).
The following method can be used to retrieve the raw bytes that were received:
public static byte[] GetParameterBinary(this SLProtocol protocol, int parameterId)
{
var data = (object[])protocol.GetData("parameter", parameterId);
return data?.Cast<byte>().ToArray();
}
Usage:
byte[] data = protocol.GetParameterBinary(7);