我正在尝试通过串口自动化与调制解调器的XML通信,调制解调器接受xml请求并提供xml响应以及事件,响应格式为....并且事件格式为...... 我编写了一个Perl代码但无法捕获完整的响应。我需要解决方案并非常拼命地等待它...
这是我的Perl代码
#!/bin/perl
#To open Com1 port
use IO::Handle;
#below is initialization request
$initreq = "<request timestamp=\"1331734792\"><get resource=\"mod.Security.Session\"/></request>";
$nak = "<nak/>";
$ack = "<ack/>";
#logic starts here
$COM_PORT = "/dev/ttyS0";
print "trying to open $COM_PORT\n";
system ("mode /dev/ttyS0 baud=115200 stop=1 data=8 parity=n rts=off dtr=off");
open DEV,"+>$COM_PORT" or die "failed to open com port\n";
print "port opened \n";
$ofh = select(DEV);
$| = 0;
$/='>';
select($ofh);
print "Sending Session Initialization command\n";
print DEV "$initreq";
$out = <DEV>;
print "Initialization Response: $out \n" ;
#Below line sends login request
print DEV "<request session=\"1\" timestamp=\"9876543210\"><set resource=\"mod\"><Login>TRUE</Login><Pin>abcd</Pin></set></request>";
$out = <DEV>;
print "Login Response: $out";
#below gets some responses
print DEV "<request session=\"1\" timestamp=\"07012013174726006\"><get resource=\"mod.Sensors.{1}\"/></request>";
$out = <DEV>;
print "Get Sensor n details Response: $out \n";
#the below is logout request
print DEV "<request session=\"1\" timestamp=\"9876543211\"><set resource=\"nmp\"><Login>FALSE</Login></set></request>";
$out = <DEV>;
print "Logout Response: $out \n";