in reply to Re^2: Win32::SerialPort on Win10 issue
in thread Win32::SerialPort on Win10 issue

Hi. Thanks to all for the help.

I did try Serial Port Monitor (2 weeks trail). Wireshark looks too involved (and I previously have used on TCP/IP only). The Serial Port Monitor gives the response below, when I used the Realterm connection;

[05/07/2024 13:43:32] - Open port COM5 (C:\Program Files (x86)\BEL\Rea +lterm\realterm.exe) # this occurs on connection with SW [05/07/2024 13:04:58] Written data (COM5) 61 74 69 0d ati. + [05/07/2024 13:04:58] Read data (COM5) 45 4c 4d 33 32 37 20 76 31 2e 35 0d 0d 3e ELM327 v1.5..> + [05/07/2024 13:05:05] - Close port COM5 # this occurs on Realterm shutdown

While when I use the PERL connection;

[05/07/2024 13:05:12] - Open port COM5 (C:\Strawberry\perl\bin\perl.ex +e) # occurs with the creation of the object [05/07/2024 13:05:28] - Close port COM5 # occurs with Eclipse shutting down the running Perl

My only conclusion (at this stage) is that I am failing to connect to COM5 while there is nothing suspicious about the USB unit (yes it is a On Board Diagnostic unit used with automobiles with ~16 pin connector and no access to RS232).

Regards JC....

Replies are listed 'Best First'.
Re^4: Win32::SerialPort on Win10 issue
by jmClifford (Beadle) on Jul 08, 2024 at 13:55 UTC

    Hi. I did eventually find out the main issue with my previous program not working. The Win32::SerialPort as presented does not work with 64 bit operation (Perl). However there is a fix provided at (as linked to by Discipulus):

    https://rt.cpan.org/Public/Bug/Display.html?id=113337#txn-1691722

    This fix basically increases the sizes of some parameters in referencing a module (the memory mapping involved with this process).

    My current working program is:

    #! C:\perl\bin\perl.exe use strict; use warnings; use Win32::SerialPort; use Time::HiRes qw(usleep); my $port_name = 'COM5'; #my $config_file = 'setup.cfg'; # use this to configure from the fi +le my $port = new Win32::SerialPort( $port_name ) || die "Unable to open +: $^E\n"; # $^E EXTENDED_OS_ERROR #my $port = new Win32::SerialPort($port_name, $config_file) || die "Un +able to open: $^E\n"; $port->handshake('none'); # none dtr rts xoff $port->baudrate(38400); # 19200 57600 1200 9600 115200 4800 600 +2400 300 38400 $port->parity('none'); # space none odd even mark #$port->parity_enable(1); # for any parity except "none" $port->databits(8); # 7 8 $port->stopbits(1); # 2 1 $port->buffers(256, 256); $port->read_interval(0); #RI $port->read_const_time(20); #RC $port->write_char_time(1); #WM $port->write_const_time(100); #WC print "Write settings \n"; $port->write_settings || undef $port; # A report out to this console my $baud = $port->baudrate; my $parity = $port->parity; my $data = $port->databits; my $stop = $port->stopbits; my $hshake = $port->handshake; print "B = $baud, D = $data, S = $stop, P = $parity, H = $hshake\n"; # use the below to save the current configuration # if ( $port ) { $port->save('setup.cfg') ; print "Serial Port OK \n" +}; # pack: used for assembling binary stuff # my $status = pack('H2' * 6, 'ca', '00', '01', '00', '00', 'fe'); $port->write("ati"."\r"); #$port->write("ati\x0D\x0A"); # carriage return and line feed: n +o different #$port->write("ate0"."\r"); usleep 0; my $debug = 1; my $cmd = " "; while ($cmd ne "quit") { print "Input command: "; $cmd = <STDIN>; chomp $cmd; if ($cmd eq "quit") {next;} $port->write($cmd."\r"); my $loop = 1; while( $loop ) { usleep(200000); # 0.2 of a second my $response = $port->input; chomp $response; print $response; #my $responseHex = unpack ('H*', $response); #print $responseHex."\n"; my $last = substr ( $response, -1 ); # get the last charact +er if ($last eq ">") { $loop = 0; next; } print "."; } }

    Regards JC.....

Re^4: Win32::SerialPort on Win10 issue
by Marshall (Canon) on Jul 06, 2024 at 02:00 UTC
    Ok. This is progress. we learn that lower case AT commands are ok and that the line ending is \x0D. Use that instead of \n.

    Did you follow my suggestion of reading the port settings (handshake, etc)? Make sure that the port is configured and "happy" - if not it won't send data. I would not introduce the complication of a config file at this early stage.

    Again, trying running outside of Eclipse. That could make a difference.

    please show the exact code that you are using for this testing.