Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: can't write-Win32::SerialPort

by Anonymous Monk
on May 15, 2014 at 21:51 UTC ( [id://1086218]=note: print w/replies, xml ) Need Help??


in reply to Re^2: can't write-Win32::SerialPort
in thread can't write-Win32::SerialPort

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.

Replies are listed 'Best First'.
Re^4: can't write-Win32::SerialPort
by franko (Initiate) on May 15, 2014 at 22:50 UTC
    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
Re^4: can't write-Win32::SerialPort
by franko (Initiate) on May 15, 2014 at 22:34 UTC

    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\micro-2.pl 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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1086218]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-24 01:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found