my $PortName = '/dev/ttyS16' ; my $PortObj = new Device::SerialPort($PortName) || die "Can't open $PortName: $!\n"; $PortObj->databits(8); $PortObj->baudrate(19200); $PortObj->parity("none"); $PortObj->stopbits(1); #$PortObj->flowcontrol("none"); $PortObj->write('asic_rst 0'); my ($r1, $saw1) = $PortObj->read(255) ; $PortObj->write("asic_rst 1"); my ($r2, $saw2) = $PortObj->read(255) ; $PortObj->close || die "failed to close"; undef $PortObj; #### r1 = 8 $saw1 = a®k}r.\x17‚ r2 = 8 $saw1 = a®k}r.\x17Š #### #!/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 #### 1: 0 2: 5 3: 0 4: 0 Response is: 1ªó5├