jabidof has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w # use strict; use warnings; use threads; use Thread::Queue; use Win32::SerialPort; use Data::Dump qw(dump); # GLOBALS my %CONFIG = ( ReaderCOMPort => "COM56", ReaderCOMPortOpen => 1, testTime => 5 # testing time in seconds ); <readmore> my $ob; # Initialize the serial port of the reader initRS232(); $ob->read_interval(250); $ob->read_const_time(10000); $ob->lookclear; while (1) { my ($count, $str) = $ob->read(14); DumpString($str); sleep 1; } undef $ob; exit; sub initRS232 { eval { $ob = Win32::SerialPort->new ($CONFIG{ReaderCOMPort}); # || r +eturn "Can't open $PortName: $^E\n" }; if($@) { # We know it died, but is it an object or a # printable message? if( ref $@ ) { # Assume it's an exception object. Not a # great way to do it, but it works. # # Now, what kind of exception is it? # if( $@->isa( 'IOException' ) ) { } elsif( $@->isa( 'OtherException' ) ) { } else { } } else { # Assume it's an error string } } $CONFIG{ReaderCOMPortOpen} = 1; $ob->user_msg(1); # misc. warnings $ob->error_msg(1); # hardware and data errors $ob->baudrate(2400); $ob->parity("none"); $ob->parity_enable(1); # for any parity except "none" $ob->databits(8); $ob->stopbits(1); #$ob->xon_limit(20); # bytes left in buffer #$ob->xoff_limit(100); # space left in buffer $ob->write_settings; $ob->save("tekpower.cfg"); #$ob->are_match("\xE8"); } # dump the contents of a string as decimal and hex bytes and character +s sub DumpString { my @a = unpack('C*',$_[0]); my $o = 0; while (@a) { my @b = splice @a,0,16; my @d = map sprintf("%03d",$_), @b; my @x = map sprintf("%02x",$_), @b; my $c = substr($_[0],$o,16); $c =~ s/[[:^print:]]/ /g; printf "%6d %s\n",$o,join(' ',@d); print " "x8,join(' ',@x),"\n"; print " "x9,join(' ',split(//,$c)),"\n"; $o += 16; } } </readmore>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Blocking on serial port!
by RichardK (Parson) on Apr 24, 2013 at 22:50 UTC | |
by jabidof (Initiate) on Apr 26, 2013 at 13:12 UTC | |
Re: Blocking on serial port!
by Random_Walk (Prior) on Apr 25, 2013 at 07:37 UTC | |
by jabidof (Initiate) on Apr 26, 2013 at 17:38 UTC | |
Re: Blocking on serial port!
by OfficeLinebacker (Chaplain) on Apr 24, 2013 at 23:50 UTC | |
by jabidof (Initiate) on Apr 26, 2013 at 13:13 UTC | |
by OfficeLinebacker (Chaplain) on Apr 29, 2013 at 06:55 UTC |