RadioEngineer has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Sending UDP Packets to MATLAB
by pryrt (Abbot) on Aug 24, 2016 at 22:00 UTC
    Either you're AryanSinha trying to get someone else to write the code requested in Send a UDP Packet with bunch of numbers in PERL? that we couldn't write (since there wasn't enough information) and wouldn't write (because we gave plenty of hints, and people new to a language need to try in order to learn it), or you've just happened to start from nearly identical code as AryanSinha did, including the path starting with 'C:\Users\Aryan Sinha\...', but didn't see the other post which includes nearly identical code to yours.

    If you are not the same individual, I suggest reading that thread, especially NetWallah's probing questions, my hint-filled post and Mr. Muskrat's question-filled post. You've given us a little more data (confirmation of Big Endian, and a list of possible types), but it's still not enough for us to magically write it for you. And we don't know what separators (if any) that Simulink's Decode block might want. If nothing else, at least point us to the specific documentation for that block.

    After you've studied those answers, especially the documentation linked, and come up with your own nested processing loop: if that doesn't work, please come back (as either individual in either thread) and show us your progress, and ask specific questions about what you don't understand.

    You won't learn if you don't try yourself.

    update: rephrase first paragraph

Re: f
by NetWallah (Canon) on Aug 24, 2016 at 23:47 UTC
    This is the content in this posting(node 1170337) that the OP chose to delete:

    Quote:
    Sending UDP Packets to MATLAB

    Hello ,
    My Background in Perl: 5 Days of Experience in using Perl

    Task where I am stuck at :

    1) I have a radio which outputs 10 values at a given time stamp. I need to send those 10 Values as a single UDP packet via Ethernet connected to Another Hardware managed by MATLAB/Simulink.

    2) I wrote a Perl Script which gives me a string of all values like $data = '2.2,4,6,7.43,23.34,11,45576,343,22,10' ..

    3) MATLAB/Simulink blocks (related to my hardware) doesn't accepts strings . It needs numbers of type (Boolean,int8,unit8,int16,uint16,int32,uint32,float,double) and have big Endian format...

    4) Coming to my application , I can only receive 32 Bit Word input data stream so that decode block converts back into an array of 10 numbers... (There is no way I can know the functionality of Decode block so that I can encode in the same way in my perl script.)

    Can anyone please help me in this regard as to tell how can i send those bunch of numbers in a single UDP packet.

    I believe its similar to pack/unpack functions in Perl . Except the fact that Unpack is Decode block in Simulink. I have to PACK the data to either of Datatypes above mentioned with any possible delimiters
    End Quote.

            "Software interprets lawyers as damage, and routes around them" - Larry Wall

Re: Sending UDP Packets to MATLAB
by ikegami (Patriarch) on Aug 24, 2016 at 20:29 UTC

    You'll need to describe the format of the blocks if you want our help creating a block of that format.

      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?>
        #!/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 ....

        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);
Re: Sending UDP Packets to MATLAB
by Marshall (Canon) on Aug 25, 2016 at 20:30 UTC
    I tried to match up your 10 values with the 9 formats of your spec into a table and got this result (you have 10 data values and only 9 format specs):
    Data Type 2.2 Boolean 4 int8 6 unit8 7.43 int16 23.34 uint16 11 int32 45576 unit32 343 float 22 double 10 ????
    That table as per your post does not make sense to me.
    int8, uint8, int16, uint16, int32, uint32 are clear. How big is Boolean, one byte? Is float 32 bits? is double 64 bits?

    Please re-do the above table and show exactly what you need.  2.2    Boolean makes no sense to me. Neither does 7.43   int16 You will wind up with a buffer of bytes that can be sent via UDP, but the format spec must be exact and I mean to the exact bit! I presume that "unit8" means "uint8" or unsigned integer 8 bits. If you are RadioEngineer, get the terminology straight! There is a difference between ohms and volts. Same thing here.

    Update: Please do not delete stuff from your post. You can use the <strike> and </strike> tags to strike-thorough content. The problem is that when folks read your post later, some answers may not make sense or there is other confusion when things magically "disappear". If you choose to update your original post with the table that I requested, I would do so with an "Edit" and "update" comment just like this. That will raise the visibility of the update rather than a reply just to me. In this particular case, I think that would be better. There are folks here literately "chomping at the bit" to help you, but your question is not a good one. If you improve the question, you will get better answers.

Re: Sending UDP Packets to MATLAB
by RadioEngineer (Initiate) on Aug 24, 2016 at 20:03 UTC
    #!/usr/bin/perl #udpclient.pl use IO::Socket; use warnings; use Time::HiRes qw (sleep); my ($socket,$data); #my $in_file_name = $ARGV[0]; $in_file_name='C:\Users\Aryan Sinha\Documents\Example.csv'; open(INFILE,"<",$in_file_name) or die "Not able to open test file $!"; $socket = IO::Socket::INET->new (PeerAddr => '10.11.xxx.yy', PeerPort +=> 5012, Type => SOCK_DGRAM, Proto => 'udp') or die "ERROR in $socket +->send("$data"); sleep(0.25); $socket->close();