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

Hi all,

I'm having a bit of a problem with Telnet and Modbus.

I'm trying to send a packet over to a Modbus slave but Telnet.pm is attaching a CRLF (0d 0a) to the end of my packet and it's confusing my Modbus slave. I am unsure how to prevent the module from sending the last packet! My send code is attached below. I've tried changing binmode but all it does is change whether CR or LF is being sent. Help please. Thanks!

Regards, Paul.

Example sent packet: 01 06 07 D0 00 00 89 47 0A

What I need: 01 06 07 D0 00 00 89 47

$data = join('',@buffor); #M +odbus frame to scalar print "ASCII characters sent: $data\n"; if ($Telnet) { #print "Sending over telnet\n"; $pass=$ob->print($data) or warn "Modbus client : problem with send: $! +\n";

Replies are listed 'Best First'.
Re: Telnet.pm Sending CRLF
by moritz (Cardinal) on Feb 22, 2012 at 08:24 UTC
    Looking at the source code of Telnet.pm:
    sub print { my ($self) = shift; my ( $buf, $fh, $s, ); $s = *$self->{net_telnet}; $s->{timedout} = ''; return $self->error("write error: filehandle isn't open") unless $s->{opened}; ## Add field and record separators. $buf = join($s->{ofs}, @_) . $s->{ors}; ...

    Can you already spot it? Yes, it's ors, the Output Record Separator. You can configure that, and the docs even tell you how. Isn't it great?

      Thanks moritz, that worked!