holandes777 has asked for the wisdom of the Perl Monks concerning the following question:
A hex charater is a hex character or is it?
A) my $indata = ''; B) while ((my $c = $Tty->read(1)) ne "") { $indata .= ($c); } # here + I am bringing in hex chracters one at a time. The unit sends me 0xfc + 0x05 0x11 0x27 and 0x56 C) my $payload = extract_payload($indata); # this syas we have 5 byte +s total, we strip to the length and strip the 2 byte CRC at the end l +eaving 0x11 D) my $prtpayload = unpack "H*", $payload; my $prtstatus = unpack "H*" +, substr($payload,0,1); print "kk: payload=$prtpayload status=$prtsta +tus "; E) my $status = substr($payload,0,1); # in this case it is the only b +yte F) $prtstatus = unpack "H*", $status; my $ordstatus = ord($status); pr +int "kk: status2=$prtstatus status3=$ordstatus "; G) if ( $status eq 0x11 ) { print "ok_0x11 "; } else { print "not_0x11 + "; } # note that I also used == for the comparison "just in case) a +nd had the same results OUTPUT: kk: payload=11 status=11 kk: status2=11 status3=17 not_0x11
here is where I am massively confused:
1) I know, for a fact, from the protocol manual and the channel analyzer, that the unit is sending 0x11
2) The output generated by D and F both indicate it is 0x11 or 17 decimal.
3) Why does "G" say that $status, which is 0x11 is not 0x11?
Thanks you all!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: vexed by the hex!
by Eily (Monsignor) on Jan 13, 2017 at 14:07 UTC | |
Re: vexed by the hex!
by choroba (Cardinal) on Jan 13, 2017 at 14:10 UTC | |
Re: vexed by the hex!
by Anonymous Monk on Jan 13, 2017 at 19:09 UTC | |
by holandes777 (Scribe) on Jan 13, 2017 at 19:48 UTC | |
by AnomalousMonk (Archbishop) on Jan 13, 2017 at 20:17 UTC |
Back to
Seekers of Perl Wisdom