I'm trying to receive simple udp packet with length and data.
Packet structure has no header/trailer and like followings.
|LENGTH(2byte)|DATA(variable length)|
ex)
0C 00 00 01 02 03 04 05 06 07 08 09 0a 0b
I defined in the protocol like followings but didn't work.
The packets can be seen in stream viewer but not handled in the connector.
[Response]<Param id="100">
<Name>DataLength</Name>
<Type>length</Type>
<Interprete>
<RawType>numeric text</RawType>
<LengthType>fixed</LengthType>
<Length>2</Length>
<Type>double</Type>
</Interprete>
<Length>
<Content>
<Param>1</Param>
</Content>
</Length>
</Param><Param id="101">
<Name>DataBody</Name>
<Type>read</Type>
<Interprete>
<RawType>other</RawType>
<Type>string</Type>
<LengthType>next param</LengthType>
</Interprete>
</Param>
[Trigger]<Response id="100">
<Name>DevicePacket</Name>
<Content>
<Param>100</Param>
<Param>101</Param>
</Content>
</Response>
[Action]<Trigger id="100">
<Name>Before Packet</Name>
<On id="100">response</On>
<Time>before</Time>
<Type>action</Type>
<Content>
<Id>10</Id>
<Id>11</Id>
</Content>
</Trigger><Trigger id="101">
<Name>After Packet</Name>
<On id="100">response</On>
<Time>after</Time>
<Type>action</Type>
<Content>
<Id>100</Id>
</Content>
</Trigger>
<Action id="10">
<Name>Response Read</Name>
<On>response</On>
<Type>read</Type>
</Action>
<Action id="11">
<Name>Response Length</Name>
<On>response</On>
<Type>length</Type>
</Action>
Something wrong or missing?
Hi,
I noticed that this question has been open for some time now. If this has been resolved in the meantime, could you select the best answer so the question is closed? If none of the answers provided the solution, but you have found it yourself, could you add an answer of your own?
This issue has solved by replacing the order of the read/length.
[Original][Fixed]<Trigger id=”100″>
<Name>Before Packet</Name>
<On id=”100″>response</On>
<Time>before</Time>
<Type>action</Type>
<Content>
<Id>10</Id> <!-- On Response: Read -->
<Id>11</Id> <!-- Response Length -->
</Content>
</Trigger>
<Trigger id=”100″>
<Name>Before Packet</Name>
<On id=”100″>response</On>
<Time>before</Time>
<Type>action</Type>
<Content>
<Id>11</Id> <!-- Response Length -->
<Id>10</Id> <!-- On Response: Read -->
</Content>
</Trigger>
This is reverse order in the document but it's working for now.
Hi Hideyuki
If feasible, I'd suggest configuring a smart-serial connection to process UDP data, as UDP packets are asynchronous.
The parsing of the response can be managed within a QAction by using the protocol.GetData() method which returns an object array where each item is a byte.
Method GetData | DataMiner Docs
As an additional point, ensure the response is cleared after the processing.
Regards
Hi Hideyuki,
In addition to what Tom suggested, check if the value of the length parameter and the actual length of the Data are equal/matching. When the number of bytes is larger or smaller than the defined length, the response processing will fail, and the data parameter will not be updated with received content; only the length field will be updated with its corresponding new value. From the example you provided (assuming it is a valid response data), that seems the case. The actual length of the data is 12 bytes whereas the value of the length parameter (0C 00) is higher. This looks like the length parameter is coming in big endian. The default endianness used in Dataminer is little endian. You can change the endianness in the interpret tag of the length parameter definition as follows.
<Param id="100">
<Name>DataLength</Name>
<Type>length</Type>
<Interprete>
<RawType>numeric text</RawType>
<LengthType>fixed</LengthType>
<Length>2</Length>
<Type>double</Type>
<Base>16</Base>
<Endian>big</Endian>
</Interprete>
</Param>
Hi Fenta,
Thank you for the comment.
These streams are little endian. 0x0c is the first and 0x00 is the second.
As I commented in the main thread, this issue seems to be fixed by changing the action orders.
Hi Hideyuki,
Could you please try again using the following parameter definition? The 'length' action should also not be needed anymore.
<Param id="100">
<Name>DataLength</Name>
<Type>length</Type>
<Interprete>
<RawType>numeric text</RawType>
<LengthType>fixed</LengthType>
<Length>2</Length>
<Type>double</Type>
<Base>16</Base>
</Interprete>
</Param><Param id="101">
<Name>DataBody</Name>
<Type>read</Type>
<Interprete>
<RawType>other</RawType>
<Type>string</Type>
<LengthType id="100">other param</LengthType>
</Interprete>
</Param>
Hi Tom,
Thank you for the reply.
I’ve already tried these definition but didn’t work.
I think this is what explained in the doc.
https://docs.dataminer.services/develop/devguide/Connector/ConnectionsSerialCreatingCommandsAndResponses.html#responses-with-dynamically-defined-length
I tried param type of 100 as both ‘length’ and ‘read’ but didn’t work.
I tried replacing the order between action:read and action:length and the packet received correctly. (action:length > action:read)
Are these reasonable?
In doc – https://docs.dataminer.services/develop/devguide/Connector/ConnectionsSerialCreatingCommandsAndResponses.html#responses-with-length-field
It said “Note that the length action needs to be after “read response”.”…