Multiple options, not sure where to start.

Multiple devices, multiple serial ports, auto=calibration

Page 1 of 1

3 Replies - 1071 Views - Last Post: 19 February 2010 - 06:33 AM Rate Topic: -----

#1 dbvanhorn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-January 10

Multiple options, not sure where to start.

Posted 18 February 2010 - 11:47 AM

Ok, this one has had me in a loop for a while. I've held back asking since I didn't see a clear way to frame the question. I still don't but I guess I'll just try to describe it accurately.

I have a hardcoded version of this working on two com ports with devices on COM1 and measurements on COM2, but I need to make it self-configure, so that the user can basically plug anything in anywhere and the system will figure it out by doing what a human might do in this situation.


My application needs to use several serial devices, on multiple com ports.
There will me multiple devices of mixed types on a given port.


First, I need to find out what serial ports are available.

Then on each port, I need to find out what devices have been connected. I can query measurements and devices, so it comes down to scanning the available com ports, querying for devices, and then saving that information (how?) for the next part.


There are two classes of devices, Measurement and Device.

I need to init all devices, wait till they are initted, and then init all measurements.
(this part I know how to do for any given device or measurement)

After that, I need to exercise each device and while a given device is running, see which measurement is changing, and associate it (there may be more than one) with the device.

After each device has at least one measurement associated with it, then I need to cycle the devices 10x and average the measurement readings to establish a baseline. (This part I also understand)

What I'm looking for comes down to two things:

Get a list of available com ports.
I don't need or even want to present them to the user, I just need to know what com ports exist, which are not already in use by some other application.

Associate given device with its com port, and with any measurements that are physically connected to it, and there may be more than one. Measurement devices may be on different com ports than the devices, or they may not.

An association might look like this:
Device1, COM2
Measurement4, COM2
Measurement5, COM3

I don't know how to handle the association part, or scan for available ports.


Simplifying assumptions: Less than 10 devices, always at least one measurement per device, probably less than three measurements per device. Com ports could range from 0 to 999 (Digi Edgeports)

I'll also want to write the configuration to a text file, but I don't anticipate any trouble there.


Ideas? :)

Is This A Good Question/Topic? 0
  • +

Replies To: Multiple options, not sure where to start.

#2 T3hC13h   User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: Multiple options, not sure where to start.

Posted 18 February 2010 - 01:42 PM

I had a look at the SerialPort class and cooked up this quick bit of code to show the ports available, put them into a dictionary collection so they can be reference by the name of our choosing and then test to see if they are available.

If you call open on a port that is already in use it will throw an access denied exception.

Imports System.IO.Ports
Module Module1
    Sub Main()
        Dim dtPorts As New Dictionary(Of String, SerialPort)
        For Each sPortName As String In SerialPort.GetPortNames()
            dtPorts.Add(sPortName, New SerialPort(sPortName))
        Next
        For Each comPort As SerialPort In dtPorts.Values
            Try
                comPort.Open()
                Console.WriteLine(comPort.PortName & " is available.")
            Catch ex As Exception
                Console.WriteLine(ex.Message)
            End Try
        Next
        Console.ReadLine()
        For Each comPort As SerialPort In dtPorts.Values
            If comPort.IsOpen Then
                comPort.Close()
            End If
        Next
    End Sub
End Module


This post has been edited by T3hC13h: 18 February 2010 - 02:29 PM

Was This Post Helpful? 0
  • +
  • -

#3 Guest_dbvanhorn*


Reputation:

Re: Multiple options, not sure where to start.

Posted 18 February 2010 - 04:43 PM

Ok, I see what you're doing there. I didn't want to do that, because it might take quite a while to cycle through 1000 possible com ports. I thought there was a way to ask the system what com ports actually exist.

?
Was This Post Helpful? 0

#4 T3hC13h   User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: Multiple options, not sure where to start.

Posted 19 February 2010 - 06:33 AM

View Postdbvanhorn, on 18 February 2010 - 03:43 PM, said:

Ok, I see what you're doing there. I didn't want to do that, because it might take quite a while to cycle through 1000 possible com ports. I thought there was a way to ask the system what com ports actually exist.

?


Thats fine but just know that the code I posted shows three different actions, returning and naming the ports, opening, and finally closing any open ports. It was simply an example use of the SerialPort class. :)

System.IO.Ports.SerialPort.GetPortNames()
returns a string array with the names of all available (they could be in use) com ports. Is this not quite what you are looking for?
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1