clinicalAD has asked for the wisdom of the Perl Monks concerning the following question:
This code stops after printing "2" if I've not opened/closed the port in Powershell yet - it's the reading of RS232 input where the script seems to get blocked quite consistently across different scripts. Powershell code to open and close is:use Win32::SerialPort; # Use instead for Windows my $port=Win32::SerialPort->new("COM1") || die "couldn't open COM1"; $port->baudrate(9600); # Configure this to match your device $port->databits(8); $port->parity("none"); $port->stopbits(1); #$port->handshake("none"); $port->user_msg(ON); print "Port COM1 successfully opened\n"; $count = 0; my $chars=0; my $buffer=""; print "1\n"; do { print "2\n"; my ($count,$saw)=$port->read(255); # will read _up to_ 255 char +s print "3\n"; if ($count > 0) { $chars+=$count; $buffer.=$saw; print $saw; } print "4\n"; $port->lookclear; print "5\n"; } while 1; $port->close;
Powershell to send RS232 on test bed is: $port.WriteLine("test") Unfortunately access permissions do not let me run a powershell script, and I'd rather not have the end user have to manually type in powershell code each time the PC is turned on... Many thanks for any advice provided.$port = new-Object System.IO.Ports.SerialPort COM1,9600,None,8,one $port.open() $port.close()
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SerialPort issues under Windows 10
by haukex (Archbishop) on Apr 15, 2021 at 19:08 UTC | |
by haukex (Archbishop) on Apr 16, 2021 at 12:24 UTC | |
by clinicalAD (Initiate) on Apr 20, 2021 at 13:19 UTC | |
|
Re: SerialPort issues under Windows 10
by Discipulus (Canon) on Apr 15, 2021 at 13:05 UTC | |
|
Re: SerialPort issues under Windows 10
by jcb (Parson) on Apr 16, 2021 at 02:58 UTC |