CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2011
    Posts
    4

    Make a copy of a serial port handle to local class var

    Hi
    I’m trying to pass a handle to a serial port class to a form that will configure the serial port.
    I can pass a handle to the constructor and it works fine/as I expect inside the constructor but I need a local copy of the handle that points to the port I can use after the constructor is finished by combobox events.
    I can declare a local serial port class var.
    I can copy of the original serial port’s class data but I want a handle to the original not a copy of its data.

    public ref class Config_Serial_Port_Form : public System::Windows::Forms::Form
    {
    public:
    Config_Serial_Port_Form(System::IO::Ports::SerialPort^% initport)
    {
    initport->BaudRate = 600; //this accesses the correct port
    theport = initport; //this only copies all the original to the local object
    //I need theport to be a pointer
    InitializeComponent();
    //
    //TODO: Add the constructor code here
    //
    }

    void domystuff(void)
    {
    port_stuff^ port_stuff_ptr;
    port_stuff_ptr = gcnew port_stuff();
    this->Baud_Rate_comboBox->Text = port_stuff_ptr->BaudRate_to_string(theport);
    this->Parity_comboBox->Text = port_stuff_ptr->Parity_to_string(theport);
    this->handshakingcomboBox->Text = port_stuff_ptr->Handshake_to_string(theport);
    this->databitscomboBox->Text = port_stuff_ptr->DataBits_to_string(theport);
    if (theport->IsOpen)
    this->portselectcomboBox->Text = theport->PortName;
    this->portselectcomboBox->Items->AddRange(theport->GetPortNames());
    this->portselectcomboBox->Items->Add("COM4");

    }
    protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Config_Serial_Port_Form()
    {
    if (components)
    {
    delete components;
    }
    }

    private: System::IO::Ports::SerialPort^ theport; /// this gives me a second object not a handle to the original.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Make a copy of a serial port handle to local class var

    Wrong forum. Your code looks like a managed C++, not a native VC++ one.
    Victor Nijegorodov

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Make a copy of a serial port handle to local class var

    Quote Originally Posted by gpsdude View Post
    Where is the freakin edit button?????
    It is to the left of the Quote button.
    Victor Nijegorodov

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Make a copy of a serial port handle to local class var

    I guess it appears only after 5 posts...
    Victor Nijegorodov

  5. #5
    Join Date
    Jan 2011
    Posts
    4

    Re: Make a copy of a serial port handle to local class var

    Hi Victor
    After the edit button finally poped up I was able to delete the follow on messages but not the original message in the thread.

    I moved it to managed C++ as you suggested.
    Can the SYS op delete this thread for me??
    Last edited by gpsdude; January 28th, 2011 at 12:01 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured