Wiegand Library - Can´t Serial.print/ extract HEX

Hi good people

Same days ago I find that my efforts to get a Hex output of a Wiegand reader became a issue.

So I find a answer to this in another topic, so I did the same method but no results.

I think that´s again my error, so please get me some help here.

wiegRead.ino (302 Bytes)

 unsigned long cod=(wg.getCode(), HEX);
   Serial.println(cod, HEX); // get 10  why???

Because that is what the comma operator does.

Just because some values in parentheses mean something to a function does NOT mean that the same values in parentheses means the same thing to another function (the assignment operator IS a function).

The value HEX doesn't mean a thing to the assignment operator.

Hi PaulS

This is no my lucky day.

I followed your idea but with: Serial.println(cod); // get 16 this time.

This is still strange for me.

Any sugestions are welcome.

Thanks in advance.

I followed your idea but with: Serial.println(cod); // get 16 this time.

Printing 16 in base 16 is going to result in you seeing 10.

Printing 16 in base 10 is going to result in you seeing 16.

The problem is that you are assigning the wrong value to cod, because of the way you are abusing the comma operator.

The CORRECT assignment is

unsigned long cod = wg.getCode();

Why are you naming the variable after a fish?

Hi PaulS again

Ok I agree with you.

To see the right value printed I must use HEX only when printing > Serial.print( ..., HEX).

My battle is because I need to use that HEX value into a String variable to compare later, the reader send me 6 chars and I need to cut the first one in a substring or another method.

So I need your help, please, to assign that HEX value to use it later.

That variable naming was a cut and paste!

Thank you

My battle is because I need to use that HEX value into a String variable to compare later

The value to compare it to should be in the same format. That format is NOT a hex representation in a String instance.

The value to compare is an array of bytes. The value to compare to should also be an array of bytes.

If you absolutely insist on doing it the wrong way, with Strings, you need to assemble the String one byte at a time.