in reply to Re^2: Win32 Serial Under Windows 7
in thread Win32 Serial Under Windows 7

PilotinControl:

I don't know anything about Win32::Serial, nor how it may interact with Windows 10. I'd suggest sprinkling a few print statements in locations to see what the code is doing.

The first one I'd suggest is to put a print statement immediately inside the while loop:

my $are_we_done_yet = 0; while (!$are_we_done_yet) { print "loop\n"; # Check for console activity my $con_key = ReadKey(-1);

This way, we can see if the loop is operating correctly. However, it'll quickly fill your screen up. So if that's working OK, you'll want to take it out again after checking.

Next, we can add a couple print statements to is_serial_data_ready, to see what it's doing:

sub is_serial_data_ready { print "is_serial_data_ready: enter\n"; # Non-blocking read: otherwise, we'll hang up here! my $c = $port->input; print "is_serial_data_ready: got <$c>\n"; # Process the incoming characters for my $char (split '', $c) { print "is_serial_data_ready: char '$char'\n"; if ($char eq "\n" or $char eq "\r") { print "is_serial_data_ready: end-of-line found\n"; # End of line found, add current line to buffer # (unless it's empty) if ($serial_input ne '') { push @serial_data, $serial_input; # start a new blank line $serial_input = ""; } } else { # Just a normal character, add to the input $serial_input .= $char; } } # Returns true if there are any completed lines to handle print "is_serial_data_ready: ", join(" // ", @serial_data), ".\n"; return scalar @serial_data; }

This way, you can see if it's actually entering the is_serial_data_ready function. If so, you can see if there's any time lag on the input statement, and whether anything ever shows up in $c. It'll also show if the characters are building up into statements or not.

The idea is to put some print statements in various locations to verify that the program is operating as you expect it to. Normally, I'd suggest using the perl debugger, but this trick should help you get started along finding the problem.

Since you say it operates differently between Windows 10 and Windows 7, I'd try to first concentrate on finding out just what the difference is. From there, it may give a clue on what to research to find the problem.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^4: Win32 Serial Under Windows 7
by PilotinControl (Pilgrim) on Apr 04, 2018 at 14:32 UTC
    I added each print statement as described....the only print that comes through is the Loop.....nothing ever comes from the is_serial_data_ready print statements. I find that very weird....as stated before when I use Putty and connect to the Arduino and push the button the feedback is printed to the screen. Each computer has the same version of perl and same version of Win32::SerialPort. The laptop running Vista is fine, the laptop running Windows 7 is fine....the Tablet running Windows 10...with an attached keyboard works fine sending...doesn't receive.

      PilotinControl:

      OK, then if you're never seeing the is_serial_data_ready print statements, then I'm assuming that you see only one "loop" statement printed on the screen until you press a key. If that's the case, then your "my $con_key = ReadKey(-1);" is blocking. You'll need to dig deeper into the use of Win32::Console and/or Term::ReadKey stuff to find out how to do a non-blocking read.

      If you get a continuous stream of "loop", then the $con_key value is defined even when there's no keypress ready. This is causing the first branch of the if statement to fire. You'd need to change the test to let the elsif condition activate and get into the is_serial_data_ready part of the code.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

        Correct... I only see one LOOP when a key is pressed etc. I still find this strange on windows 10 as windows xp, vista, and 7 all work fine makes you wonder what "broke". I will keep working and report back.
        so I've narrowed it down to this:
        user Term::ReadKey; ReadMode 4; my $key; while (!defined ($key = ReadKey(-1))) { print "Test\n"; sleep(5); } ReadMode 0;
        This does not work on Windows 10 using Strawberry Perl or ActiveState Perl....anyone else have this issue?