How to convert array<System::Byte^>^ to array<unsigned char>^
-
I have an pointer to an array of System::Byte pointers, and im trying to use the SerialPort.Write function that only accepts**
array^
**It is necessary that I used System::Byte pointers because the value of byte array needs to be update from time to time during runtime. heres my sample code
System::Void MyForm::button1\_Click(System::Object^ sender, System::EventArgs^ e) { array^ myArray = gcnew array(10U); myArray\[0\] = (System::Byte) 0x01; myArray\[1\] = (System::Byte) 0x02; myArray\[2\] = (System::Byte) 0x03; myArray\[3\] = (System::Byte) 0x04; myArray\[4\] = (System::Byte) 0x05; myArray\[5\] = (System::Byte) 0x06; myArray\[6\] = (System::Byte) 0x07; myArray\[7\] = (System::Byte) 0x08; myArray\[8\] = (System::Byte) 0x09; myArray\[9\] = (System::Byte) 0x10; SerialPort1->Write(myArray,0,10U);/\*ERROR,E0304 no instance of overloaded function "System::IO::Ports::SerialPort::Write" matches the argument list; argument types are: (cli::array ^, int, unsigned int)\*/ object type is: System::IO::Ports::SerialPort ^ }
-
I have an pointer to an array of System::Byte pointers, and im trying to use the SerialPort.Write function that only accepts**
array^
**It is necessary that I used System::Byte pointers because the value of byte array needs to be update from time to time during runtime. heres my sample code
System::Void MyForm::button1\_Click(System::Object^ sender, System::EventArgs^ e) { array^ myArray = gcnew array(10U); myArray\[0\] = (System::Byte) 0x01; myArray\[1\] = (System::Byte) 0x02; myArray\[2\] = (System::Byte) 0x03; myArray\[3\] = (System::Byte) 0x04; myArray\[4\] = (System::Byte) 0x05; myArray\[5\] = (System::Byte) 0x06; myArray\[6\] = (System::Byte) 0x07; myArray\[7\] = (System::Byte) 0x08; myArray\[8\] = (System::Byte) 0x09; myArray\[9\] = (System::Byte) 0x10; SerialPort1->Write(myArray,0,10U);/\*ERROR,E0304 no instance of overloaded function "System::IO::Ports::SerialPort::Write" matches the argument list; argument types are: (cli::array ^, int, unsigned int)\*/ object type is: System::IO::Ports::SerialPort ^ }
-
Why have you declared your array as Byte pointers, when it only contains single bytes in each element? And it is clear form SerialPort.Write Method (System.IO.Ports) | Microsoft Docs[^] that the method requires an array of Bytes.
I fixed my problem already , Updated from array^ to array^.