in reply to Re: Sending UDP Packets to MATLAB
in thread Sending UDP Packets to MATLAB

I need to Pack those Numbers and send it ... Unpacking part will be taken care of Decode block within Simulnk.  $message_array = pack ("(A*)*", @Numbers_to_Send); Do u think this should work?>

Replies are listed 'Best First'.
Re^3: Sending UDP Packets to MATLAB
by Anonymous Monk on Aug 24, 2016 at 21:50 UTC
    #!/usr/bin/perl #udpclient.pl use IO::Socket; use warnings; use Time::HiRes qw (sleep); my ($socket,$data); $socket = IO::Socket::INET->new (PeerAddr => '10.11.254.81', PeerPort => 5005, Type => SOCK_DGRAM, Proto => 'udp') or die "ERROR in + Socket Creation : $!\n"; @tempData = (20,30,40); $socket->send(pack ("(A*)*", @tempData)); $socket->close();
    I am receiving the data as 203040 ... How cna I add a delimiter like a space to this ... so that I can receive the data as 20 30 40 ....
      If you are trying to send floating point data in a form that the Simulink will be happy with -- one of the binary formats that RadioEngineer listed -- then trying to encode the integers 20, 30, 40 as a string "20 30 40" is not the right way to go about it. Read the other thread I referenced, and ask specific questions.

      In that other thread, I already said which pack formats are needed in order to properly encode floating point numbers; you concatenate those together (with whatever separators that the Simulink block is expecting) and send them as a single message.

Re^3: Sending UDP Packets to MATLAB
by ikegami (Patriarch) on Aug 25, 2016 at 14:04 UTC

    I already said which pack formats are needed in order to properly encode floating point numbers

    I asked for the format of the packet, and you have no yet provided that. There can only be one of those.

    Maybe you mean you control the decoding, so we're free to create a packet format that's composed of those number formats. If so, packing the numbers as double-precision numbers sounds most appropriate.

    my $packet = pack('d>*', @nums);