How to convert MiFare Classic UID read to character

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to convert MiFare Classic UID read to character

Jump to solution
4,470 Views
cyndi
Contributor I

Hi Nxp Community,

I'm currently using the NFC Reader Library for Linux Example 4 for MiFare Classic 1k tag and I'm trying to convert the UID and store the data read to a const character variable (so I can parse the data using socket to my application on the PC).

However, after multiple tries of type casting to char, char array, pointer of char or even using itoa method (even though the UID is of unsigned integer of 8 bytes), I still can't get it to work:smileycry: I am unsure if I missed out anything or misinterpreted the UID data type as when i do casting, it shows me 

warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

or

warning: assignment makes pointer from integer without a cast

I'm new to C and this is a huge hurdle for me.. Any help or examples to convert would be greatly appreciated and feel free to let me know should the code for sending data via socket is needed for reference. Thank you!

Labels (1)
0 Kudos
1 Solution
3,435 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Cyndi L,

From your description it is not clear what kind of conversion / casting you want to do, or what format is required for the intended parsing.

Do you want to have the UID as a string of printable ASCII characters?

If that is the case there is not a direct method or casting to do that, so it involves a custom function or loop procedure. For example you can do it like next:

uint8_t loop;
char UID_string[PHAC_DISCLOOP_I3P3A_MAX_UID_LENGTH*2];

for(loop = 0; loop < sDiscLoop.sTypeATargetInfo.aTypeA_I3P3[0].bUidSize; loop++)
{
   sprintf(UID_string + loop*2, "%02X", sDiscLoop.sTypeATargetInfo.aTypeA_I3P3[0].aUid[loop]);
}‍‍‍‍‍‍‍‍‍‍

Regards!

Jorge Gonzalez

View solution in original post

1 Reply
3,436 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Cyndi L,

From your description it is not clear what kind of conversion / casting you want to do, or what format is required for the intended parsing.

Do you want to have the UID as a string of printable ASCII characters?

If that is the case there is not a direct method or casting to do that, so it involves a custom function or loop procedure. For example you can do it like next:

uint8_t loop;
char UID_string[PHAC_DISCLOOP_I3P3A_MAX_UID_LENGTH*2];

for(loop = 0; loop < sDiscLoop.sTypeATargetInfo.aTypeA_I3P3[0].bUidSize; loop++)
{
   sprintf(UID_string + loop*2, "%02X", sDiscLoop.sTypeATargetInfo.aTypeA_I3P3[0].aUid[loop]);
}‍‍‍‍‍‍‍‍‍‍

Regards!

Jorge Gonzalez