如何将原始十六进制char []转换为ASCII字符串-C ++ Dotnet

时间:2020-01-21 21:21:09

标签: arrays .net byte c++-cli

我正在修改一些通过USB发送和接收数据的现有代码。数据以ascii格式输入文本框,转换为原始数据,即'1'= 01h,然后发送到USB处理程序。

我有以下代码将字符串转换为十六进制:

    String^ TestString = TxDataTB->Text;

    //Prepare a USB OUT data packet to send to the device firmware

    //convert to a byte array
    Encoding^ ascii = Encoding::GetEncoding("iso-8859-1");
    array<Byte>^ TxHexData = ascii->GetBytes(TestString);
    cli::pin_ptr<UCHAR> pin_ptr_n = &TxHexData[0];
    UCHAR* ptr_n = pin_ptr_n;

    //Now send the USB packet data in the OUTBuffer[] to the device firmware.
    USBHandler->SendData(ptr_n, Msglength, PipeNo);

那似乎做得很好,我已经用断点测试了这一点(还没有硬件!)。 我正在努力寻找一种将接收到的数据转换为字符串的方法^-getBytes仅适用于已经采用编码格式的数据;转换似乎只适用于数组^,而且我什至找不到将char []转换为数组的方法^在本应用程序中,以ascii格式发送数据不是一种选择

0 个答案:

没有答案