Newsgroup: it.comp.lang.visual-basic
Titolo: Rilevare le porte COM disponibili

Ciao a tutti,
sto realizzando un programma che dovrà gestire un'apparecchiatura via 
seriale, però ho bisogno di sapere quante seriali ci sono e quali sono già 
occupate per dare la possibilità di settare qualla libera.
Sapreste dirmi se c'è una procedura che faccia al mio caso?
Grazie per gli eventuali consigli 

 Sapreste dirmi se c'è una procedura che faccia al mio caso?
Mmmm ... io utilizzerei le API di windows ...
CreateFile e GetCommConfig
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/getcommconfig.asp
P.S. Attento a non pungerti! :-D
-- 
Ciao,
 Fabrizio
=== 
http://www.negusweb.it
 ===

 ha scritto:

Più che un consiglio una routine già fatta:
________________________________
'queste sono info da MSDN perchè viene da un esempio trovato su un
'sito che non funzionava:
'  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 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
'queste sono info da MSDN
' typedef struct _COMM_CONFIG {  DWORD dwSize;  WORD wVersion;
'  WORD wReserved;  DCB dcb ;DWORD dwProviderSubType;
' DWORD dwProviderOffset;  DWORD dwProviderSize;
' WCHAR wcProviderData[1];} COMMCONFIG, *LPCOMMCONFIG;
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
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()
' io uso una matrice di controlli per selezionare la porta
If EnumSerPorts(1) = 0 Then OpCom(1).Enabled = False
If EnumSerPorts(2) = 0 Then OpCom(2).Enabled = False
If EnumSerPorts(3) = 0 Then OpCom(3.)Enabled = False
If EnumSerPorts(4) = 0 Then OpCom(4).Enabled = False
end sub
_______________________________
ciao
 Stefano

GRAZIE A TUTTI PER L'AIUTO