Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. How to convert array<System::Byte^>^ to array<unsigned char>^

How to convert array<System::Byte^>^ to array<unsigned char>^

Scheduled Pinned Locked Moved Managed C++/CLI
data-structureshelptutorialannouncement
3 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_15150778
    wrote on last edited by
    #1

    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 ^
    
    }
    
    L 1 Reply Last reply
    0
    • M Member_15150778

      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 ^
      
      }
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      M 1 Reply Last reply
      0
      • L Lost User

        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.

        M Offline
        M Offline
        Member_15150778
        wrote on last edited by
        #3

        I fixed my problem already , Updated from array^ to array^.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups