use strict; require 5.003; use Win32API::CommPort; use Win32::SerialPort qw( :STAT 0.19); use Win32; my $quiet = 1; # Einschränkung bei Fehlermeldung my $PortName = 'COM3'; my $configFile = 'ER400TRS.cfg'; my $PortObj = new Win32::SerialPort( $PortName, $quiet )    or die "Can't open $PortName: $^E\n"; ## initialize $PortObj->user_msg( 'ON' ); $PortObj->baudrate( 19200 ); $PortObj->databits( 8 ); $PortObj->parity( "none" ); $PortObj->stopbits( 1 ); $PortObj->handshake( "none" ); my @ar=$PortObj->buffers( 128, 128 ); ## read buffer, write buffer ## write settings to com port $PortObj->write_settings or undef $PortObj; unless( $PortObj ){ print "can't change device control block: $^E\n"; } ## save settings in configuration file $PortObj->save( $configFile ) or warn "can't save $configFile: $^E\n"; ## close all stuff $PortObj->close or die "failed to close"; undef $PortObj; ## frees memory back to perl ## open again with tie (needed for some functions) $PortObj = tie( *COMFH, 'Win32::SerialPort', $configFile ) or die "can't tie using $configFile: ^E\n"; ### ready to communicate ##get current status my $BlockingFlags; my ( $InBytes, $OutBytes, $LatchErrorFlags ); ( $BlockingFlags, $InBytes, $OutBytes, $LatchErrorFlags ) = $PortObj->status        || warn "could not get port status\n"; if ( $BlockingFlags ) { warn "Port is blocked"; } if ( $BlockingFlags & BM_fCtsHold ) { warn "Waiting for CTS (clear to send)"; } if ( $LatchErrorFlags & CE_FRAME ) { warn "Framing Error"; } #######write to serial port################### my ( $count_out, $output_string ); $output_string = "Hallo "; my $i = 10; while( $i > 0 ) {   $count_out = $PortObj->write( $output_string );   warn "write failed\n"         unless ( $count_out );   warn "write incomplete\n"     if ( $count_out != length( $output_string ) );   $i--; } ## close all stuff $PortObj->close or die "failed to close"; undef $PortObj; ## frees memory back to perl