use Win32::SerialPort qw( :STAT 0.19 ); use Convert::ASCIInames; use String::HexConvert ':all'; #use strict; $PortName = "COM1"; $Configuration_File_Name = "Serial_Settings.cfg"; $PortObj = new Win32::SerialPort ($PortName, $quiet) || die "Can't open $PortName: $^E\n"; # $quiet is optional #$PortObj->user_msg(1); $PortObj->databits(8); $PortObj->baudrate(115200); $PortObj->parity("none"); $PortObj->stopbits(1); $PortObj->handshake("none"); $PortObj->buffers(4096, 4096); $PortObj->are_match("\n"); # possible end strings $PortObj->read_interval(100); # max time between read char (milliseconds) $PortObj->read_char_time(5); # avg time between read char $PortObj->read_const_time(100); # total = (avg * bytes) + const $PortObj->write_char_time(5); $PortObj->write_const_time(100); $PortObj->write_settings || undef $PortObj; $PortObj->save($Configuration_File_Name); $PortObj->close || die "close failed"; undef $PortObj; #--------------------------------------------------------- $PortObj = tie (*FH, 'Win32::SerialPort', $Configuration_File_Name) || die "Can't tie: $^E\n"; $PortObj->are_match("\n","\r"); # possible end strings $PortObj->write_settings || undef $PortObj; $PortObj->lookclear; # empty buffers sleep 5; print FH "Enter string:\n"; # works well my $out = ; # shouldn't this be blocking? print "$out\n"; print FH "Enter another string:\n"; # works well my $out = ; # shouldn't this be blocking? print "$out\n"; close FH || warn "close failed"; ## CLOSE ## undef $PortObj; untie *FH; ## DESTROY ##