Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: can't write-Win32::SerialPort

by kschwab (Priest)
on May 15, 2014 at 18:28 UTC ( #1086185=note: print w/replies, xml ) Need Help??

in reply to can't write-Win32::SerialPort

Downloaded your script and ran it on a Windows 7 box, and I see FF010003005F630A going out the port.

Your problem is probably one of:

  1. Bad serial monitor. There aren't many software serial monitors that actually work on Windows 7. I use "Advanced Serial Port Monitor", which does work.
  2. Serial port permissions. Run your script under a shell that you started with right click -> run as administrator.
  3. Wrong serial port. Start device manager (under control panel) and make sure you see COM1, without any yellow or red warning symbols about the device state. This one seems likely. It's unusual (not impossible) for windows to assign COM1 to a USB to serial device. I bet your serial port is actually COM3.

Replies are listed 'Best First'.
Re^2: can't write-Win32::SerialPort
by franko (Initiate) on May 15, 2014 at 20:44 UTC
    Thanks for such speedy input! 1. Serial monitor: I see output from the dotnet program so the monitor is working. 2. I opened a privileged command prompt and still get the same problem. 3.I reassigned the com port to 1 and am using it successfully with the dotnet program. I don't get an open error on Com 1. It did not work on com 3, which as you point out, was the initial default. I updated the program and have some error messsges output:
    #! C:\perl\bin\perl.exe use strict; use warnings; use Win32::SerialPort ; my $count_out = 0; my $PortObj = new Win32::SerialPort ("COM1") || die "Can't open port\n"; $PortObj->baudrate(9600); $PortObj->parity("none"); $PortObj->databits(8); $PortObj->stopbits(1); $PortObj->handshake("none"); $PortObj->write_settings || undef $PortObj; my $stt = pack 'H16', 'FF010003005F630A' ; # $PortObj->write($stt); $count_out = $PortObj->write($stt); warn "write failed\n" unless $count_out; warn "write incomplete\n" if $count_out != length($stt); $PortObj->error_msg(1); $PortObj->user_msg(1); $PortObj->close || warn "Close Failed!\n"; undef $PortObj; # output from program: # C:\Users\Frank\Desktop> # Write failed # Use of uninitialized value $count_out in numeric ne (!=) at C:\Users +\Frank\Deskttop\ line 34. # Write incomplete

      Place the two statements $PortObj->error_msg(1); $PortObj->user_msg(1); before the initialization (i.e. just after new). Also, please follow all of the advice from this node.

      Also, this thread is starting to sound incredibly similar to this one, in which the problem was reportedly solved by using 32-bit Strawberry Perl instead of 64-bit. Another user reported similar problems.

        OK, thanks much for that reference to the other posts - which somehow I could not find. Anyway, after not knowing how to deal with the error message "the handle is invalid", I tried uninstalling 64 bit Strawberry and installing 32 bit strawberry. I got error msgs when I installed SerialPort, so I moved the com port back to 1. Still more error messages - failed tests, so I did a 'force install'. Bottom line - my program now works perfectly - I can write to com 1 now. Thanks much. I don't know how to pursue the 64 bit problem, but I post this in the hopes that others may benefit and carry on the fight. Frank

        The plot thickens... I reset the comm port back to com3 just to be safe.

        (I set it to Com 1 because the Serial Port module install seemed to demand a Com 1 test!) Although moving the port to com1 let me get farther in the module install, it still failed until I did a force. That installed it, but maybe that is part of the problem?

        I now get this:

        write failed: The handle is invalid at C:\Users\Frank\Desktop\ line 32

        #! C:\perl\bin\perl.exe use strict; use warnings; use Win32::SerialPort ; my $count_out = 0; my $PortObj = new Win32::SerialPort("COM3") || die "Can't open port\n"; $PortObj->error_msg(1); $PortObj->user_msg(1); $PortObj->baudrate(9600); $PortObj->parity("none"); $PortObj->databits(8); $PortObj->stopbits(1); $PortObj->handshake("none"); $PortObj->write_settings || undef $PortObj; my $stt = pack 'H16', 'FF010003005F630A' ; $count_out = $PortObj->write($stt) or die "write failed: $^E"; warn "write failed\n" unless $count_out; warn "write incomplete\n" if $count_out != length($stt); $PortObj->close || warn "Close Failed!\n"; undef $PortObj;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1086185]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2018-07-21 23:35 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (450 votes). Check out past polls.