#!/usr/bin/perl -w use strict; use warnings ; use Win32::SerialPort qw( :STAT ) ; # } my $PortName = 'COM17' ; my $serial_port = new Win32::SerialPort($PortName) || die "Can't open $PortName: $!\n"; $serial_port->databits( 8 ); $serial_port->baudrate(19200); $serial_port->parity("none"); $serial_port->stopbits( 1 ); $serial_port->handshake("rts") ; my $response = undef ; my $complete = 0 ; my $command = "12345" ; $serial_port->write("$command\r") ; sleep 1 ; my ( $blocking_flags, $in_bytes, $out_bytes, $latch_error_flags ) = $serial_port->status() ; print("1: $blocking_flags\n") ; print("2: $in_bytes\n") ; print("3: $out_bytes\n") ; print("4: $latch_error_flags\n") ; $serial_port->lookclear; #clear the buffer sleep (2) ; if( $in_bytes > 0 ) { for( my $i = 0 ; $i < $in_bytes ; $i++ ) { # Get a byte at a time to process. $response .= $serial_port->read( 1 ) ; if( $response =~ /\r/ ) { $complete = 1 ; } } } print ("Response is: $response\n") ; $serial_port->close || die "failed to close"; undef $serial_port; # frees memory back