Sending a nested struct type package which includes different types of data (uint8, uint16, etc.) with User Datagram Protocol (UDP)
4 ビュー (過去 30 日間)
I am trying to send a nested struct type package which includes different types of data (uint8, uint16, etc.) with UDP using udpport() in Instrument Control Toolbox. And I want to observe this sending process via wireshark. After reading the necessary documents, but I got the error that I could not enter a struct as input in the parameters I wrote in the write() function.
Expected input number 2, data, to be one of these types:
double, single, uint8, uint16, uint32, uin64, int8, int16, int32, int64, string, char,
Instead its type was struct.
After that I used struct2cell() cell2mat() to typecast it into correct form. I get another error.
All contents of the input cell array must be of the same data type.
Is there a way to do what I'm trying to achieve? Or do I have to use non-struct types with the same variables types in line with these functions?
I am new to the Matlab world so I hope I explained my question correctly.
回答 (1 件)
Sai 2022 年 12 月 28 日
I understand that you are trying to send nested structt type pckage whuch includes different types of data to UDP port. Since the UDP accepts only certain data types as input, you are using “struct2cell()” and “cell2map()” functions for typecasting. But before that try to convert different datatypes of struct to same datatype (either ‘uint8’ to ‘uint16’ or ‘uint16’ to ‘uint8’) using “typecast” function and then proceed with your methods. After retrieving data from UDP, you can again convert datatypes back to original format using same “typecast” function. But the data will not be altered as shown in below code snippet.
x = uint8([1 2 3])
y = uint16(x)
z = uint8(y)
Refer to the below documentation for more information on “typecast”
Find more on Instrument Connection and Communication in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!