フィルターのクリア

Sending UDP Packets from Perl Script to SImulink

5 ビュー (過去 30 日間)
A P S
A P S 2016 年 8 月 24 日
コメント済み: Pawel Ladosz 2016 年 8 月 26 日
Hello Everyone ,
I have bunch of numbers which I get from a hardware which needs to be sent to Simulink via UDP-Ethernet connection. I tried to use UDP Receive block in Simulink and exported the data to workspace. But I am not able to get any data .. What i get is all zeros.
Here is the sample Perl Script
#!/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\PQRST\Documents\Example.csv';
open(INFILE,"<",$in_file_name) or die "Not able to open test file $!";
$socket = IO::Socket::INET->new (PeerAddr => 'localhost',
PeerPort => 5005,
Type => SOCK_DGRAM,
Proto => 'udp') or die "ERROR in
+ Socket Creation : $!\n";
while (<INFILE>)
{
chomp;
if($. != 1) #skip first line
{
$data=$_; # Data would be in String format
$socket->send("$data");
sleep(0.25);
}
}
$socket->close();
Instead of directly running the script on hardware , I am just sending the data to myself ("localhost") and I am keeping '0.0.0.0' at port 5005 to receive data from all. Can anyone give me insight on this .. Any help would be appreciated...
  2 件のコメント
Walter Roberson
Walter Roberson 2016 年 8 月 25 日
Did you experiment with sending a constant string and seeing what comes out?
A P S
A P S 2016 年 8 月 25 日
Hello Roberson, Thanks for your reply. Yes, I did try the simple String like "Hello" . I received ASCII Value of HELLO>.. Like repeated values of 72 101 108 108 111 ... but I am not sure why I can't just send numbers.. Got to do with some Datatypei issues.. The Script and model used is same as below.. Instead I just Sent Repeated "Hello"

サインインしてコメントする。

回答 (1 件)

Pawel Ladosz
Pawel Ladosz 2016 年 8 月 25 日
Hi A P S,
Usually when we had this type of problem it was either of two things:
1. Your data type/length is not defined correctly on UDP receive end (less likely as you have managed to have some success before)
2. Your data is not being received/send on right ip adress/port. Instead of defining your address as localhost in your pearl script I recommend you define it as actual IP address (IP address of machine you are on). Same goes for UDP receive, just define IP of receiver as the machine you are on.
Let me know if this worked for you
  4 件のコメント
A P S
A P S 2016 年 8 月 25 日
Double Precision Mr.Roberson
Pawel Ladosz
Pawel Ladosz 2016 年 8 月 26 日
Change your "data Type" to Double and leave length as 1 in UDP receive2 block. Also for testing I recommend you attach a Display block and see what is going on much quicker

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by