Newsgroup: it.comp.lang.visual-basic
Titolo: Elenco porte seriali in XP

Ho sempre usato con successo l'api EnumPorts per avere i nomi delle porte
seriali, poi e' arrivato XP e adesso tutte le porte seriali si chiamano
LocalPort.
Le istruzioni per usare l'api le avevo prese da
www.andreavb.com/tip040003.html
Sapete come posso fare per avere i nomi delle porte?
Grazie
Marco Rossi

LocalPort.
hai provato con la GetDefaultCommConfig?
 Questa va, l'ho presa da un esempio in VC e adattata:
Private Type DCB
        DCBlength As Long
        BaudRate As Long
        fBinary As Long
        fParity As Long
        fOutxCtsFlow As Long
        fOutxDsrFlow As Long
        fDtrControl As Long
        fDsrSensitivity As Long
        fTXContinueOnXoff As Long
        fOutX As Long
        fInX As Long
        fErrorChar As Long
        fNull As Long
        fRtsControl As Long
        fAbortOnError As Long
        fDummy2 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
'' in VisualC
'typedef struct _DCB {  DWORD DCBlength;  DWORD BaudRate;  DWORD
fBinary  :1;  DWORD fParity  :1;  DWORD fOutxCtsFlow  :1;
'DWORD fOutxDsrFlow  :1;  DWORD fDtrControl  :2;  DWORD
fDsrSensitivity  :1;  DWORD fTXContinueOnXoff  :1;
'DWORD fOutX  :1;  DWORD fInX  :1;  DWORD fErrorChar  :1;  DWORD fNull
:1;  DWORD fRtsControl  :2; DWORD fAbortOnError  :1;
'DWORD fDummy2  :17;  WORD wReserved;  WORD XonLim;  WORD XoffLim;
BYTE ByteSize; BYTE Parity;  BYTE StopBits;
'char XonChar;  char XoffChar;  char ErrorChar;  char EofChar;  char
EvtChar;  WORD wReserved1;} DCB;
Private 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
'' in VisualC
'typedef struct _COMM_CONFIG {  DWORD dwSize;  WORD wVersion;
' WORD wReserved;  DCB dcb ;DWORD dwProviderSubType;
 'DWORD dwProviderOffset;  DWORD dwProviderSize;  WCHAR
'wcProviderData[1];} COMMCONFIG, *LPCOMMCONFIG;
Private Declare Function GetDefaultCommConfig Lib "kernel32" Alias
"GetDefaultCommConfigA" (ByVal lpszName As String, lpCC As COMMCONFIG,
lpdwSize As Long) As Long
----------------
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" & CStr(port) &
Chr(0), cc, ccsize)
       ' Debug.Print Err.LastDllError
End Function
-----------------
Private Sub Form_Load()
 Dim Y As Integer
 For Y = 1 To 4   'OpCOM è un optionbutton
  If EnumSerPorts(Y) > 0 Then OpCOM(Y).Value = True
 Next
  Select Case CommPort
    Case 1: OpCOM(1).Value = True
    Case 2: OpCOM(2).Value = True
    Case 3: OpCOM(3).Value = True
    Case 4: OpCOM(4).Value = True
  End Select
(..........)
 
End Sub

 ha scritto nel messaggio
news:vkpgc0tqfafhchk3e...@4ax.com...
