USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Dicas

  Visual Basic    (Redes/Comunicações)

Título da Dica:  Determinando se a porta serial está disponivel.
Postada em 4/10/2003 por Roßerto            
'coloque num modulo

Option Explicit

Private 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

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 ComPortExists(ByVal ComPort As Integer) _
   As Boolean
    Dim udtComConfig As COMMCONFIG
    Dim lUDTSize As Long
    Dim lRet As Long
    
    lUDTSize = LenB(udtComConfig)
    lRet = GetDefaultCommConfig("COM" + Trim(Str(ComPort)) + _
        Chr(0), udtComConfig, lUDTSize)
    ComPortExists = lRet <> 0
End Function

'fim do modulo

'coloque no evento de um command

    Dim bAns As Boolean
    bAns = ComPortExists(1)
    If bans then
        msgbox "Com Port 1 is available
    Else
        msgbox "Com Port 1 is not available
    End if



 


CyberWEB Network Ltda.    © Copyright 2000-2024   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página