Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3604336
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:59:05+00:00 2026-05-18T20:59:05+00:00

I want to have an array of SerialPort-Objects for each Port in the System.

  • 0

I want to have an array of SerialPort-Objects for each Port in the System.
My idea was to make it in that way:

    public ref class CommunicatorClass
{
private:
    static array<SerialPort^>^ _serialPortList;

public: 
    static void Main(){
//          _serialPortList->Initialize;
        for each (String^ s in SerialPort::GetPortNames())
        {
            Console::WriteLine("   {0}", s);
            AddListItem(s);

        }
    }

     static void AddListItem(String^ s)
    {
        // Get the length
        _serialPortList->Length = _serialPortList->GetLength + 1;

        _serialPortList[_serialPortList->GetLength] = gcnew SerialPort(s, 9600);
    }
};

but I am completely new to C++/Windows-Programming. So, yes, sure, there are many errors in. Can anyone please correct it (if the idea itself is not complete bullshit) and tell me some words on the errors ?

Would be nice, thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:59:06+00:00Added an answer on May 18, 2026 at 8:59 pm

    You want to actually open every serial port on the system, all at the same baud rate?

    You can’t change the length of an array, you have to create a brand-new one and copy over all the data, and it’s inefficient to do that every time you need to add another item. I suggest using System::Collections::Generic::List instead, which takes care of all the dynamic resizing for you.

    C++/CLI can call the native Windows serial port functions directly, and I suggest you do so, because the .NET SerialPort class is a piece of total garbage which forces you into a programming style that causes nothing but trouble. Of course you’ll want to hide the Windows interface behind a wrapper class of your own, but it’s well worth the effort.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have an array of objects that is shared between two different
I have an array that I want to sort based on the value of
I have an array that I want to have displayed in HTML.. I don't
I want to have an array as a private class member. I use Itcl
I have an array like that: int sizes[5] = {1,2,3,4,5}; I want to have
I have two array list. Each has list of Objects of type Employee. The
I have a class (TExample) and I want to have an array of pointers
I want to have an array that is accessible throughout my Objective-C project whose
I want to have an array of ArrayLists: ArrayList<MyClass>[] myArray; I want to initialize
What if i want to have an array of pointers to a function and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.