May 25, 2013, 7:36 AM
Post #1 of 3
Hi All. I'm a perl noob for sure, and am trying to write a quick perl script that will poll a device's information continuously via serial port.
Perl/Linux and Serial Port Communications
The device accepts various hex commands, and immediately outputs status based on the command. I'm trying to obtain the device's LCD screen readout (the device returns 70 bytes of data for this), but am having a bit of difficulty.
I've verified that sending the command to the device works, as I can run 'cat /dev/ttyUSB0' in a second session and see the device's output. My perl script however, is not capturing the output - almost as if the output occurs to quickly for perl to pick it up.
Below is my code:
use Device::SerialPort qw ( :PARAM :STAT 0.07);
my $port = new Device::SerialPort("/dev/ttyUSB0");
$port->write( pack('H*', q[024C034F]));
# my $answer = $port->lookfor;
$answer = $port->read(70);
I've also tried other sample scripts found online, but the same behavior results.
If anyone has a suggestion, I would be greatful.