Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
A simple and working means to enumerate the COM po...
Author:
Dimitrios Papadopoulos
Submitted:
8/28/2000
Version:
VB5
Compatibility:
VB5, VB6
Category:
Windows API
Views:
21402
A simple and working means to enumerate the COM ports in your system (i.e. to find the ones that really exist)
Declarations:
' In many programms, there is an option for selecting ' the serial port. Instead of providing selection ' for all possible ports and including an error ' handling routine for those ports non-existed in ' hardware, here is an easy way to enumerate the ' serial ports of a computer, using Visual Basic 5 or ' higher (I ' am not sure about the older versions). ' It works on both Win95-98 and Win NT 4. ' Declarations are taken from win32api.txt. ' Original idea from a C programm by PJ Naughter ' at http://www.naughter.com Type DCB DCBlength As Long BaudRate As Long fBitFields As Long wReserved As Integer XonLim As Integer XoffLim As Integer ByteSize As Byte Parity As Byte StopBits As Byte XonChar As Byte XoffChar As Byte ErrorChar As Byte EofChar As Byte EvtChar As Byte wReserved1 As Integer End Type Type COMMCONFIG dwSize As Long wVersion As Integer wReserved As Integer dcbx As DCB dwProviderSubType As Long dwProviderOffset As Long dwProviderSize As Long wcProviderData As Byte End Type Declare Function GetDefaultCommConfig Lib "kernel32" Alias "GetDefaultCommConfigA" (ByVal lpszName As String, lpCC as COMMCONFIG, lpdwSize As Long) As Long
Code:
Public Function EnumSerPorts(port As integer) As Long 'returns non-zero value if the port exists Dim cc As COMMCONFIG, ccsize As Long ccsize = LenB(cc) 'gets the size of COMMCONFIG structure EnumSerPorts = GetDefaultCommConfig("COM" + Trim(Str(port)) + chr(0), cc, ccsize) End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement