Author Topic: Are all virtual com ports last in GetPortNames??  (Read 27187 times)

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Are all virtual com ports last in GetPortNames??
« on: September 05, 2012, 07:21:42 am »
Hi All,
Bit of a bizarre title but I am trying to avoid problems in my software regarding the virtual Serial Port.  A device that is being designed user a USB virtual com port. I am reading this using the Serial Port Complete Method
 do
            {
                index += 1;
                cboPort.Items.Add(nameArray[index]);
            } while (!((nameArray[index] == myComPortName) || (index == nameArray.GetUpperBound(0))));
            cboPort.Text = nameArray[0];

this method gets all the comm ports available and is rock solid. I am looking at putting the code in a function after the port has been closed and the device removed.  This is to allow multiple devices that could be attached to the PC as it might be used as to interface a number of these units or a single at this stage. Will this code all ways stick the Virtual Com as the last as it appears to using the below method

do
            {
                index += 1;
                cboPort.Items.Add(nameArray[index]);
            } while (!((nameArray[index] == myComPortName) || (index == nameArray.GetUpperBound(0))));
            cboBaudRate.Text = cboBaudRate.Items[0].ToString();
            //cboPort.Text = nameArray[0];

            maxsize = cboPort.Items.Count;
            maxsize--;
            LastVal = cboPort.Items[maxsize].ToString();
            cboPort.Text = LastVal;


I trying to avoid "it works on my PC"
Glenn
« Last Edit: September 05, 2012, 11:00:24 am by GlennP »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Are all virtual com ports last in GetPortNames??
« Reply #1 on: September 05, 2012, 09:38:20 am »
The code adds myComPortName as the last item in the array. If you sort the array, myComPortName might not be last.

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Re: Are all virtual com ports last in GetPortNames??
« Reply #2 on: September 05, 2012, 11:11:48 am »
Well, if I remember not to sort should not be a problem.  Now if I try and get available serial ports using that method the program builds, runs, and swaps the port then errors any ideas? ::)

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Are all virtual com ports last in GetPortNames??
« Reply #3 on: September 05, 2012, 11:44:19 am »
What do you mean by "the program swaps the port then errors"?

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Re: Are all virtual com ports last in GetPortNames??
« Reply #4 on: September 06, 2012, 05:57:12 am »
The port is swapped then (one USB out another USB in on a different unit).
 I think I may have solved it by indicating to the user better as what is happening and when they need to plug in and click the button :)
Glenn

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Re: Are all virtual com ports last in GetPortNames??
« Reply #5 on: September 06, 2012, 08:13:37 am »
Again in the great tradition of trying of writing down the problem you then see a solution, all good,
Thanks Glenn
 :)

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Are all virtual com ports last in GetPortNames??
« Reply #6 on: September 06, 2012, 08:42:05 pm »
Again in the great tradition of trying of writing down the problem you then see a solution, all good,
Thanks Glenn
 :)

I can't tell you how often that happens to me!