I have a server that sends data using UDP and want to use smart-serial to receive these data.
Since there will be no triggers or timers or command/response pairs, how can I read the data and set param with the data?
Hi Dennis,
As stated in the comment Dojo doesn't allow me to reply nice pieces of XML in comments so here is the answer to your comment:
Yes, actually but actually you would only have 1 response which would look like this:
<Responses>
<Response id="1">
<Name>genericResponse</Name>
<Description>GenericResponse</Description>
<Content>
<Param>60</Param>
</Content>
</Response>
</Responses>
And Param 60 would look like this:
<Param id="60">
<Name>genericResponseParam</Name>
<Description>GenericResponseParam</Description>
<Type>read</Type>
<Interprete>
<RawType>other</RawType>
<LengthType>next param</LengthType>
<Type>string</Type>
</Interprete>
</Param>
After every response of “GenericResponse” you can trigger a QAction and within this QAction you can get the data from the response, check to see if there is still old data. This is some inspiration on how your Qaction might look like:
byte[] bytesBuffer = GetDataFromParameter(protocol, Parameter.messagebuffer_23);
byte[] responseBytes = GetDataFromParameter(protocol, Parameter.genericresponseparam_60);
bool bUpdateInput;
bool bUpdateOutput;if (responseBytes.Length == 0)
{
return;
}byte[] bytes = new byte[bytesBuffer.Length + responseBytes.Length];
// This code will append the old + new data
Buffer.BlockCopy(responseBytes, 0, bytes, bytesBuffer.Length, responseBytes.Length);// In this method we would try and make messages out of the data.
List<NsBusMessage> messages = GetCandidateMessages(protocol, bytes);// here we will process these messages
ProcessCandidateMessages(protocol, messages, out bUpdateInput, out bUpdateOutput);public static byte[] GetDataFromParameter(SLProtocol protocol, int ccspPid)
{
Array byteArray = (Array)protocol.GetData("PARAMETER", ccspPid);if (byteArray != null)
{
byte[] byteCommand = new byte[byteArray.Length];
for (int i = 0; i < byteArray.Length; i++)
{
byteCommand.SetValue(byteArray.GetValue(i), i);
}return byteCommand;
}return new byte[] { };
}
Thanks Timothy, now I understand this connector better and can start writing the protocol.