c# - 无法从 'byte[]' 转换为 'byte*'

标签 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

谢谢

最佳答案

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

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

C# byte array to fixed int pointer

你需要类似的东西,在方法中接收一个 byte[] 然后做赋值

fixed(byte *packet = packetArray)
    {
        ... etc
    }

关于c# - 无法从 'byte[]' 转换为 'byte*',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33413032/

相关文章:

c# - 数据绑定(bind)到 WPF 中的 UserControl

c# - Windows 服务总线向 MSMQ 添加了什么?

c# - 什么是 NamedPipeServerStream 和 NamedPipeClientStream(s)?

c++ - 类图数据结构和 C++ 实现

python - 使用串口将 float 从arduino发送到python

c# - 多选DataGrid

c++ - 使用 node-gyp 编译时 CFLAGS 在 Windows 上不起作用

C++ 和微软 SAPI 5 : How to list all available voices and select a voice

arduino - Sparkfun edge 引导加载程序问题...无法正常工作

web-services - 使用 Arduino GSM/GPRS shield 将数据发送到我的网络服务