Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to write a simple program to communicate with the serial port. I am able to send commands, but getting what is sent back has proven difficult. I cannot use Win32::SerialPort, or Device::SerialPort.
I had limited success with:
But it can hang on $input = <DEV> when there is no incoming data.my $COM_PORT = "com1"; open DEV,"+<", "$COM_PORT" or die "failed to open com port\n"; print DEV "\n"; $input = <DEV>;
But when run, this simply outputs:use IO::Select; use IO::Handle; $COM_PORT = "COM1"; my $Serial; #system("mode com1 baud=9600 stop=1 data=8 parity=n rts=on dtr=on"); #open $Serial,"+<", "$COM_PORT" or die "failed to open com port\n"; sysopen $Serial,"$COM_PORT", O_RDWR|O_NDELAY|O_NCOTTY or die "failed t +o open com port\n"; my $fd = fileno($Serial); close ($Serial); print "File Descriptor is: $fd \n"; $sel = IO::Select->new; $sel -> add($Serial); if($sel -> exists($Serial)) { print "Handle exists \n"; } print $Serial "\n"; my $timeout = 0; if (my @ready = $sel -> can_read(0)) { print "Ready to read! \n"; } if (my @ready = $sel -> can_write(0)) { print "Ready to write! \n"; } if(my @ready = $sel -> has_error(0)) { print "Exceptions found! \n"; } close ($Serial); print "Finished... \n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Serial Port I/O
by Anonymous Monk on May 15, 2013 at 17:32 UTC | |
|
Re: Serial Port I/O
by jmlynesjr (Deacon) on May 15, 2013 at 19:41 UTC | |
|
Re: Serial Port I/O
by bulk88 (Priest) on May 16, 2013 at 00:37 UTC |