Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Checking Com Ports

Posted on 2000-04-10
4
Medium Priority
?
504 Views
Last Modified: 2008-03-25
How do you check to see if a comm port is already in use ,and if so what application is using it.
cheers T
0
Comment
Question by:visualbasic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Accepted Solution

by:
OTveit earned 200 total points
ID: 2700237
I use the ScanCom sub to find available com ports on my machine:

'Table of free COM ports
Public nPortFree(0 To MAXPORTS - 1) As Integer

'Make table over available COM Ports
Public Sub ScanCom(ByRef comObj As MSComm)
    Dim i As Integer
    For i = 0 To MAXPORTS - 1
       If (bolOpenSer(comObj, i + 1, 9600, 0, 8, 1)) Then
            nPortFree(i) = True
            comObj.PortOpen = False
        Else
            nPortFree(i) = False
        End If
    Next i
End Sub

Public Function bolOpenSer(ByRef comObj As MSComm, _
                        ByVal lngPno As Long, _
                        ByVal lngBaud As Long, _
                        ByVal lngParity As Long, _
                        ByVal lngDataBits As Long, _
                        ByVal lngStopBits As Long) As Boolean
    'Set Error Handling
    On Error GoTo ErrorHandler
   
    ' Open the serial port
    comObj.CommPort = lngPno
    comObj.Settings = strNumbersToSettings(lngBaud, lngParity,lngDataBits, lngStopBits)
    comObj.PortOpen = True    
    bolOpenSer = True
   
Exit Function
ErrorHandler:
    bolOpenSer = False
End Function
0
 
LVL 5

Expert Comment

by:Voodooman
ID: 2700953
Hi OTVeit!

Interesting Answer!

I am working on a Comms Routine to Update an Access Database at a Remote Location and this is useful even if I didnt ask the question!!

Thanks!!

Voodooman!

P.S. If anybody is using Serial Comms - try Greenleaf CommX.OCX - excellent tool!

0
 

Author Comment

by:visualbasic
ID: 2703178
Hello OTveit
could you post the function strNumbersToSettings
Also is there a way of checking the number of ports before you check are they in use.
Regards T
0
 

Expert Comment

by:OTveit
ID: 2707500
Here is the code for the funtion strNumbersToSettings (it's really simple).

To find the number of physical serial ports on your machine you could read the registry (use GetSetting, GetAllSettings):
\HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM


'-----------------------------------------------------------------------------
' Function: strNumbersToSettings
' Description: Converts Port Settings to String
' Input:    1. Baud Rate
'               2. Parity
'               3. Data Bits
'               4. Stop Bits
' Returns: Port settings as string
'------------------------------------------------------------------------------
Private Function strNumbersToSettings(ByVal lngBaud As Long, _
                                        ByVal lngParity As Long, _
                                        ByVal lngDataBits As Long, _
                                        ByVal lngStopBits As Long) As String
   
    'Error handling
    On Error GoTo ErrorHandler
   
    'Set default value
    strNumbersToSettings = "Not defined"
   
    'Settings Value
    strNumbersToSettings = lngBaud & ","
    strNumbersToSettings = strNumbersToSettings & Switch(lngParity = 0, "N", lngParity = 1, "E", lngParity = 2, "O") & ","
    strNumbersToSettings = strNumbersToSettings & lngDataBits & ","
    strNumbersToSettings = strNumbersToSettings & lngStopBits
   
Exit Function
ErrorHandler:
    strNumbersToSettings = "Not defined"
End Function

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question