in reply to Really Odd Bug With LWP and Device::SerialPort
#!/usr/bin/perl use strict; use warnings; # # You must change what's below to a valid comm port, or the bug won't # show itself # my $port="COM9"; my $url='https://github.com'; use LWP::UserAgent; my $serial; BEGIN { if ($^O eq "MSWin32" or $^O eq "cygwin") { eval "use Win32::SerialPort"; die "$@\n" if ($@); } else { eval "use Device::SerialPort"; die "$@\n" if ($@); } } if ($^O eq "MSWin32" or $^O eq "cygwin") { $serial = Win32::SerialPort->new($port,1); } else { $serial = Device::SerialPort->new($port,1); } my $useragent = LWP::UserAgent->new(); my $request = new HTTP::Request; $request->method("GET"); $request->url($url); my $response = $useragent->request($request); my $data = $response->decoded_content; # # the line below grabs the first 6 bytes, which would be <!DOCT # but, the bug is triggered # $data=~s/(......).*/$1/s; # # now, uncomment the line below, and the bug doesn't show itself # $data=substr($data,0); # print "data is [$data]\n"; $serial->baudrate(9600); $serial->parity('none'); $serial->databits(8); $serial->stopbits(1); $serial->handshake('none'); $serial->write_settings(); $serial->write($data);
|
|---|