diff options
Diffstat (limited to 'roles/daq-node/t/01-probe.t')
| -rw-r--r-- | roles/daq-node/t/01-probe.t | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/roles/daq-node/t/01-probe.t b/roles/daq-node/t/01-probe.t index 8a84da3..3310f30 100644 --- a/roles/daq-node/t/01-probe.t +++ b/roles/daq-node/t/01-probe.t @@ -1,39 +1,27 @@ #!/usr/bin/env perl -# -*- mode: perl-ts; -*- +# -*- mode: cperl; -*- +# Basic Atlas Scientific EZO probe smoke test. + +use 5.40.1; use strict; use warnings; -use Test::More tests => 3; +use Test2::V0; +plan tests => 3; +use Device::SerialPort; use Time::HiRes qw(usleep); -# Basic Atlas Scientific EZO probe smoke test. -# -# Run on a daq-node: -# prove -v t/probe.t -# -# Optional overrides: -# FAPG_DAQ_SERIAL_PORT=/dev/ttyUSB1 FAPG_DAQ_SERIAL_BAUD=9600 prove -v t/probe.t - -my $port = $ENV{FAPG_DAQ_SERIAL_PORT} // $ARGV[0] // '/dev/ttyUSB0'; -my $baud = $ENV{FAPG_DAQ_SERIAL_BAUD} // $ARGV[1] // 9600; - -my $serial_module_ok = eval { - require Device::SerialPort; - Device::SerialPort->import; - 1; -}; - -BAIL_OUT("Device::SerialPort is required: $@") unless $serial_module_ok; -BAIL_OUT("Serial port does not exist: $port") unless -e $port; +my $port = '/dev/ttyUSB0'; +my $baud = 9600; my $serial = Device::SerialPort->new($port) or BAIL_OUT("Cannot open serial port: $port"); -$serial->baudrate($baud) or BAIL_OUT("Cannot set baudrate to $baud"); -$serial->databits(8) or BAIL_OUT('Cannot set databits to 8'); -$serial->parity('none') or BAIL_OUT('Cannot set parity to none'); -$serial->stopbits(1) or BAIL_OUT('Cannot set stopbits to 1'); +$serial->baudrate($baud); +$serial->databits(8); +$serial->parity('none'); +$serial->stopbits(1); $serial->read_char_time(0); $serial->read_const_time(100); @@ -87,9 +75,10 @@ sub drain_serial { sub clean_reply { my ($reply) = @_; - $reply =~ s/\r/\n/g; - $reply =~ s/\n+/\n/g; - $reply =~ s/^\n|\n$//g; + $reply + =~ s/\r/\n/gr + =~ s/\n+/\n/gr + =~ s/^\n|\n$//g; return $reply; } |