$sock->send( "$msg\n" ); # possibly " $msg\r\n "
# or send a blank line
$sock->send( "\n" );
to tell the hardware you are done sending your line.
You might also try something like this hack to inefficiently read 1 byte at a time
while(my $len = sysread( $sock, my $buffer, 1) > 0) { print "$buffer\
+n"; }
Otherwise, you need to provide much more information about your hardware. Does the hardware have a driver written in c or c++? Can you look at the driver's source code to see what it does? Does the hardware have any driver that works?
Finally, when you use the socket methods send and recv, you are establishing a 1 way-at-a-time protocol. The hardware device might be getting locked into recv mode.
You might be better off using IO::Select on the socket and using syswrite and sysread instead of send and recv.
A simple IO::Select program might look like this:
#!/usr/bin/perl
use warnings;
use strict;
my $sock = new IO::Socket::INET(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
Reuse => 1
);
$sock->autoflush(1); # latest Sockets has this on by default
print $sock "log in information";
my $read_set = new IO::Select($sock);
my $incoming_data = "";
while (1) {
my @ready = $read_set->can_read(.5);
foreach my $rh (@ready) {
sysread ( $rh, my $line, 1024);
$incoming_data .= $line;
print "$incoming_data\n";
}
}
|