DeviceName
Retrieves the full Device Name of the communications port. (The Windows "Friendly Name" of the device)
Can also be used to 'detect' if the com port exists - See remarks below.
ReadOnly at Design time and Runtime.
Only available using the Comm32 ocx. Not supported by MSComm32
 |
| |
Syntax |
value = object.DeviceName |
| |
|
|
| |
object |
Name of the communications control. |
| |
value |
A String containing the Windows Friendly name of the port - See remarks below |
| |
|
|
| |
Examples |
|
| |
|
MsgBox = object.DeviceName |
'// Retrieves the value |
| |
|
|
|
|
 |
Remarks:
All Windows Com ports have 'Dos' compatible names such as "Com1", "Com2", "Com23" etc. But, since Windows95, com ports also have more descriptive names which often give more information about the device. Windows refers to these longer names as "Friendly Names".
This property returns the WIndows Friendly Name. (Or an empty String if the port does not exist)
The following are examples of Windows Friendly Names.
"Communications Port (Com1)"
"Prolific USB-to-Serial Port (Com18)"
"NetMos PCI Serial Port (Com23)"
IMPORTANT - You can also use this property to detect if a Com port exists - Using most other communications controls the only way to detect if a port exists is by attempting to open it. That method will of course fail if an existing port is already in use by some other application or other instance of the control. Using this DeviceName property you can retrieve the Windows Friendly name even if the port is in use. The property returns an empty string if the port does not exist
Example - When displaying a list of available Com ports you may prefer to display the more descriptive device name.
'// We're going to populate a listbox with the full device names of all existing ports - we'll loop through changing the CommPort number and then read the DeviceName of that CommPort - You might display a list like this to allow your user to select an available port before setting the PortOpen property to open the selected port..
Private Sub PopulateList( )
Dim i as Long
List1.Clear
'// In this example we'll test for ports up to 32 - you can test up to 255 if you want.
For i = 1 To 32
Comm1.CommPort = i
If Comm1.DeviceName = "" Then
'// This Com Port does not exist at all
Else
'// This port exists so show the DeviceName in the list
List1.AddItem Comm1.DeviceName
'// Also store i so that when the user selects one we'll know which port to open
List1.ItemData(List1.NewIndex) = i
End If
Next i
End Sub
'// When the user selects a port we'll get the portnumber from List1.ItemData
Private Sub List1_Click( )
Comm1.CommPort = List1.ItemData(List1.ListIndex)
Comm1.PortOpen = True
End Sub |