How to convert MiFare Classic UID read to character

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How to convert MiFare Classic UID read to character

跳至解决方案
4,516 次查看
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!

标签 (1)
0 项奖励
1 解答
3,481 次查看
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

在原帖中查看解决方案

1 回复
3,482 次查看
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