#!/usr/bin/perl -w use strict; use warnings; use Win32::SerialPort; my $psr500bin = 'C:/Users/mbates/Documents/My PSR 500/20080330-mydownload.bin'; open (FILE_IN_1, "> $psr500bin") or die "Could not open $psr500bin for write: $!\n"; binmode(FILE_IN_1); my $port_name = 'COM4'; my $config_file = 'tpj4.cfg'; my $port = new Win32::SerialPort($port_name, $config_file) || die "Unable to open: $^E\n"; #Setup the parameters $port->baudrate(115200) #$port->baudrate(38400) || die "Can't set serial port baudrate ...\n"; $port->parity("none") || die "Can't set serial port parity ...\n"; $port->databits(8) || die "Can't set serial port databits ...\n"; $port->stopbits(1) || die "Can't set serial port stopbits ...\n"; #$port->handshake('xoff'); $port->handshake('rts') || die "Can't set serial port handshake ...\n"; $port->binary('T'); $port->stty_echo(0); $port->stty_igncr(0); $port->stty_echoctl(0); $port->datatype('raw'); #my $dtr=$port->dtr_active(0); # my $rts=$port->rts_active(0); $port->write_settings || die "Can't write setting ...\n"; $port->read_char_time(1); #$port->read_const_time(1000); 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"; $port-> error_msg(1); # prints hardware messages like "Framing Error" $port-> user_msg(1); # prints function messages like "Waiting for my $status = pack('C*', 0x02, 0x50, 0x01, 0x03, 0x54 ); $port->write($status); sleep 1; $status = pack('C*', 0x45 ); $port->write($status); sleep 1; $port->lookclear; #clear the buffer $port->read_interval(0); $port->read_const_time(1000); my $in; my ($InBytes, $count_in); $InBytes = 132; ($count_in, $in) = $port->read($InBytes); warn "read unsuccessful\n" unless ($count_in == $InBytes); my $done = 0; my $blk; my $err; my $out; my $result; my $buf_in; my $count_total = 0; $count_total = $count_in; $buf_in = $in; my $reads = 1; print "CountIN: $count_in Reads: $reads Count Total: $count_total\n"; $InBytes = 132; print_hex($in); for (;;) { ($count_in, $in) = $port->read($InBytes); warn "read unsuccessful\n" unless ($count_in == $InBytes); $reads = $reads + 1; $count_total = $count_total + $count_in; print "CountIN: $count_in Reads: $reads Count Total: $count_total \n"; $buf_in = $buf_in . $in; print_hex($in); last if ($count_in == 0); } print FILE_IN_1 $buf_in; $port->close || warn "Close Failed!\n"; undef $port; close(FILE_IN_1); #### 55 55 05 2f 10 05 10 #### 55 55 01 05 2F 00 00 00 00 10 05 10