无法转换为' byte []'到'字节*'

时间:2015-10-29 11:30:27

标签: c# c++ arduino rfid windows-10-iot-core

我正在尝试将arduino lib转换为通用Windows平台,但我在byte []到byte *转换时存货。

例如:

public bool readCardSerial()
{
    byte status;
    byte[] str = new byte[MAX_LEN];

    status = anticoll(str);
    Array.Copy(serNum, str, 5);

    return (status == MI_OK);
}

public unsafe byte anticoll(byte* serNum)
{
    byte status;
    byte i;
    byte serNumCheck = 0;
    uint unLen;

    writeMFRC522(BitFramingReg, 0x00);

    serNum[0] = PICC_ANTICOLL;
    serNum[1] = 0x20;
    status = MFRC522ToCard(PCD_TRANSCEIVE, serNum, 2, serNum, &unLen);

    if (status == MI_OK)
    {
        for (i = 0; i < 4; i++)
            serNumCheck ^= serNum[i];
        if (serNumCheck != serNum[i])
            status = MI_ERR;
    }

    return status;
}

readCardSerial函数的str var就是其中一个错误。

如果需要,我在github上有我的代码 - https://github.com/watashimeandeu/rfid.uwp

谢谢

1 个答案:

答案 0 :(得分:1)

检查以下链接,他们回答了类似的问题:

How to assign byte[] as a pointer in C#

C# byte array to fixed int pointer

你需要类似的东西,在方法中接收byte[],然后进行分配

fixed(byte *packet = packetArray)
    {
        ... etc
    }
相关问题